2023-08-29 11:49:22 +00:00
|
|
|
import pytest
|
2023-08-29 10:15:10 +00:00
|
|
|
from papis_extract.annotation_data import Annotation
|
|
|
|
|
|
|
|
|
2023-08-29 11:49:22 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"fmt_string,expected",
|
|
|
|
[
|
|
|
|
("{{quote}}", "I am the text value"),
|
|
|
|
(
|
|
|
|
"> {{quote}}\n{{#note}}Note: {{note}}{{/note}}",
|
|
|
|
"> I am the text value\nNote: Whereas I represent the note",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"{{#note}}Note: {{note}}{{/note}}{{#page}}, p. {{page}}{{/page}}",
|
|
|
|
"Note: Whereas I represent the note",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_formatting(fmt_string, expected):
|
|
|
|
sut = Annotation(
|
|
|
|
"myfile",
|
|
|
|
text="I am the text value",
|
|
|
|
content="Whereas I represent the note",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert sut.format(fmt_string) == expected
|
|
|
|
|
|
|
|
def test_colorname_matches_exact():
|
|
|
|
sut = Annotation(
|
2023-08-29 20:23:52 +00:00
|
|
|
"testfile", colors=(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"
|
|
|
|
|
|
|
|
# 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):
|
|
|
|
sut = Annotation(
|
2023-08-29 20:23:52 +00:00
|
|
|
"testfile", colors=color_value, minimum_similarity_color=0.833
|
2023-08-29 11:49:22 +00:00
|
|
|
)
|
2023-08-29 10:15:10 +00:00
|
|
|
c_name = sut.colorname
|
|
|
|
assert c_name == "red"
|