Added ExportOptions to photoexporter.py, #462

This commit is contained in:
Rhet Turnbull
2022-01-15 16:12:27 -08:00
parent 231d132792
commit 9517876bd0
6 changed files with 337 additions and 573 deletions

View File

@@ -8,7 +8,7 @@ import pytest
import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON
from osxphotos.exiftool import get_exiftool_path
from osxphotos.photoexporter import PhotoExporter
from osxphotos.photoexporter import ExportOptions, PhotoExporter
from osxphotos.utils import dd_to_dms_str
# determine if exiftool installed so exiftool tests can be skipped
@@ -321,7 +321,9 @@ def test_export_12(photosdb):
edited_name = pathlib.Path(photos[0].path_edited).name
edited_suffix = pathlib.Path(edited_name).suffix
filename = pathlib.Path(photos[0].original_filename).stem + "_edited" + edited_suffix
filename = (
pathlib.Path(photos[0].original_filename).stem + "_edited" + edited_suffix
)
expected_dest = os.path.join(dest, filename)
got_dest = photos[0].export(dest, edited=True)[0]
@@ -418,7 +420,9 @@ def test_exiftool_json_sidecar_ignore_date_modified(photosdb):
) as fp:
json_expected = json.load(fp)[0]
json_got = PhotoExporter(photo)._exiftool_json_sidecar(ignore_date_modified=True)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(
ExportOptions(ignore_date_modified=True)
)
json_got = json.loads(json_got)[0]
assert json_got == json_expected
@@ -449,7 +453,9 @@ def test_exiftool_json_sidecar_keyword_template_long(capsys, photosdb):
long_str = "x" * (_MAX_IPTC_KEYWORD_LEN + 1)
photos[0]._verbose = print
json_got = PhotoExporter(photos[0])._exiftool_json_sidecar(keyword_template=[long_str])
json_got = PhotoExporter(photos[0])._exiftool_json_sidecar(
ExportOptions(keyword_template=[long_str])
)
json_got = json.loads(json_got)[0]
captured = capsys.readouterr()
@@ -484,7 +490,9 @@ def test_exiftool_json_sidecar_keyword_template(photosdb):
str(pathlib.Path(SIDECAR_DIR) / f"{uuid}_keyword_template.json"), "r"
) as fp:
json_expected = json.load(fp)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(keyword_template=["{folder_album}"])
json_got = PhotoExporter(photo)._exiftool_json_sidecar(
ExportOptions(keyword_template=["{folder_album}"])
)
json_got = json.loads(json_got)
assert json_got == json_expected
@@ -500,7 +508,9 @@ def test_exiftool_json_sidecar_use_persons_keyword(photosdb):
) as fp:
json_expected = json.load(fp)[0]
json_got = PhotoExporter(photo)._exiftool_json_sidecar(use_persons_as_keywords=True)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(
ExportOptions(use_persons_as_keywords=True)
)
json_got = json.loads(json_got)[0]
assert json_got == json_expected
@@ -516,7 +526,9 @@ def test_exiftool_json_sidecar_use_albums_keywords(photosdb):
) as fp:
json_expected = json.load(fp)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(use_albums_as_keywords=True)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(
ExportOptions(use_albums_as_keywords=True)
)
json_got = json.loads(json_got)
assert json_got == json_expected
@@ -536,7 +548,7 @@ def test_exiftool_sidecar(photosdb):
@pytest.mark.skipif(exiftool is None, reason="exiftool not installed")
def test_xmp_sidecar_is_valid(tmp_path, photosdb):
""" validate XMP sidecar file with exiftool """
"""validate XMP sidecar file with exiftool"""
from osxphotos.exiftool import ExifTool
photos = photosdb.photos(uuid=[UUID_DICT["xmp"]])
@@ -560,7 +572,7 @@ def test_xmp_sidecar(photosdb):
def test_xmp_sidecar_extension(photosdb):
""" test XMP sidecar when no extension is passed """
"""test XMP sidecar when no extension is passed"""
uuid = UUID_DICT["xmp"]
photos = photosdb.photos(uuid=[uuid])
@@ -581,7 +593,9 @@ def test_xmp_sidecar_use_persons_keyword(photosdb):
with open(pathlib.Path(SIDECAR_DIR) / f"{uuid}_persons_as_keywords.xmp") as fp:
xmp_expected = fp.read()
xmp_got = PhotoExporter(photo)._xmp_sidecar(use_persons_as_keywords=True, extension="jpg")
xmp_got = PhotoExporter(photo)._xmp_sidecar(
ExportOptions(use_persons_as_keywords=True), extension="jpg"
)
assert xmp_got == xmp_expected
@@ -593,12 +607,14 @@ def test_xmp_sidecar_use_albums_keyword(photosdb):
with open(pathlib.Path(SIDECAR_DIR) / f"{uuid}_albums_as_keywords.xmp") as fp:
xmp_expected = fp.read()
xmp_got = PhotoExporter(photo)._xmp_sidecar(use_albums_as_keywords=True, extension="jpg")
xmp_got = PhotoExporter(photo)._xmp_sidecar(
ExportOptions(use_albums_as_keywords=True), extension="jpg"
)
assert xmp_got == xmp_expected
def test_xmp_sidecar_gps(photosdb):
""" Test export XMP sidecar with GPS info """
"""Test export XMP sidecar with GPS info"""
uuid = UUID_DICT["location"]
photo = photosdb.get_photo(uuid)
@@ -619,7 +635,7 @@ def test_xmp_sidecar_keyword_template(photosdb):
xmp_expected = fp.read()
xmp_got = PhotoExporter(photo)._xmp_sidecar(
keyword_template=["{created.year}", "{folder_album}"], extension="jpg"
ExportOptions(keyword_template=["{created.year}", "{folder_album}"]),
extension="jpg",
)
assert xmp_got == xmp_expected