Feature timewarp (#675)
* Implemented timewarp command * Updated docs * Added missing pytest mark
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
""" pytest test configuration """
|
||||
import os
|
||||
import pathlib
|
||||
import tempfile
|
||||
|
||||
import photoscript
|
||||
import pytest
|
||||
from applescript import AppleScript
|
||||
from photoscript.utils import ditto
|
||||
@@ -10,6 +12,8 @@ from osxphotos.exiftool import _ExifToolProc
|
||||
|
||||
from .test_catalina_10_15_7 import UUID_DICT_LOCAL
|
||||
|
||||
TEST_TIMEWARP = False
|
||||
|
||||
|
||||
def get_os_version():
|
||||
import platform
|
||||
@@ -34,11 +38,20 @@ def get_os_version():
|
||||
OS_VER = get_os_version()[1]
|
||||
if OS_VER == "15":
|
||||
TEST_LIBRARY = "tests/Test-10.15.7.photoslibrary"
|
||||
from tests.config_timewarp_catalina import TEST_LIBRARY_TIMEWARP
|
||||
else:
|
||||
TEST_LIBRARY = None
|
||||
TEST_LIBRARY_TIMEWARP = None
|
||||
# pytest.exit("This test suite currently only runs on MacOS Catalina ")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def setup_photos_timewarp():
|
||||
if not TEST_TIMEWARP:
|
||||
return
|
||||
copy_photos_library(TEST_LIBRARY_TIMEWARP, delay=10)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_singletons():
|
||||
"""Need to clean up any ExifTool singletons between tests"""
|
||||
@@ -52,28 +65,46 @@ def pytest_addoption(parser):
|
||||
default=False,
|
||||
help="run --add-exported-to-album tests",
|
||||
)
|
||||
parser.addoption(
|
||||
"--timewarp", action="store_true", default=False, help="run --timewarp tests"
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
if config.getoption("--addalbum") and config.getoption("--timewarp"):
|
||||
pytest.exit("--addalbum and --timewarp are mutually exclusive")
|
||||
|
||||
config.addinivalue_line(
|
||||
"markers", "addalbum: mark test as requiring --addalbum to run"
|
||||
)
|
||||
config.addinivalue_line(
|
||||
"markers", "timewarp: mark test as requiring --timewarp to run"
|
||||
)
|
||||
|
||||
if config.getoption("--timewarp"):
|
||||
global TEST_TIMEWARP
|
||||
TEST_TIMEWARP = True
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
if config.getoption("--addalbum") and TEST_LIBRARY is not None:
|
||||
# --addalbum given in cli: do not skip addalbum tests (these require interactive test)
|
||||
return
|
||||
if not (config.getoption("--addalbum") and TEST_LIBRARY is not None):
|
||||
skip_addalbum = pytest.mark.skip(
|
||||
reason="need --addalbum option and MacOS Catalina to run"
|
||||
)
|
||||
for item in items:
|
||||
if "addalbum" in item.keywords:
|
||||
item.add_marker(skip_addalbum)
|
||||
|
||||
skip_addalbum = pytest.mark.skip(
|
||||
reason="need --addalbum option and MacOS Catalina to run"
|
||||
)
|
||||
for item in items:
|
||||
if "addalbum" in item.keywords:
|
||||
item.add_marker(skip_addalbum)
|
||||
if not (config.getoption("--timewarp") and TEST_LIBRARY_TIMEWARP is not None):
|
||||
skip_timewarp = pytest.mark.skip(
|
||||
reason="need --timewarp option and MacOS Catalina to run"
|
||||
)
|
||||
for item in items:
|
||||
if "timewarp" in item.keywords:
|
||||
item.add_marker(skip_timewarp)
|
||||
|
||||
|
||||
def copy_photos_library(photos_library=TEST_LIBRARY, delay=0):
|
||||
def copy_photos_library(photos_library, delay=0):
|
||||
"""copy the test library and open Photos, returns path to copied library"""
|
||||
script = AppleScript(
|
||||
"""
|
||||
@@ -134,3 +165,33 @@ def delete_crash_logs():
|
||||
path = pathlib.Path(os.getcwd()) / "osxphotos_crash.log"
|
||||
if path.is_file():
|
||||
path.unlink()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def photoslib():
|
||||
return photoscript.PhotosLibrary()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def suspend_capture(pytestconfig):
|
||||
class suspend_guard:
|
||||
def __init__(self):
|
||||
self.capmanager = pytestconfig.pluginmanager.getplugin("capturemanager")
|
||||
|
||||
def __enter__(self):
|
||||
self.capmanager.suspend_global_capture(in_=True)
|
||||
|
||||
def __exit__(self, _1, _2, _3):
|
||||
self.capmanager.resume_global_capture()
|
||||
|
||||
yield suspend_guard()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def output_file():
|
||||
"""Create a temporary filename for writing output"""
|
||||
tempdir = tempfile.gettempdir()
|
||||
fd, filename = tempfile.mkstemp(dir=tempdir)
|
||||
os.close(fd)
|
||||
yield filename
|
||||
os.remove(filename)
|
||||
|
||||
Reference in New Issue
Block a user