Add --add-exported-to-album, # 428
This commit is contained in:
@@ -1,9 +1,116 @@
|
||||
""" pytest test configuration """
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
from applescript import AppleScript
|
||||
from photoscript.utils import ditto
|
||||
|
||||
from osxphotos.exiftool import _ExifToolProc
|
||||
|
||||
|
||||
def get_os_version():
|
||||
import platform
|
||||
|
||||
# returns tuple containing OS version
|
||||
# e.g. 10.13.6 = (10, 13, 6)
|
||||
version = platform.mac_ver()[0].split(".")
|
||||
if len(version) == 2:
|
||||
(ver, major) = version
|
||||
minor = "0"
|
||||
elif len(version) == 3:
|
||||
(ver, major, minor) = version
|
||||
else:
|
||||
raise (
|
||||
ValueError(
|
||||
f"Could not parse version string: {platform.mac_ver()} {version}"
|
||||
)
|
||||
)
|
||||
return (ver, major, minor)
|
||||
|
||||
|
||||
OS_VER = get_os_version()[1]
|
||||
if OS_VER == "15":
|
||||
TEST_LIBRARY = "tests/Test-10.15.7.photoslibrary"
|
||||
else:
|
||||
TEST_LIBRARY = None
|
||||
pytest.exit("This test suite currently only runs on MacOS Catalina ")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_singletons():
|
||||
""" Need to clean up any ExifTool singletons between tests """
|
||||
_ExifToolProc.instance = None
|
||||
_ExifToolProc.instance = None
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--addalbum",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="run --add-exported-to-album tests",
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
config.addinivalue_line(
|
||||
"markers", "addalbum: mark test as requiring --addalbum to run"
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
if config.getoption("--addalbum"):
|
||||
# --addalbum given in cli: do not skip addalbum tests (these require interactive test)
|
||||
return
|
||||
skip_addalbum = pytest.mark.skip(reason="need --addalbum option to run")
|
||||
for item in items:
|
||||
if "addalbum" in item.keywords:
|
||||
item.add_marker(skip_addalbum)
|
||||
|
||||
|
||||
def copy_photos_library(photos_library=TEST_LIBRARY, delay=0):
|
||||
""" copy the test library and open Photos, returns path to copied library """
|
||||
script = AppleScript(
|
||||
"""
|
||||
tell application "Photos"
|
||||
quit
|
||||
end tell
|
||||
"""
|
||||
)
|
||||
script.run()
|
||||
src = pathlib.Path(os.getcwd()) / photos_library
|
||||
picture_folder = (
|
||||
pathlib.Path(os.environ["PHOTOSCRIPT_PICTURES_FOLDER"])
|
||||
if "PHOTOSCRIPT_PICTURES_FOLDER" in os.environ
|
||||
else pathlib.Path("~/Pictures")
|
||||
)
|
||||
picture_folder = picture_folder.expanduser()
|
||||
if not picture_folder.is_dir():
|
||||
pytest.exit(f"Invalid picture folder: '{picture_folder}'")
|
||||
dest = picture_folder / photos_library
|
||||
ditto(src, dest)
|
||||
script = AppleScript(
|
||||
f"""
|
||||
set tries to 0
|
||||
repeat while tries < 5
|
||||
try
|
||||
tell application "Photos"
|
||||
activate
|
||||
delay 3
|
||||
open POSIX file "{dest}"
|
||||
delay {delay}
|
||||
end tell
|
||||
set tries to 5
|
||||
on error
|
||||
set tries to tries + 1
|
||||
end try
|
||||
end repeat
|
||||
"""
|
||||
)
|
||||
script.run()
|
||||
return dest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def addalbum_library():
|
||||
copy_photos_library(delay=10)
|
||||
|
||||
File diff suppressed because one or more lines are too long
92
tests/test_cli_add_to_album.py
Normal file
92
tests/test_cli_add_to_album.py
Normal file
@@ -0,0 +1,92 @@
|
||||
""" Test --add-exported-to-album """
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from click.testing import CliRunner
|
||||
import photoscript
|
||||
|
||||
UUID_EXPORT = {"3DD2C897-F19E-4CA6-8C22-B027D5A71907": {"filename": "IMG_4547.jpg"}}
|
||||
UUID_MISSING = {
|
||||
"8E1D7BC9-9321-44F9-8CFB-4083F6B9232A": {"filename": "IMG_2000.JPGssss"}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.addalbum
|
||||
def test_export_add_to_album(addalbum_library):
|
||||
from osxphotos.cli import export
|
||||
|
||||
runner = CliRunner()
|
||||
cwd = os.getcwd()
|
||||
with runner.isolated_filesystem():
|
||||
EXPORT_ALBUM = "OSXPhotos Export"
|
||||
SKIP_ALBUM = "OSXPhotos Skipped"
|
||||
MISSING_ALBUM = "OSXPhotos Missing"
|
||||
|
||||
uuid_opt = [f"--uuid={uuid}" for uuid in UUID_EXPORT]
|
||||
uuid_opt += [f"--uuid={uuid}" for uuid in UUID_MISSING]
|
||||
|
||||
result = runner.invoke(
|
||||
export,
|
||||
[
|
||||
".",
|
||||
"-V",
|
||||
"--add-exported-to-album",
|
||||
EXPORT_ALBUM,
|
||||
"--add-skipped-to-album",
|
||||
SKIP_ALBUM,
|
||||
*uuid_opt,
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert f"Creating Photos album '{EXPORT_ALBUM}'" in result.output
|
||||
assert f"Creating Photos album '{SKIP_ALBUM}'" in result.output
|
||||
|
||||
photoslib = photoscript.PhotosLibrary()
|
||||
album = photoslib.album(EXPORT_ALBUM)
|
||||
assert album is not None
|
||||
|
||||
assert len(album) == len(UUID_EXPORT)
|
||||
got_uuids = [p.uuid for p in album.photos()]
|
||||
assert sorted(got_uuids) == sorted(list(UUID_EXPORT.keys()))
|
||||
|
||||
skip_album = photoslib.album(SKIP_ALBUM)
|
||||
assert skip_album is not None
|
||||
assert len(skip_album) == 0
|
||||
|
||||
result = runner.invoke(
|
||||
export,
|
||||
[
|
||||
".",
|
||||
"-V",
|
||||
"--add-exported-to-album",
|
||||
EXPORT_ALBUM,
|
||||
"--add-skipped-to-album",
|
||||
SKIP_ALBUM,
|
||||
"--add-missing-to-album",
|
||||
MISSING_ALBUM,
|
||||
"--update",
|
||||
*uuid_opt,
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert f"Creating Photos album '{EXPORT_ALBUM}'" not in result.output
|
||||
assert f"Creating Photos album '{SKIP_ALBUM}'" not in result.output
|
||||
assert f"Creating Photos album '{MISSING_ALBUM}'" in result.output
|
||||
|
||||
photoslib = photoscript.PhotosLibrary()
|
||||
export_album = photoslib.album(EXPORT_ALBUM)
|
||||
assert export_album is not None
|
||||
assert len(export_album) == len(UUID_EXPORT)
|
||||
|
||||
skip_album = photoslib.album(SKIP_ALBUM)
|
||||
assert skip_album is not None
|
||||
assert len(skip_album) == len(UUID_EXPORT)
|
||||
got_uuids = [p.uuid for p in skip_album.photos()]
|
||||
assert sorted(got_uuids) == sorted(list(UUID_EXPORT.keys()))
|
||||
|
||||
missing_album = photoslib.album(MISSING_ALBUM)
|
||||
assert missing_album is not None
|
||||
assert len(missing_album) == len(UUID_MISSING)
|
||||
got_uuids = [p.uuid for p in missing_album.photos()]
|
||||
assert sorted(got_uuids) == sorted(list(UUID_MISSING.keys()))
|
||||
|
||||
@@ -47,6 +47,9 @@ def test_exportresults_init():
|
||||
assert results.exiftool_error == []
|
||||
assert results.deleted_files == []
|
||||
assert results.deleted_directories == []
|
||||
assert results.exported_album == []
|
||||
assert results.skipped_album == []
|
||||
assert results.missing_album == []
|
||||
|
||||
|
||||
def test_exportresults_iadd():
|
||||
@@ -110,6 +113,6 @@ def test_str():
|
||||
results = ExportResults()
|
||||
assert (
|
||||
str(results)
|
||||
== "ExportResults(exported=[],new=[],updated=[],skipped=[],exif_updated=[],touched=[],converted_to_jpeg=[],sidecar_json_written=[],sidecar_json_skipped=[],sidecar_exiftool_written=[],sidecar_exiftool_skipped=[],sidecar_xmp_written=[],sidecar_xmp_skipped=[],missing=[],error=[],exiftool_warning=[],exiftool_error=[],deleted_files=[],deleted_directories=[])"
|
||||
== "ExportResults(exported=[],new=[],updated=[],skipped=[],exif_updated=[],touched=[],converted_to_jpeg=[],sidecar_json_written=[],sidecar_json_skipped=[],sidecar_exiftool_written=[],sidecar_exiftool_skipped=[],sidecar_xmp_written=[],sidecar_xmp_skipped=[],missing=[],error=[],exiftool_warning=[],exiftool_error=[],deleted_files=[],deleted_directories=[],exported_album=[],skipped_album=[],missing_album=[])"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user