Metadata writer #17
+1
-1
@@ -2,4 +2,4 @@ LLM_API_BASE_URL = "http://localhost:1234/v1"
|
|||||||
LLM_API_KEY = "not-relevant"
|
LLM_API_KEY = "not-relevant"
|
||||||
LLM_DEFAULT_TEMPERATURE = 1.0
|
LLM_DEFAULT_TEMPERATURE = 1.0
|
||||||
|
|
||||||
METADATA_PREFIX = "photools:"
|
METADATA_PREFIX = "photools|"
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ from photools3.metadata_writer import (
|
|||||||
_is_prefixed,
|
_is_prefixed,
|
||||||
_prefixed,
|
_prefixed,
|
||||||
)
|
)
|
||||||
|
from photools3.settings import settings
|
||||||
from test.test_photo import PATHS_DNG_EXAMPLES
|
from test.test_photo import PATHS_DNG_EXAMPLES
|
||||||
|
|
||||||
|
PREFIX = settings.metadata_prefix
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def make_dng_file(tmp_path):
|
def make_dng_file(tmp_path):
|
||||||
@@ -74,13 +77,13 @@ def test_get_keywords(make_dng_file, pic, expected_keywords):
|
|||||||
def test_prefixed():
|
def test_prefixed():
|
||||||
txt = "bla_bla"
|
txt = "bla_bla"
|
||||||
txt_prefixed = _prefixed(txt)
|
txt_prefixed = _prefixed(txt)
|
||||||
assert txt_prefixed == "photools|bla_bla"
|
assert txt_prefixed == f"{PREFIX}bla_bla"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"txt, expected_result",
|
"txt, expected_result",
|
||||||
[
|
[
|
||||||
("photools|some text", True),
|
(f"{PREFIX}some text", True),
|
||||||
("prefix is missing here", False),
|
("prefix is missing here", False),
|
||||||
("some_perfix|but not the right one", False),
|
("some_perfix|but not the right one", False),
|
||||||
],
|
],
|
||||||
@@ -108,7 +111,7 @@ def test_set_caption(make_dng_file, pic):
|
|||||||
assert metadata_writer.sidecar_path.exists() # ... but now!
|
assert metadata_writer.sidecar_path.exists() # ... but now!
|
||||||
result = metadata_writer.get_caption()
|
result = metadata_writer.get_caption()
|
||||||
assert result
|
assert result
|
||||||
assert result == "photools|This is a test"
|
assert result == f"{PREFIX}This is a test"
|
||||||
|
|
||||||
|
|
||||||
def test_set_caption_on_existing(metadata_writer_on_existing):
|
def test_set_caption_on_existing(metadata_writer_on_existing):
|
||||||
@@ -120,19 +123,19 @@ def test_set_caption_on_existing(metadata_writer_on_existing):
|
|||||||
metadata_writer_on_existing.write_caption("Another caption")
|
metadata_writer_on_existing.write_caption("Another caption")
|
||||||
assert (
|
assert (
|
||||||
metadata_writer_on_existing.get_caption()
|
metadata_writer_on_existing.get_caption()
|
||||||
== "Let's pretend this is the caption of the original image. photools|Another caption"
|
== f"Let's pretend this is the caption of the original image. {PREFIX}Another caption"
|
||||||
)
|
)
|
||||||
|
|
||||||
metadata_writer_on_existing.write_caption("Updated caption")
|
metadata_writer_on_existing.write_caption("Updated caption")
|
||||||
assert (
|
assert (
|
||||||
metadata_writer_on_existing.get_caption()
|
metadata_writer_on_existing.get_caption()
|
||||||
== "Let's pretend this is the caption of the original image. photools|Updated caption"
|
== f"Let's pretend this is the caption of the original image. {PREFIX}Updated caption"
|
||||||
)
|
)
|
||||||
|
|
||||||
metadata_writer_on_existing.write_caption("Don't do this!", override=False)
|
metadata_writer_on_existing.write_caption("Don't do this!", override=False)
|
||||||
assert (
|
assert (
|
||||||
metadata_writer_on_existing.get_caption()
|
metadata_writer_on_existing.get_caption()
|
||||||
== "Let's pretend this is the caption of the original image. photools|Updated caption"
|
== f"Let's pretend this is the caption of the original image. {PREFIX}Updated caption"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -144,23 +147,23 @@ def test_set_caption_on_existing(metadata_writer_on_existing):
|
|||||||
[
|
[
|
||||||
"architektur",
|
"architektur",
|
||||||
"zeit|abend",
|
"zeit|abend",
|
||||||
"photools|hund",
|
f"{PREFIX}hund",
|
||||||
"photools|katze",
|
f"{PREFIX}katze",
|
||||||
"photools|maus",
|
f"{PREFIX}maus",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
PATHS_DNG_EXAMPLES[1],
|
PATHS_DNG_EXAMPLES[1],
|
||||||
["architektur", "photools|hund", "photools|katze", "photools|maus"],
|
["architektur", f"{PREFIX}hund", f"{PREFIX}katze", f"{PREFIX}maus"],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
PATHS_DNG_EXAMPLES[2],
|
PATHS_DNG_EXAMPLES[2],
|
||||||
[
|
[
|
||||||
"morgen",
|
"morgen",
|
||||||
"tiere|vögel",
|
"tiere|vögel",
|
||||||
"photools|hund",
|
f"{PREFIX}hund",
|
||||||
"photools|katze",
|
f"{PREFIX}katze",
|
||||||
"photools|maus",
|
f"{PREFIX}maus",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@@ -173,9 +176,9 @@ def test_set_caption_on_existing(metadata_writer_on_existing):
|
|||||||
"mainz",
|
"mainz",
|
||||||
"spiegelung",
|
"spiegelung",
|
||||||
"wasser",
|
"wasser",
|
||||||
"photools|hund",
|
f"{PREFIX}hund",
|
||||||
"photools|katze",
|
f"{PREFIX}katze",
|
||||||
"photools|maus",
|
f"{PREFIX}maus",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@@ -187,9 +190,9 @@ def test_set_caption_on_existing(metadata_writer_on_existing):
|
|||||||
"personen",
|
"personen",
|
||||||
"tiefe",
|
"tiefe",
|
||||||
"weg",
|
"weg",
|
||||||
"photools|hund",
|
f"{PREFIX}hund",
|
||||||
"photools|katze",
|
f"{PREFIX}katze",
|
||||||
"photools|maus",
|
f"{PREFIX}maus",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -200,9 +203,9 @@ def test_set_keywords(make_dng_file, pic, expected_keywords):
|
|||||||
result = metadata_writer.get_keywords()
|
result = metadata_writer.get_keywords()
|
||||||
assert result
|
assert result
|
||||||
assert isinstance(result, list)
|
assert isinstance(result, list)
|
||||||
assert "photools|hund" in result
|
assert f"{PREFIX}hund" in result
|
||||||
assert "photools|katze" in result
|
assert f"{PREFIX}katze" in result
|
||||||
assert "photools|maus" in result
|
assert f"{PREFIX}maus" in result
|
||||||
|
|
||||||
|
|
||||||
def test_set_keywords_on_existing():
|
def test_set_keywords_on_existing():
|
||||||
|
|||||||
Reference in New Issue
Block a user