This commit is contained in:
@@ -4,44 +4,61 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from photools3.metadata_writer import (
|
||||
XMP_KEYS_CAPTION,
|
||||
MetadataWriter,
|
||||
_is_prefixed,
|
||||
_prefixed,
|
||||
)
|
||||
from test.test_photo import PATHS_DNG_EXAMPLES
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_dng_file(tmp_path):
|
||||
def _make(index: int = 0) -> Path:
|
||||
src = PATHS_DNG_EXAMPLES[index]
|
||||
dst = tmp_path / f"copy_{index}_{src.name}"
|
||||
def _make(src: Path) -> Path:
|
||||
dst = tmp_path / f"copy_{src.name}"
|
||||
shutil.copy(src, dst)
|
||||
return dst
|
||||
|
||||
return _make
|
||||
|
||||
|
||||
def test_read_metadata(make_dng_file):
|
||||
@pytest.mark.parametrize("pic", PATHS_DNG_EXAMPLES)
|
||||
def test_read_metadata(make_dng_file, pic):
|
||||
"""primitive test for `MetadataWriter`"""
|
||||
file_path = make_dng_file()
|
||||
file_path = make_dng_file(pic)
|
||||
result = MetadataWriter(file_path)
|
||||
assert result
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pic_no", range(len(PATHS_DNG_EXAMPLES)))
|
||||
def test_read_metadata_sidecar_path(make_dng_file, pic_no):
|
||||
file_path = make_dng_file(pic_no)
|
||||
def test_prefixed():
|
||||
txt = "bla_bla"
|
||||
txt_prefixed = _prefixed(txt)
|
||||
assert txt_prefixed == "photools: bla_bla"
|
||||
|
||||
|
||||
def test_is_prefixed():
|
||||
txt_prefixed = "photools: some text"
|
||||
txt_not_prefixed = "prefix is missing here"
|
||||
txt_false_prefix = "some_perfix: but not the right one"
|
||||
|
||||
assert _is_prefixed(txt_prefixed)
|
||||
assert not _is_prefixed(txt_not_prefixed)
|
||||
assert not _is_prefixed(txt_false_prefix)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pic", PATHS_DNG_EXAMPLES)
|
||||
def test_read_metadata_sidecar_path(make_dng_file, pic):
|
||||
file_path = make_dng_file(pic)
|
||||
metadata_writer = MetadataWriter(file_path)
|
||||
print(metadata_writer.sidecar_path)
|
||||
assert isinstance(metadata_writer.sidecar_path, Path)
|
||||
assert str(metadata_writer.sidecar_path).lower().endswith(".dng.xmp")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pic_no", range(len(PATHS_DNG_EXAMPLES)))
|
||||
def test_set_caption(make_dng_file, pic_no):
|
||||
metadata_writer = MetadataWriter(make_dng_file(pic_no))
|
||||
@pytest.mark.parametrize("pic", PATHS_DNG_EXAMPLES)
|
||||
def test_set_caption(make_dng_file, pic):
|
||||
metadata_writer = MetadataWriter(make_dng_file(pic))
|
||||
metadata_writer.write_caption("This is a test")
|
||||
result = metadata_writer.get_metadata(XMP_KEYS_CAPTION[0])
|
||||
result = metadata_writer.get_caption()
|
||||
assert result
|
||||
|
||||
|
||||
@@ -50,9 +67,16 @@ def test_set_caption_on_existing():
|
||||
...
|
||||
|
||||
|
||||
def test_set_keywords():
|
||||
# TODO
|
||||
...
|
||||
@pytest.mark.parametrize("pic", PATHS_DNG_EXAMPLES)
|
||||
def test_set_keywords(make_dng_file, pic):
|
||||
metadata_writer = MetadataWriter(make_dng_file(pic))
|
||||
metadata_writer.write_keywords(["hund", "katze", "maus"])
|
||||
result = metadata_writer.get_keywords()
|
||||
assert result
|
||||
assert isinstance(result, list)
|
||||
assert "photools: hund" in result
|
||||
assert "photools: katze" in result
|
||||
assert "photools: maus" in result
|
||||
|
||||
|
||||
def test_set_keywords_on_existing():
|
||||
|
||||
Reference in New Issue
Block a user