2023-08-29 11:49:22 +00:00
|
|
|
import pytest
|
2024-01-24 10:14:45 +00:00
|
|
|
from papis.document import Document
|
|
|
|
|
2023-09-22 18:04:39 +00:00
|
|
|
from papis_extract.annotation import Annotation
|
2023-08-29 10:15:10 +00:00
|
|
|
|
|
|
|
|
2023-08-29 11:49:22 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"fmt_string,expected",
|
|
|
|
[
|
2023-09-22 18:04:39 +00:00
|
|
|
("{{quote}}", "I am the text value"),
|
2023-08-29 11:49:22 +00:00
|
|
|
(
|
2023-09-22 18:04:39 +00:00
|
|
|
"> {{quote}}\n{{#note}}Note: {{note}}{{/note}}",
|
2023-08-29 11:49:22 +00:00
|
|
|
"> I am the text value\nNote: Whereas I represent the note",
|
|
|
|
),
|
|
|
|
(
|
2023-09-22 18:04:39 +00:00
|
|
|
"{{#note}}Note: {{note}}{{/note}}{{#page}}, p. {{page}}{{/page}}",
|
2023-08-29 11:49:22 +00:00
|
|
|
"Note: Whereas I represent the note",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2023-09-22 18:04:39 +00:00
|
|
|
def test_formatting_replacements(fmt_string, expected):
|
2023-08-29 11:49:22 +00:00
|
|
|
sut = Annotation(
|
|
|
|
"myfile",
|
2024-01-24 10:14:45 +00:00
|
|
|
content="I am the text value",
|
|
|
|
note="Whereas I represent the note",
|
2023-08-29 11:49:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert sut.format(fmt_string) == expected
|
|
|
|
|
2023-10-17 20:03:35 +00:00
|
|
|
|
2023-09-22 18:04:39 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"fmt_string,expected",
|
|
|
|
[
|
|
|
|
("{{doc.title}}", "document-title"),
|
|
|
|
("{{doc.title}}-{{doc.author}}", "document-title-document-author"),
|
|
|
|
("{{quote}} ({{doc.author}})", "I am the text value (document-author)"),
|
2023-10-17 20:03:35 +00:00
|
|
|
],
|
2023-09-22 18:04:39 +00:00
|
|
|
)
|
|
|
|
def test_formatting_document_access(fmt_string, expected):
|
|
|
|
sut = Annotation(
|
|
|
|
"myfile",
|
2024-01-24 10:14:45 +00:00
|
|
|
content="I am the text value",
|
|
|
|
note="Whereas I represent the note",
|
2023-09-22 18:04:39 +00:00
|
|
|
)
|
2023-10-17 20:03:35 +00:00
|
|
|
doc = Document(data={"title": "document-title", "author": "document-author"})
|
2023-09-22 18:04:39 +00:00
|
|
|
|
|
|
|
assert sut.format(fmt_string, doc=doc) == expected
|
2023-09-19 15:35:39 +00:00
|
|
|
|
2023-10-17 20:03:35 +00:00
|
|
|
|
2023-08-29 11:49:22 +00:00
|
|
|
def test_colorname_matches_exact():
|
2024-01-24 10:14:45 +00:00
|
|
|
sut = Annotation("testfile", color=(1.0, 0.0, 0.0), minimum_similarity_color=1.0)
|
2023-08-29 11:49:22 +00:00
|
|
|
c_name = sut.colorname
|
|
|
|
assert c_name == "red"
|
|
|
|
|
2023-09-19 15:35:39 +00:00
|
|
|
|
2023-08-29 11:49:22 +00:00
|
|
|
# TODO inject closeness value instead of relying on default
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"color_value",
|
|
|
|
[
|
|
|
|
(1.0, 0.0, 0.0),
|
|
|
|
(0.9, 0.0, 0.0),
|
|
|
|
(0.8, 0.0, 0.0),
|
|
|
|
(0.7, 0.0, 0.0),
|
|
|
|
(0.51, 0.0, 0.0),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_matches_inexact_colorname(color_value):
|
2024-01-24 10:14:45 +00:00
|
|
|
sut = Annotation("testfile", color=color_value, minimum_similarity_color=0.833)
|
2023-08-29 10:15:10 +00:00
|
|
|
c_name = sut.colorname
|
|
|
|
assert c_name == "red"
|