import shutil from pathlib import Path import pytest from photools3.metadata_writer import ( XMP_KEYS_CAPTION, MetadataWriter, ) 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}" shutil.copy(src, dst) return dst return _make def test_read_metadata(make_dng_file): """primitive test for `MetadataWriter`""" file_path = make_dng_file() 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) 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)) metadata_writer.write_caption("This is a test") result = metadata_writer.get_metadata(XMP_KEYS_CAPTION[0]) assert result def test_set_caption_on_existing(): # TODO ... def test_set_keywords(): # TODO ... def test_set_keywords_on_existing(): # TODO ...