Refactored photoinfo, photoexporter; #462

This commit is contained in:
Rhet Turnbull
2022-01-02 09:06:04 -08:00
parent c99cf5518d
commit a73dc72558
23 changed files with 2681 additions and 2604 deletions

View File

@@ -13,6 +13,7 @@ import pytest
import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON
from osxphotos.photoexporter import PhotoExporter
from osxphotos.utils import _get_os_version
OS_VERSION = _get_os_version()
@@ -1142,6 +1143,7 @@ def test_date_invalid():
"""Test date is invalid"""
# doesn't run correctly with the module-level fixture
from datetime import datetime, timedelta, timezone
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
@@ -1396,7 +1398,7 @@ def test_exiftool_newlines_in_description(photosdb):
"""Test that exiftool handles newlines embedded in description, issue #393"""
photo = photosdb.get_photo(UUID_DICT["description_newlines"])
exif = photo._exiftool_dict()
exif = PhotoExporter(photo)._exiftool_dict()
assert photo.description.find("\n") > 0
assert exif["EXIF:ImageDescription"].find("\n") > 0

View File

@@ -4291,7 +4291,7 @@ def test_export_error(monkeypatch):
def throw_error(*args, **kwargs):
raise ValueError("Argh!")
monkeypatch.setattr(osxphotos.PhotoInfo, "export2", throw_error)
monkeypatch.setattr(osxphotos.PhotoExporter, "export2", throw_error)
with runner.isolated_filesystem():
result = runner.invoke(
export,

View File

@@ -2,7 +2,7 @@
import pytest
from osxphotos.photoinfo import ExifInfo
from osxphotos.exifinfo import ExifInfo
PHOTOS_DB_5 = "tests/Test-Cloud-10.15.1.photoslibrary"
PHOTOS_DB_4 = "tests/Test-10.14.6.photoslibrary"
@@ -82,14 +82,14 @@ def photosdb():
def test_exif_info_v5(photosdb):
""" test exif_info """
"""test exif_info"""
for uuid in EXIF_DICT:
photo = photosdb.photos(uuid=[uuid], movies=True)[0]
assert photo.exif_info == EXIF_DICT[uuid]
def test_exif_info_v4():
""" test version 4, exif_info should be None """
"""test version 4, exif_info should be None"""
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_4)

View File

@@ -8,6 +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.utils import dd_to_dms_str
# determine if exiftool installed so exiftool tests can be skipped
@@ -401,7 +402,7 @@ def test_exiftool_json_sidecar(photosdb):
with open(str(pathlib.Path(SIDECAR_DIR) / f"{uuid}.json"), "r") as fp:
json_expected = json.load(fp)[0]
json_got = photo._exiftool_json_sidecar()
json_got = PhotoExporter(photo)._exiftool_json_sidecar()
json_got = json.loads(json_got)[0]
assert json_got == json_expected
@@ -417,7 +418,7 @@ def test_exiftool_json_sidecar_ignore_date_modified(photosdb):
) as fp:
json_expected = json.load(fp)[0]
json_got = photo._exiftool_json_sidecar(ignore_date_modified=True)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(ignore_date_modified=True)
json_got = json.loads(json_got)[0]
assert json_got == json_expected
@@ -448,7 +449,7 @@ def test_exiftool_json_sidecar_keyword_template_long(capsys, photosdb):
long_str = "x" * (_MAX_IPTC_KEYWORD_LEN + 1)
photos[0]._verbose = print
json_got = photos[0]._exiftool_json_sidecar(keyword_template=[long_str])
json_got = PhotoExporter(photos[0])._exiftool_json_sidecar(keyword_template=[long_str])
json_got = json.loads(json_got)[0]
captured = capsys.readouterr()
@@ -483,7 +484,7 @@ 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 = photo._exiftool_json_sidecar(keyword_template=["{folder_album}"])
json_got = PhotoExporter(photo)._exiftool_json_sidecar(keyword_template=["{folder_album}"])
json_got = json.loads(json_got)
assert json_got == json_expected
@@ -499,7 +500,7 @@ def test_exiftool_json_sidecar_use_persons_keyword(photosdb):
) as fp:
json_expected = json.load(fp)[0]
json_got = photo._exiftool_json_sidecar(use_persons_as_keywords=True)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(use_persons_as_keywords=True)
json_got = json.loads(json_got)[0]
assert json_got == json_expected
@@ -515,7 +516,7 @@ def test_exiftool_json_sidecar_use_albums_keywords(photosdb):
) as fp:
json_expected = json.load(fp)
json_got = photo._exiftool_json_sidecar(use_albums_as_keywords=True)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(use_albums_as_keywords=True)
json_got = json.loads(json_got)
assert json_got == json_expected
@@ -528,7 +529,7 @@ def test_exiftool_sidecar(photosdb):
with open(pathlib.Path(SIDECAR_DIR) / f"{uuid}_no_tag_groups.json", "r") as fp:
json_expected = fp.read()
json_got = photo._exiftool_json_sidecar(tag_groups=False)
json_got = PhotoExporter(photo)._exiftool_json_sidecar(tag_groups=False)
assert json_got == json_expected
@@ -554,7 +555,7 @@ def test_xmp_sidecar(photosdb):
with open(f"tests/sidecars/{uuid}.xmp", "r") as file:
xmp_expected = file.read()
xmp_got = photos[0]._xmp_sidecar(extension="jpg")
xmp_got = PhotoExporter(photos[0])._xmp_sidecar(extension="jpg")
assert xmp_got == xmp_expected
@@ -568,7 +569,7 @@ def test_xmp_sidecar_extension(photosdb):
xmp_expected = file.read()
xmp_expected_lines = [line.strip() for line in xmp_expected.split("\n")]
xmp_got = photos[0]._xmp_sidecar()
xmp_got = PhotoExporter(photos[0])._xmp_sidecar()
assert xmp_got == xmp_expected
@@ -580,7 +581,7 @@ 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 = photo._xmp_sidecar(use_persons_as_keywords=True, extension="jpg")
xmp_got = PhotoExporter(photo)._xmp_sidecar(use_persons_as_keywords=True, extension="jpg")
assert xmp_got == xmp_expected
@@ -592,7 +593,7 @@ 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 = photo._xmp_sidecar(use_albums_as_keywords=True, extension="jpg")
xmp_got = PhotoExporter(photo)._xmp_sidecar(use_albums_as_keywords=True, extension="jpg")
assert xmp_got == xmp_expected
@@ -605,7 +606,7 @@ def test_xmp_sidecar_gps(photosdb):
with open(pathlib.Path(SIDECAR_DIR) / f"{uuid}.xmp") as fp:
xmp_expected = fp.read()
xmp_got = photo._xmp_sidecar()
xmp_got = PhotoExporter(photo)._xmp_sidecar()
assert xmp_got == xmp_expected
@@ -617,7 +618,7 @@ def test_xmp_sidecar_keyword_template(photosdb):
with open(pathlib.Path(SIDECAR_DIR) / f"{uuid}_keyword_template.xmp") as fp:
xmp_expected = fp.read()
xmp_got = photo._xmp_sidecar(
xmp_got = PhotoExporter(photo)._xmp_sidecar(
keyword_template=["{created.year}", "{folder_album}"], extension="jpg"
)
assert xmp_got == xmp_expected

View File

@@ -2,6 +2,7 @@ import os
import pytest
from osxphotos._constants import _UNKNOWN_PERSON
from osxphotos.photoexporter import PhotoExporter
skip_test = "OSXPHOTOS_TEST_CONVERT" not in os.environ
pytestmark = pytest.mark.skipif(
@@ -43,7 +44,7 @@ def test_export_convert_raw_to_jpeg(photosdb):
dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["raw"]])
results = photos[0].export2(dest, convert_to_jpeg=True)
results = PhotoExporter(photos[0]).export2(dest, convert_to_jpeg=True)
got_dest = pathlib.Path(results.exported[0])
assert got_dest.is_file()
@@ -60,7 +61,7 @@ def test_export_convert_heic_to_jpeg(photosdb):
dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["heic"]])
results = photos[0].export2(dest, convert_to_jpeg=True)
results = PhotoExporter(photos[0]).export2(dest, convert_to_jpeg=True)
got_dest = pathlib.Path(results.exported[0])
assert got_dest.is_file()
@@ -87,7 +88,7 @@ def test_export_convert_live_heic_to_jpeg():
dest = tempdir.name
photo = photosdb.get_photo(UUID_LIVE_HEIC)
results = photo.export2(dest, convert_to_jpeg=True, live_photo=True)
results = PhotoExporter(photo).export2(dest, convert_to_jpeg=True, live_photo=True)
for name in NAMES_LIVE_HEIC:
assert f"{tempdir.name}/{name}" in results.exported

View File

@@ -1,9 +1,11 @@
import json
import pathlib
import pytest
import json
import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON
import pathlib
from osxphotos.photoexporter import PhotoExporter
PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
PHOTOS_DB_PATH = "/Test-10.14.6.photoslibrary/database/photos.db"
@@ -335,7 +337,7 @@ def test_exiftool_json_sidecar(photosdb):
with open(str(pathlib.Path(SIDECAR_DIR) / f"{uuid}.json"), "r") as fp:
json_expected = json.load(fp)[0]
json_got = photo._exiftool_json_sidecar()
json_got = PhotoExporter(photo)._exiftool_json_sidecar()
json_got = json.loads(json_got)[0]
assert json_got == json_expected
@@ -349,7 +351,7 @@ def test_xmp_sidecar(photosdb):
with open(pathlib.Path(SIDECAR_DIR) / f"{uuid}_ext.xmp") as fp:
xmp_expected = fp.read()
xmp_got = photo._xmp_sidecar(extension="jpg")
xmp_got = PhotoExporter(photo)._xmp_sidecar(extension="jpg")
assert xmp_got == xmp_expected
@@ -362,7 +364,7 @@ def test_xmp_sidecar_keyword_template(photosdb):
with open(pathlib.Path(SIDECAR_DIR) / f"{uuid}_keyword_template.xmp") as fp:
xmp_expected = fp.read()
xmp_got = photo._xmp_sidecar(
xmp_got = PhotoExporter(photo)._xmp_sidecar(
keyword_template=["{created.year}", "{folder_album}"], extension="jpg"
)

View File

@@ -1,7 +1,7 @@
""" test ExportResults class """
import pytest
from osxphotos.photoinfo import ExportResults
from osxphotos.photoexporter import ExportResults
EXPORT_RESULT_ATTRIBUTES = [
"exported",

View File

@@ -13,6 +13,7 @@ import pytest
import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON
from osxphotos.photoexporter import PhotoExporter
from osxphotos.utils import _get_os_version
OS_VERSION = _get_os_version()
@@ -1109,6 +1110,7 @@ def test_date_invalid():
"""Test date is invalid"""
# doesn't run correctly with the module-level fixture
from datetime import datetime, timedelta, timezone
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
@@ -1349,7 +1351,7 @@ def test_exiftool_newlines_in_description(photosdb):
"""Test that exiftool handles newlines embedded in description, issue #393"""
photo = photosdb.get_photo(UUID_DICT["description_newlines"])
exif = photo._exiftool_dict()
exif = PhotoExporter(photo)._exiftool_dict()
assert photo.description.find("\n") > 0
assert exif["EXIF:ImageDescription"].find("\n") > 0

View File

@@ -3,7 +3,7 @@
from math import isclose
import pytest
from osxphotos.photoinfo import ScoreInfo
from osxphotos.scoreinfo import ScoreInfo
PHOTOS_DB_5 = "tests/Test-10.15.5.photoslibrary"
PHOTOS_DB_4 = "tests/Test-10.14.6.photoslibrary"

View File

@@ -9,6 +9,7 @@ import osxphotos
from osxphotos._constants import SIDECAR_XMP
from osxphotos.exiftool import ExifTool, get_exiftool_path
from osxphotos.fileutil import FileUtil
from osxphotos.photoexporter import PhotoExporter
PHOTOS_DB_15_7 = "tests/Test-10.15.7.photoslibrary"
@@ -39,7 +40,7 @@ def test_sidecar_xmp(photosdb):
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos")
dest = tempdir.name
photo = photosdb.get_photo(uuid)
photo.export2(dest, photo.original_filename, sidecar=SIDECAR_XMP)
PhotoExporter(photo).export2(dest, photo.original_filename, sidecar=SIDECAR_XMP)
filepath = str(pathlib.Path(dest) / photo.original_filename)
xmppath = filepath + ".xmp"
@@ -53,6 +54,8 @@ def test_sidecar_xmp(photosdb):
test_xmp = str(pathlib.Path(dest) / "test.xmp")
FileUtil.copy(xmppath, test_xmp)
exif = ExifTool(test_xmp)
output, warning, error = exif.run_commands("-tagsfromfile", xmppath, "-all:all", test_xmp, no_file=True)
output, warning, error = exif.run_commands(
"-tagsfromfile", xmppath, "-all:all", test_xmp, no_file=True
)
assert not warning
assert not error