fixed formatting (#1096)

This commit is contained in:
Rhet Turnbull 2023-06-18 16:22:46 -07:00 committed by GitHub
parent 492e1edb7f
commit 2c80226ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
88 changed files with 187 additions and 189 deletions

View File

@ -21,7 +21,6 @@ from osxphotos.sqlitekvstore import SQLiteKVStore
class Latitude(click.ParamType): class Latitude(click.ParamType):
name = "Latitude" name = "Latitude"
def convert(self, value, param, ctx): def convert(self, value, param, ctx):
@ -37,7 +36,6 @@ class Latitude(click.ParamType):
class Longitude(click.ParamType): class Longitude(click.ParamType):
name = "Longitude" name = "Longitude"
def convert(self, value, param, ctx): def convert(self, value, param, ctx):

View File

@ -23,10 +23,7 @@ to your function. You can then do whatever you want with the photos.
from __future__ import annotations from __future__ import annotations
import osxphotos import osxphotos
from osxphotos.cli import ( from osxphotos.cli import selection_command, verbose
selection_command,
verbose,
)
@selection_command @selection_command

View File

@ -2,9 +2,10 @@
import sys import sys
import osxphotos
import click import click
import osxphotos
@click.command() @click.command()
@click.argument("album1") @click.argument("album1")

View File

@ -1,6 +1,7 @@
import osxphotos
import os.path import os.path
import osxphotos
def main(): def main():
db = osxphotos.utils.get_system_library_path() db = osxphotos.utils.get_system_library_path()

View File

@ -32,7 +32,7 @@ import osxphotos
default=False, default=False,
) )
def export(export_path, default_album, library_path, edited): def export(export_path, default_album, library_path, edited):
""" Export all photos, organized by album """ """Export all photos, organized by album"""
export_path = os.path.expanduser(export_path) export_path = os.path.expanduser(export_path)
library_path = os.path.expanduser(library_path) if library_path else None library_path = os.path.expanduser(library_path) if library_path else None

View File

@ -32,7 +32,7 @@ import osxphotos
default=None, default=None,
) )
def export(export_path, library_path, uuid): def export(export_path, library_path, uuid):
""" export photos to export_path and draw faces """ """export photos to export_path and draw faces"""
library_path = os.path.expanduser(library_path) if library_path else None library_path = os.path.expanduser(library_path) if library_path else None
if library_path is not None: if library_path is not None:
photosdb = osxphotos.PhotosDB(library_path) photosdb = osxphotos.PhotosDB(library_path)
@ -61,7 +61,7 @@ def export(export_path, library_path, uuid):
def get_circle_points(xy, radius): def get_circle_points(xy, radius):
""" Returns tuples of (x0, y0), (x1, y1) for a circle centered at x, y with radius """Returns tuples of (x0, y0), (x1, y1) for a circle centered at x, y with radius
Arguments: Arguments:
xy: tuple of x, y coordinates xy: tuple of x, y coordinates

View File

@ -77,7 +77,9 @@ def place_folder(photo: osxphotos.PhotoInfo) -> str:
return "" return ""
def photos_folders(photo: osxphotos.PhotoInfo, options: osxphotos.phototemplate.RenderOptions, **kwargs) -> Union[List, str]: def photos_folders(
photo: osxphotos.PhotoInfo, options: osxphotos.phototemplate.RenderOptions, **kwargs
) -> Union[List, str]:
"""template function for use with --directory to export photos in a folder structure similar to Photos """template function for use with --directory to export photos in a folder structure similar to Photos
Args: Args:

View File

@ -29,7 +29,9 @@ def main():
exported = photo.export(tempdir.name, use_photos_export=True, timeout=300) exported = photo.export(tempdir.name, use_photos_export=True, timeout=300)
if photo.hasadjustments: if photo.hasadjustments:
exported.extend( exported.extend(
photo.export(tempdir.name, use_photos_export=True, edited=True, timeout=300) photo.export(
tempdir.name, use_photos_export=True, edited=True, timeout=300
)
) )
for filename in exported: for filename in exported:
print(f"Removing temporary file {filename}") print(f"Removing temporary file {filename}")

View File

@ -10,7 +10,7 @@ from osxphotos._constants import TIME_DELTA
@dataclass @dataclass
class Comment: class Comment:
""" Class for shared photo comments """ """Class for shared photo comments"""
uuid: str uuid: str
sort_fok: int sort_fok: int
@ -22,7 +22,7 @@ class Comment:
@dataclass @dataclass
class Like: class Like:
""" Class for shared photo likes """ """Class for shared photo likes"""
uuid: str uuid: str
sort_fok: int sort_fok: int
@ -32,7 +32,7 @@ class Like:
def get_shared_person_info(photosdb, hashed_person_id): def get_shared_person_info(photosdb, hashed_person_id):
""" returns tuple of (first name, last name, full name) """returns tuple of (first name, last name, full name)
for person invited to shared album with for person invited to shared album with
ZINVITEEHASHEDPERSONID = hashed_person_id ZINVITEEHASHEDPERSONID = hashed_person_id
@ -66,7 +66,7 @@ def get_shared_person_info(photosdb, hashed_person_id):
def get_comments(photosdb, uuid): def get_comments(photosdb, uuid):
""" return comments and likes, if any, for photo with uuid """return comments and likes, if any, for photo with uuid
Args: Args:
photosdb: a osxphotos.PhotosDB object photosdb: a osxphotos.PhotosDB object

View File

@ -15,11 +15,11 @@ import time
import click import click
import osxphotos import osxphotos
from osxphotos.cli import get_photos_db, _list_libraries from osxphotos.cli import _list_libraries, get_photos_db
def show(photo): def show(photo):
""" open image with default image viewer """open image with default image viewer
Note: This is for debugging only -- it will actually open any filetype which could Note: This is for debugging only -- it will actually open any filetype which could
be very, very bad. be very, very bad.

View File

@ -1,8 +1,10 @@
""" Example function for use with osxphotos import --post-function option """ """ Example function for use with osxphotos import --post-function option """
import typing as t
import photoscript
import pathlib import pathlib
import typing as t
import photoscript
from osxphotos.cli.import_cli import ReportRecord from osxphotos.cli.import_cli import ReportRecord

View File

@ -3,6 +3,7 @@ import os.path
import osxphotos import osxphotos
def main(): def main():
db = os.path.expanduser("~/Pictures/Photos Library.photoslibrary") db = os.path.expanduser("~/Pictures/Photos Library.photoslibrary")
photosdb = osxphotos.PhotosDB(db) photosdb = osxphotos.PhotosDB(db)
@ -15,11 +16,14 @@ def main():
print(photosdb.albums_as_dict) print(photosdb.albums_as_dict)
# find all photos with Keyword = Foo and containing John Smith # find all photos with Keyword = Foo and containing John Smith
photos = photosdb.photos(keywords=["Foo"],persons=["John Smith"]) photos = photosdb.photos(keywords=["Foo"], persons=["John Smith"])
# find all photos that include Alice Smith but do not contain the keyword Bar # find all photos that include Alice Smith but do not contain the keyword Bar
photos = [p for p in photosdb.photos(persons=["Alice Smith"]) photos = [
if p not in photosdb.photos(keywords=["Bar"]) ] p
for p in photosdb.photos(persons=["Alice Smith"])
if p not in photosdb.photos(keywords=["Bar"])
]
for p in photos: for p in photos:
print( print(
p.uuid, p.uuid,
@ -34,5 +38,6 @@ def main():
p.path, p.path,
) )
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -10,8 +10,8 @@
from typing import List from typing import List
def myfilter(values: List[str]) -> List[str]: def myfilter(values: List[str]) -> List[str]:
""" Custom filter to append "foo-" to template value """ """Custom filter to append "foo-" to template value"""
values = ["foo-" + val for val in values] values = ["foo-" + val for val in values]
return values return values

View File

@ -5,7 +5,6 @@ import sys
from rich import print from rich import print
from rich.traceback import install as install_traceback from rich.traceback import install as install_traceback
from osxphotos.utils import is_macos
from osxphotos.debug import ( from osxphotos.debug import (
debug_breakpoint, debug_breakpoint,
debug_watch, debug_watch,
@ -14,6 +13,7 @@ from osxphotos.debug import (
set_debug, set_debug,
wrap_function, wrap_function,
) )
from osxphotos.utils import is_macos
# apply any debug functions # apply any debug functions
# need to do this before importing anything else so that the debug functions # need to do this before importing anything else so that the debug functions

View File

@ -3,11 +3,12 @@
from __future__ import annotations from __future__ import annotations
import functools
from typing import Any, Callable
import click
import contextlib import contextlib
import functools
from textwrap import dedent from textwrap import dedent
from typing import Any, Callable
import click
from ..utils import is_macos from ..utils import is_macos
from .common import OSXPHOTOS_HIDDEN, print_version from .common import OSXPHOTOS_HIDDEN, print_version

View File

@ -2,10 +2,9 @@
from osxphotos.utils import is_macos from osxphotos.utils import is_macos
if is_macos: if is_macos:
import objc
import Foundation import Foundation
import objc
def theme(): def theme():
with objc.autorelease_pool(): with objc.autorelease_pool():

View File

@ -19,14 +19,14 @@ from osxphotos.export_db_utils import (
export_db_backup, export_db_backup,
export_db_check_signatures, export_db_check_signatures,
export_db_get_errors, export_db_get_errors,
export_db_get_last_library,
export_db_get_last_run, export_db_get_last_run,
export_db_get_version, export_db_get_version,
export_db_migrate_photos_library,
export_db_save_config_to_file, export_db_save_config_to_file,
export_db_touch_files, export_db_touch_files,
export_db_update_signatures, export_db_update_signatures,
export_db_vacuum, export_db_vacuum,
export_db_migrate_photos_library,
export_db_get_last_library,
) )
from osxphotos.utils import pluralize from osxphotos.utils import pluralize

View File

@ -1,6 +1,7 @@
"""query command for osxphotos CLI""" """query command for osxphotos CLI"""
import sys import sys
import click import click
import osxphotos import osxphotos

View File

@ -8,7 +8,7 @@ import click
from osxphotos._constants import UUID_PATTERN from osxphotos._constants import UUID_PATTERN
from osxphotos.export_db_utils import get_uuid_for_filepath from osxphotos.export_db_utils import get_uuid_for_filepath
from osxphotos.photosdb.photosdb_utils import get_photos_library_version from osxphotos.photosdb.photosdb_utils import get_photos_library_version
from osxphotos.utils import get_last_library_path, assert_macos from osxphotos.utils import assert_macos, get_last_library_path
assert_macos() assert_macos()

View File

@ -30,6 +30,7 @@ from osxphotos.utils import assert_macos, noop, pluralize
assert_macos() assert_macos()
from photoscript import PhotosLibrary from photoscript import PhotosLibrary
from osxphotos.photosalbum import PhotosAlbumPhotoScript from osxphotos.photosalbum import PhotosAlbumPhotoScript
from .cli_params import THEME_OPTION, TIMESTAMP_OPTION, VERBOSE_OPTION from .cli_params import THEME_OPTION, TIMESTAMP_OPTION, VERBOSE_OPTION

View File

@ -1,11 +1,14 @@
"""about command for osxphotos CLI""" """about command for osxphotos CLI"""
import click
import os import os
import click
import packaging
from osxphotos._constants import OSXPHOTOS_URL from osxphotos._constants import OSXPHOTOS_URL
from osxphotos._version import __version__ from osxphotos._version import __version__
from .common import get_latest_version from .common import get_latest_version
import packaging
@click.command(name="version") @click.command(name="version")

View File

@ -12,6 +12,7 @@ from .utils import assert_macos, noop
assert_macos() assert_macos()
from photoscript import Photo from photoscript import Photo
from .exif_datetime_updater import get_exif_date_time_offset from .exif_datetime_updater import get_exif_date_time_offset
from .phototz import PhotoTimeZone from .phototz import PhotoTimeZone

View File

@ -13,8 +13,8 @@ from wurlitzer import pipes
from .utils import is_macos from .utils import is_macos
if is_macos: if is_macos:
import objc
import Metal import Metal
import objc
import Quartz import Quartz
from Cocoa import NSURL from Cocoa import NSURL
from Foundation import NSDictionary from Foundation import NSDictionary

View File

@ -101,7 +101,9 @@ class PhotosAlbum:
try: try:
photos.append(photoscript.Photo(p.uuid)) photos.append(photoscript.Photo(p.uuid))
except Exception as e: except Exception as e:
print(f"Error creating Photo object for photo {self._format_uuid(p.uuid)}: {e}") print(
f"Error creating Photo object for photo {self._format_uuid(p.uuid)}: {e}"
)
self.verbose( self.verbose(
f"Error creating Photo object for photo {self._format_uuid(p.uuid)}: {e}" f"Error creating Photo object for photo {self._format_uuid(p.uuid)}: {e}"
) )

View File

@ -4,4 +4,4 @@ Processes a Photos.app library database to extract information about photos
""" """
from .photosdb import PhotosDB from .photosdb import PhotosDB
from .photosdb_utils import get_db_version, get_db_model_version, get_model_version from .photosdb_utils import get_db_model_version, get_db_version, get_model_version

View File

@ -6,8 +6,8 @@ import datetime
from dataclasses import dataclass from dataclasses import dataclass
from .._constants import _DB_TABLE_NAMES, _PHOTOS_4_VERSION, TIME_DELTA from .._constants import _DB_TABLE_NAMES, _PHOTOS_4_VERSION, TIME_DELTA
from ..utils import normalize_unicode
from ..sqlite_utils import sqlite_open_ro from ..sqlite_utils import sqlite_open_ro
from ..utils import normalize_unicode
def _process_comments(self): def _process_comments(self):

View File

@ -4,7 +4,7 @@
import logging import logging
from .._constants import _DB_TABLE_NAMES, _PHOTOS_4_VERSION from .._constants import _DB_TABLE_NAMES, _PHOTOS_4_VERSION
from ..sqlite_utils import sqlite_open_ro, sqlite_db_is_locked from ..sqlite_utils import sqlite_db_is_locked, sqlite_open_ro
from .photosdb_utils import get_db_version from .photosdb_utils import get_db_version

View File

@ -2,11 +2,11 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
from .._constants import _DB_TABLE_NAMES from .._constants import _DB_TABLE_NAMES
from ..sqlite_utils import sqlite_open_ro from ..sqlite_utils import sqlite_open_ro
from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from osxphotos.photosdb import PhotosDB from osxphotos.photosdb import PhotosDB

View File

@ -61,9 +61,9 @@ from ..rich_utils import add_rich_markup_tag
from ..sqlite_utils import sqlite_db_is_locked, sqlite_open_ro from ..sqlite_utils import sqlite_db_is_locked, sqlite_open_ro
from ..utils import ( from ..utils import (
_check_file_exists, _check_file_exists,
is_macos,
get_macos_version,
get_last_library_path, get_last_library_path,
get_macos_version,
is_macos,
noop, noop,
normalize_unicode, normalize_unicode,
) )

View File

@ -1,6 +1,6 @@
""" ScoreInfo class to expose computed score info from the library """ """ ScoreInfo class to expose computed score info from the library """
from dataclasses import dataclass, asdict from dataclasses import asdict, dataclass
from ._constants import _PHOTOS_4_VERSION from ._constants import _PHOTOS_4_VERSION

View File

@ -1,9 +1,8 @@
"""Utilities for working with datetimes""" """Utilities for working with datetimes"""
import datetime import datetime
from typing import Optional
import re import re
from typing import Optional
def utc_offset_string_to_seconds(utc_offset: str) -> int: def utc_offset_string_to_seconds(utc_offset: str) -> int:

View File

@ -24,7 +24,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
from .utils import assert_macos, is_macos, get_macos_version from .utils import assert_macos, get_macos_version, is_macos
if is_macos: if is_macos:
import CoreServices import CoreServices

View File

@ -18,7 +18,6 @@ if is_macos:
from osxphotos.exiftool import _ExifToolProc from osxphotos.exiftool import _ExifToolProc
# run timewarp tests (configured with --timewarp) # run timewarp tests (configured with --timewarp)
TEST_TIMEWARP = False TEST_TIMEWARP = False

View File

@ -7,7 +7,7 @@
import pathlib import pathlib
import osxphotos import osxphotos
from osxphotos.photoexporter import PhotoExporter, ExportOptions from osxphotos.photoexporter import ExportOptions, PhotoExporter
PHOTOS_DB_15_7 = "./tests/Test-10.15.7.photoslibrary/database/photos.db" PHOTOS_DB_15_7 = "./tests/Test-10.15.7.photoslibrary/database/photos.db"
PHOTOS_DB_14_6 = "./tests/Test-10.14.6.photoslibrary/database/photos.db" PHOTOS_DB_14_6 = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
@ -92,9 +92,7 @@ def generate_sidecars(dbname, uuid_dict):
# ignore_date_modified # ignore_date_modified
sidecar = str(pathlib.Path(SIDECAR_DIR) / f"{uuid}_ignore_date_modified.json") sidecar = str(pathlib.Path(SIDECAR_DIR) / f"{uuid}_ignore_date_modified.json")
json_ = exporter.exiftool_json_sidecar( json_ = exporter.exiftool_json_sidecar(ExportOptions(ignore_date_modified=True))
ExportOptions(ignore_date_modified=True)
)
with open(sidecar, "w") as file: with open(sidecar, "w") as file:
file.write(json_) file.write(json_)

View File

@ -7,7 +7,7 @@ import osxphotos
def foo(photo: osxphotos.PhotoInfo, **kwargs) -> Union[List, str]: def foo(photo: osxphotos.PhotoInfo, **kwargs) -> Union[List, str]:
""" example function for {function} template """example function for {function} template
Args: Args:
photo: osxphotos.PhotoInfo object photo: osxphotos.PhotoInfo object

View File

@ -8,10 +8,10 @@ import time
class TempDiskImage: class TempDiskImage:
""" Create and mount a temporary disk image """ """Create and mount a temporary disk image"""
def __init__(self, size=100, prefix=None): def __init__(self, size=100, prefix=None):
""" Create and mount a temporary disk image. """Create and mount a temporary disk image.
Args: Args:
size: int; size in MB of disk image, default = 100 size: int; size in MB of disk image, default = 100
@ -59,7 +59,7 @@ class TempDiskImage:
self._mount_point, self.name = self._mount_image(self.path) self._mount_point, self.name = self._mount_image(self.path)
def _mount_image(self, image_path): def _mount_image(self, image_path):
""" mount a DMG file and return path, returns (mount_point, path) """ """mount a DMG file and return path, returns (mount_point, path)"""
hdiutil = subprocess.run( hdiutil = subprocess.run(
["/usr/bin/hdiutil", "attach", image_path], ["/usr/bin/hdiutil", "attach", image_path],
check=True, check=True,

View File

@ -10,8 +10,8 @@
from typing import List from typing import List
def myfilter(values: List[str]) -> List[str]: def myfilter(values: List[str]) -> List[str]:
""" Custom filter to append "foo-" to template value """ """Custom filter to append "foo-" to template value"""
values = ["foo-" + val for val in values] values = ["foo-" + val for val in values]
return values return values

View File

@ -7,7 +7,7 @@ import osxphotos
def foo(photo: osxphotos.PhotoInfo, **kwargs) -> Union[List, str]: def foo(photo: osxphotos.PhotoInfo, **kwargs) -> Union[List, str]:
""" example function for {function} template """example function for {function} template
Args: Args:
photo: osxphotos.PhotoInfo object photo: osxphotos.PhotoInfo object

View File

@ -62,7 +62,6 @@ def test_photos_version(photosdb):
def test_persons(photosdb): def test_persons(photosdb):
assert "Katie" in photosdb.persons assert "Katie" in photosdb.persons
assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons) assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons)

View File

@ -1,7 +1,6 @@
import pytest import pytest
import osxphotos import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON, AlbumSortOrder from osxphotos._constants import _UNKNOWN_PERSON, AlbumSortOrder
PHOTOS_DB = "./tests/Test-10.15.7.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.15.7.photoslibrary/database/photos.db"

View File

@ -1,7 +1,6 @@
import pytest import pytest
import osxphotos import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
PHOTOS_DB = "./tests/Test-10.13.6.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.13.6.photoslibrary/database/photos.db"

View File

@ -1,7 +1,6 @@
import pytest import pytest
import osxphotos import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db"

View File

@ -226,6 +226,7 @@ def test_init4():
# test invalid db # test invalid db
import os import os
import tempfile import tempfile
import osxphotos import osxphotos
(bad_db, bad_db_name) = tempfile.mkstemp(suffix=".db", prefix="osxphotos-") (bad_db, bad_db_name) = tempfile.mkstemp(suffix=".db", prefix="osxphotos-")
@ -606,7 +607,6 @@ def test_keyword_2(photosdb):
def test_keyword_not_in_album(photosdb): def test_keyword_not_in_album(photosdb):
# find all photos with keyword "Kids" not in the album "Pumpkin Farm" # find all photos with keyword "Kids" not in the album "Pumpkin Farm"
photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos1 = photosdb.photos(albums=["Pumpkin Farm"])
photos2 = photosdb.photos(keywords=["Kids"]) photos2 = photosdb.photos(keywords=["Kids"])
@ -1024,6 +1024,7 @@ def test_date_invalid():
"""Test date is invalid""" """Test date is invalid"""
# doesn't run correctly with the module-level fixture # doesn't run correctly with the module-level fixture
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
import osxphotos import osxphotos
# UUID_DICT["date_invalid"] has an invalid date that's # UUID_DICT["date_invalid"] has an invalid date that's

View File

@ -15,7 +15,7 @@ import pytest
import osxphotos import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
from osxphotos.photoexporter import PhotoExporter from osxphotos.photoexporter import PhotoExporter
from osxphotos.utils import is_macos, get_macos_version from osxphotos.utils import get_macos_version, is_macos
OS_VERSION = get_macos_version() if is_macos else (None, None, None) OS_VERSION = get_macos_version() if is_macos else (None, None, None)
SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "15" SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "15"

View File

@ -14,9 +14,9 @@ import subprocess
import tempfile import tempfile
import time import time
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from bitmath import contextlib
import pytest import pytest
from bitmath import contextlib
from click.testing import CliRunner from click.testing import CliRunner
import osxphotos import osxphotos

View File

@ -4,8 +4,10 @@ import pytest
from click.testing import CliRunner from click.testing import CliRunner
from osxphotos.utils import is_macos from osxphotos.utils import is_macos
if is_macos: if is_macos:
import photoscript import photoscript
from osxphotos.cli.add_locations import add_locations from osxphotos.cli.add_locations import add_locations
else: else:
pytest.skip(allow_module_level=True) pytest.skip(allow_module_level=True)

View File

@ -6,6 +6,7 @@ import pytest
from click.testing import CliRunner from click.testing import CliRunner
from osxphotos.utils import is_macos from osxphotos.utils import is_macos
if is_macos: if is_macos:
import photoscript import photoscript
else: else:

View File

@ -24,6 +24,7 @@ TEST_RUN_SCRIPT = "examples/cli_example_1.py"
def runner() -> CliRunner: def runner() -> CliRunner:
return CliRunner() return CliRunner()
from osxphotos.cli import ( from osxphotos.cli import (
about, about,
albums, albums,
@ -43,7 +44,6 @@ from osxphotos.cli import (
tutorial, tutorial,
version, version,
) )
from osxphotos.utils import is_macos from osxphotos.utils import is_macos
if is_macos: if is_macos:
@ -72,7 +72,8 @@ def test_about(runner: CliRunner):
places, places,
tutorial, tutorial,
version, version,
] + ([uuid] if is_macos else []), ]
+ ([uuid] if is_macos else []),
) )
def test_cli_comands(runner: CliRunner, command: Callable[..., Any]): def test_cli_comands(runner: CliRunner, command: Callable[..., Any]):
with runner.isolated_filesystem(): with runner.isolated_filesystem():

View File

@ -13,6 +13,7 @@ from osxphotos.utils import is_macos
if is_macos: if is_macos:
import photoscript import photoscript
from osxphotos.cli.batch_edit import batch_edit from osxphotos.cli.batch_edit import batch_edit
else: else:
pytest.skip(allow_module_level=True) pytest.skip(allow_module_level=True)

View File

@ -91,11 +91,12 @@ def test_dump_field(photos):
"name", "name",
"{photo.original_filename}", "{photo.original_filename}",
], ],
) )
assert result.exit_code == 0 assert result.exit_code == 0
for photo in photos: for photo in photos:
assert f"{photo.uuid},{photo.original_filename}" in result.output assert f"{photo.uuid},{photo.original_filename}" in result.output
def test_dump_field_json(photos): def test_dump_field_json(photos):
"""Test osxphotos dump --field --jso""" """Test osxphotos dump --field --jso"""
runner = CliRunner() runner = CliRunner()
@ -117,7 +118,7 @@ def test_dump_field_json(photos):
"{photo.original_filename}", "{photo.original_filename}",
"--json", "--json",
], ],
) )
assert result.exit_code == 0 assert result.exit_code == 0
json_data = {record["uuid"]: record for record in json.loads(result.output)} json_data = {record["uuid"]: record for record in json.loads(result.output)}
for photo in photos: for photo in photos:

View File

@ -14,7 +14,6 @@ from tempfile import TemporaryDirectory
from typing import Dict from typing import Dict
import pytest import pytest
from click.testing import CliRunner from click.testing import CliRunner
from pytest import MonkeyPatch, approx from pytest import MonkeyPatch, approx
@ -27,6 +26,7 @@ from tests.conftest import get_os_version
if is_macos: if is_macos:
from photoscript import Photo from photoscript import Photo
from osxphotos.cli.import_cli import import_cli from osxphotos.cli.import_cli import import_cli
else: else:
pytest.skip(allow_module_level=True) pytest.skip(allow_module_level=True)

View File

@ -1,12 +1,9 @@
""" Test custom click paramater types used by osxphotos CLI""" """ Test custom click paramater types used by osxphotos CLI"""
import datetime import datetime
from bitmath import MB
import pytest import pytest
from bitmath import MB
from osxphotos.timezones import Timezone
from click.exceptions import BadParameter from click.exceptions import BadParameter
from osxphotos.cli.param_types import ( from osxphotos.cli.param_types import (
@ -21,6 +18,7 @@ from osxphotos.cli.param_types import (
TimeString, TimeString,
UTCOffset, UTCOffset,
) )
from osxphotos.timezones import Timezone
def test_date_offset(): def test_date_offset():

View File

@ -1,13 +1,16 @@
"""Test osxphotos sync command""" """Test osxphotos sync command"""
import os
import json import json
import os
import pytest import pytest
from click.testing import CliRunner from click.testing import CliRunner
from osxphotos.utils import is_macos from osxphotos.utils import is_macos
if is_macos: if is_macos:
import photoscript import photoscript
from osxphotos.cli.sync import sync from osxphotos.cli.sync import sync
else: else:
pytest.skip(allow_module_level=True) pytest.skip(allow_module_level=True)

View File

@ -3,13 +3,12 @@
import re import re
from io import StringIO from io import StringIO
from osxphotos.cli.verbose import ( from osxphotos.cli.verbose import (
_reset_verbose_globals,
get_verbose_level, get_verbose_level,
set_verbose_level, set_verbose_level,
verbose, verbose,
verbose_print, verbose_print,
_reset_verbose_globals,
) )

View File

@ -5,9 +5,10 @@ from .locale_util import setlocale
def test_datetime_formatter_1(): def test_datetime_formatter_1():
"""Test DateTimeFormatter """ """Test DateTimeFormatter"""
import datetime import datetime
import locale import locale
from osxphotos.datetime_formatter import DateTimeFormatter from osxphotos.datetime_formatter import DateTimeFormatter
setlocale(locale.LC_ALL, "en_US") setlocale(locale.LC_ALL, "en_US")
@ -29,9 +30,10 @@ def test_datetime_formatter_1():
def test_datetime_formatter_2(): def test_datetime_formatter_2():
"""Test DateTimeFormatter with hour > 12 """ """Test DateTimeFormatter with hour > 12"""
import datetime import datetime
import locale import locale
from osxphotos.datetime_formatter import DateTimeFormatter from osxphotos.datetime_formatter import DateTimeFormatter
setlocale(locale.LC_ALL, "en_US") setlocale(locale.LC_ALL, "en_US")
@ -53,9 +55,10 @@ def test_datetime_formatter_2():
def test_datetime_formatter_3(): def test_datetime_formatter_3():
"""Test DateTimeFormatter zero-padding """ """Test DateTimeFormatter zero-padding"""
import datetime import datetime
import locale import locale
from osxphotos.datetime_formatter import DateTimeFormatter from osxphotos.datetime_formatter import DateTimeFormatter
setlocale(locale.LC_ALL, "en_US") setlocale(locale.LC_ALL, "en_US")

View File

@ -1,4 +1,5 @@
from datetime import date, timezone from datetime import date, timezone
import pytest import pytest
from osxphotos.datetime_utils import * from osxphotos.datetime_utils import *

View File

@ -30,25 +30,28 @@ def test_db_version():
def test_persons(): def test_persons():
import osxphotos
import collections import collections
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
assert photosdb.persons == [] assert photosdb.persons == []
def test_keywords(): def test_keywords():
import osxphotos
import collections import collections
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
assert photosdb.keywords == [] assert photosdb.keywords == []
def test_album_names(): def test_album_names():
import osxphotos
import collections import collections
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
assert photosdb.albums == [] assert photosdb.albums == []

View File

@ -1,4 +1,5 @@
import pytest import pytest
from osxphotos.exiftool import get_exiftool_path from osxphotos.exiftool import get_exiftool_path
TEST_FILE_ONE_KEYWORD = "tests/test-images/wedding.jpg" TEST_FILE_ONE_KEYWORD = "tests/test-images/wedding.jpg"
@ -107,7 +108,7 @@ def test_version():
def test_singleton(): def test_singleton():
""" tests per-file singleton behavior """ """tests per-file singleton behavior"""
import osxphotos.exiftool import osxphotos.exiftool
exif1 = osxphotos.exiftool.ExifToolCaching(TEST_FILE_ONE_KEYWORD) exif1 = osxphotos.exiftool.ExifToolCaching(TEST_FILE_ONE_KEYWORD)
@ -131,6 +132,7 @@ def test_setvalue_1():
# test setting a tag value # test setting a tag value
import os.path import os.path
import tempfile import tempfile
import osxphotos.exiftool import osxphotos.exiftool
from osxphotos.fileutil import FileUtil from osxphotos.fileutil import FileUtil
@ -147,6 +149,7 @@ def test_setvalue_cache():
# test setting a tag value doesn't affect cached value # test setting a tag value doesn't affect cached value
import os.path import os.path
import tempfile import tempfile
import osxphotos.exiftool import osxphotos.exiftool
from osxphotos.fileutil import FileUtil from osxphotos.fileutil import FileUtil
@ -174,6 +177,7 @@ def test_setvalue_context_manager():
# test setting a tag value as context manager # test setting a tag value as context manager
import os.path import os.path
import tempfile import tempfile
import osxphotos.exiftool import osxphotos.exiftool
from osxphotos.fileutil import FileUtil from osxphotos.fileutil import FileUtil
@ -190,6 +194,7 @@ def test_flags():
# test that flags raise error # test that flags raise error
import os.path import os.path
import tempfile import tempfile
import osxphotos.exiftool import osxphotos.exiftool
from osxphotos.fileutil import FileUtil from osxphotos.fileutil import FileUtil
@ -207,6 +212,7 @@ def test_clear_value():
# test clearing a tag value # test clearing a tag value
import os.path import os.path
import tempfile import tempfile
import osxphotos.exiftool import osxphotos.exiftool
from osxphotos.fileutil import FileUtil from osxphotos.fileutil import FileUtil
@ -224,6 +230,7 @@ def test_addvalues_1():
# test setting a tag value # test setting a tag value
import os.path import os.path
import tempfile import tempfile
import osxphotos.exiftool import osxphotos.exiftool
from osxphotos.fileutil import FileUtil from osxphotos.fileutil import FileUtil
@ -276,9 +283,10 @@ def test_as_dict_no_tag_groups():
def test_json(): def test_json():
import osxphotos.exiftool
import json import json
import osxphotos.exiftool
exif1 = osxphotos.exiftool.ExifToolCaching(TEST_FILE_ONE_KEYWORD) exif1 = osxphotos.exiftool.ExifToolCaching(TEST_FILE_ONE_KEYWORD)
exifdata = json.loads(exif1.json()) exifdata = json.loads(exif1.json())
assert exifdata[0]["XMP:TagsList"] == "wedding" assert exifdata[0]["XMP:TagsList"] == "wedding"
@ -293,7 +301,7 @@ def test_str():
def test_photoinfo_exiftool(): def test_photoinfo_exiftool():
""" test PhotoInfo.exiftool which returns ExifTool object for photo """ """test PhotoInfo.exiftool which returns ExifTool object for photo"""
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
@ -306,7 +314,7 @@ def test_photoinfo_exiftool():
def test_photoinfo_exiftool_no_groups(): def test_photoinfo_exiftool_no_groups():
""" test PhotoInfo.exiftool which returns ExifTool object for photo without tag group names""" """test PhotoInfo.exiftool which returns ExifTool object for photo without tag group names"""
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)

View File

@ -357,7 +357,6 @@ def test_export_13(photosdb):
def test_dd_to_dms_str_1(): def test_dd_to_dms_str_1():
lat_str, lon_str = dd_to_dms_str( lat_str, lon_str = dd_to_dms_str(
34.559331096, 69.206499174 34.559331096, 69.206499174
) # Kabul, 34°33'33.59" N 69°12'23.40" E ) # Kabul, 34°33'33.59" N 69°12'23.40" E
@ -367,7 +366,6 @@ def test_dd_to_dms_str_1():
def test_dd_to_dms_str_2(): def test_dd_to_dms_str_2():
lat_str, lon_str = dd_to_dms_str( lat_str, lon_str = dd_to_dms_str(
-34.601997592, -58.375665164 -34.601997592, -58.375665164
) # Buenos Aires, 34°36'7.19" S 58°22'32.39" W ) # Buenos Aires, 34°36'7.19" S 58°22'32.39" W
@ -377,7 +375,6 @@ def test_dd_to_dms_str_2():
def test_dd_to_dms_str_3(): def test_dd_to_dms_str_3():
lat_str, lon_str = dd_to_dms_str( lat_str, lon_str = dd_to_dms_str(
-1.2666656, 36.7999968 -1.2666656, 36.7999968
) # Nairobi, 1°15'60.00" S 36°47'59.99" E ) # Nairobi, 1°15'60.00" S 36°47'59.99" E
@ -387,7 +384,6 @@ def test_dd_to_dms_str_3():
def test_dd_to_dms_str_4(): def test_dd_to_dms_str_4():
lat_str, lon_str = dd_to_dms_str( lat_str, lon_str = dd_to_dms_str(
38.889248, -77.050636 38.889248, -77.050636
) # DC: 38° 53' 21.2928" N, 77° 3' 2.2896" W ) # DC: 38° 53' 21.2928" N, 77° 3' 2.2896" W
@ -397,7 +393,6 @@ def test_dd_to_dms_str_4():
def test_exiftool_json_sidecar(photosdb): def test_exiftool_json_sidecar(photosdb):
uuid = EXIF_JSON_UUID uuid = EXIF_JSON_UUID
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -411,7 +406,6 @@ def test_exiftool_json_sidecar(photosdb):
def test_exiftool_json_sidecar_ignore_date_modified(photosdb): def test_exiftool_json_sidecar_ignore_date_modified(photosdb):
uuid = EXIF_JSON_UUID uuid = EXIF_JSON_UUID
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -469,9 +463,7 @@ def test_exiftool_json_sidecar_keyword_template_long(capsys, photosdb):
assert json_got[k] == v assert json_got[k] == v
def test_exiftool_json_sidecar_keyword_template(photosdb): def test_exiftool_json_sidecar_keyword_template(photosdb):
uuid = EXIF_JSON_UUID uuid = EXIF_JSON_UUID
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -488,7 +480,6 @@ def test_exiftool_json_sidecar_keyword_template(photosdb):
def test_exiftool_json_sidecar_use_persons_keyword(photosdb): def test_exiftool_json_sidecar_use_persons_keyword(photosdb):
uuid = UUID_DICT["xmp"] uuid = UUID_DICT["xmp"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -506,7 +497,6 @@ def test_exiftool_json_sidecar_use_persons_keyword(photosdb):
def test_exiftool_json_sidecar_use_albums_keywords(photosdb): def test_exiftool_json_sidecar_use_albums_keywords(photosdb):
uuid = UUID_DICT["xmp"] uuid = UUID_DICT["xmp"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -550,7 +540,6 @@ def test_xmp_sidecar_is_valid(tmp_path, photosdb):
def test_xmp_sidecar(photosdb): def test_xmp_sidecar(photosdb):
uuid = UUID_DICT["xmp"] uuid = UUID_DICT["xmp"]
photos = photosdb.photos(uuid=[uuid]) photos = photosdb.photos(uuid=[uuid])
@ -575,7 +564,6 @@ def test_xmp_sidecar_extension(photosdb):
def test_xmp_sidecar_use_persons_keyword(photosdb): def test_xmp_sidecar_use_persons_keyword(photosdb):
uuid = UUID_DICT["xmp"] uuid = UUID_DICT["xmp"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -589,7 +577,6 @@ def test_xmp_sidecar_use_persons_keyword(photosdb):
def test_xmp_sidecar_use_albums_keyword(photosdb): def test_xmp_sidecar_use_albums_keyword(photosdb):
uuid = UUID_DICT["xmp"] uuid = UUID_DICT["xmp"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -616,7 +603,6 @@ def test_xmp_sidecar_gps(photosdb):
def test_xmp_sidecar_keyword_template(photosdb): def test_xmp_sidecar_keyword_template(photosdb):
uuid = UUID_DICT["location"] uuid = UUID_DICT["location"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)

View File

@ -1,8 +1,9 @@
import os import os
import pytest import pytest
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
from osxphotos.utils import is_macos, get_macos_version from osxphotos.utils import get_macos_version, is_macos
OS_VERSION = get_macos_version() if is_macos else (None, None, None) OS_VERSION = get_macos_version() if is_macos else (None, None, None)
SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "15" SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "15"
@ -123,6 +124,7 @@ def test_export_edited(photosdb):
def test_export_edited_exiftool(photosdb): def test_export_edited_exiftool(photosdb):
# test export edited file # test export edited file
import logging
import os import os
import os.path import os.path
import pathlib import pathlib
@ -131,8 +133,6 @@ def test_export_edited_exiftool(photosdb):
import osxphotos import osxphotos
import osxphotos.exiftool import osxphotos.exiftool
import logging
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_") tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
dest = tempdir.name dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]]) photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]])

View File

@ -2,9 +2,9 @@
import os import os
import pathlib import pathlib
import shutil
import sqlite3 import sqlite3
import tempfile import tempfile
import shutil
import pytest import pytest

View File

@ -330,7 +330,6 @@ def test_export_13(photosdb):
def test_exiftool_json_sidecar(photosdb): def test_exiftool_json_sidecar(photosdb):
uuid = UUID_DICT["location"] uuid = UUID_DICT["location"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -344,7 +343,6 @@ def test_exiftool_json_sidecar(photosdb):
def test_xmp_sidecar(photosdb): def test_xmp_sidecar(photosdb):
uuid = UUID_DICT["xmp"] uuid = UUID_DICT["xmp"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)
@ -357,7 +355,6 @@ def test_xmp_sidecar(photosdb):
def test_xmp_sidecar_keyword_template(photosdb): def test_xmp_sidecar_keyword_template(photosdb):
uuid = UUID_DICT["xmp"] uuid = UUID_DICT["xmp"]
photo = photosdb.get_photo(uuid) photo = photosdb.get_photo(uuid)

View File

@ -66,9 +66,9 @@ def test_export_edited_name():
# export edited file with name provided # export edited file with name provided
import os import os
import os.path import os.path
import pathlib
import tempfile import tempfile
import time import time
import pathlib
import osxphotos import osxphotos
@ -109,10 +109,10 @@ def test_export_edited_wrong_suffix():
# should produce a warning via logging.warning # should produce a warning via logging.warning
import os import os
import os.path import os.path
import pathlib
import sys import sys
import tempfile import tempfile
import time import time
import pathlib
import osxphotos import osxphotos

View File

@ -1,6 +1,7 @@
""" test ExportResults class """ """ test ExportResults class """
import pytest import pytest
from osxphotos.photoexporter import ExportResults from osxphotos.photoexporter import ExportResults
EXPORT_RESULT_ATTRIBUTES = ExportResults().attributes EXPORT_RESULT_ATTRIBUTES = ExportResults().attributes

View File

@ -4074,7 +4074,7 @@ def photosdb4():
@pytest.mark.parametrize("uuid_dict", UUID_LIST_5) @pytest.mark.parametrize("uuid_dict", UUID_LIST_5)
def test_faceinfo_v5(photosdb5, uuid_dict): def test_faceinfo_v5(photosdb5, uuid_dict):
""" Test FaceInfo object """ """Test FaceInfo object"""
import json import json
for uuid in uuid_dict: for uuid in uuid_dict:
@ -4088,19 +4088,19 @@ def test_faceinfo_v5(photosdb5, uuid_dict):
face_dict = face.asdict() face_dict = face.asdict()
for key in face_dict: for key in face_dict:
if key == "yaw": if key == "yaw":
continue # yaw set to 0 as it's not in Ventura continue # yaw set to 0 as it's not in Ventura
assert face_dict[key] == uuid_dict[uuid][face.uuid][key] assert face_dict[key] == uuid_dict[uuid][face.uuid][key]
def test_faceinfo_v5_no_face(photosdb5): def test_faceinfo_v5_no_face(photosdb5):
""" Test FaceInfo on image with no faces """ """Test FaceInfo on image with no faces"""
photo = photosdb5.get_photo(UUID_NO_FACE_5) photo = photosdb5.get_photo(UUID_NO_FACE_5)
assert photo.face_info == [] assert photo.face_info == []
@pytest.mark.parametrize("uuid_dict", UUID_LIST_4) @pytest.mark.parametrize("uuid_dict", UUID_LIST_4)
def test_faceinfo_v4(photosdb4, uuid_dict): def test_faceinfo_v4(photosdb4, uuid_dict):
""" Test FaceInfo object """ """Test FaceInfo object"""
import json import json
for uuid in uuid_dict: for uuid in uuid_dict:
@ -4117,6 +4117,6 @@ def test_faceinfo_v4(photosdb4, uuid_dict):
def test_faceinfo_v4_no_face(photosdb4): def test_faceinfo_v4_no_face(photosdb4):
""" Test FaceInfo on image with no faces """ """Test FaceInfo on image with no faces"""
photo = photosdb4.get_photo(UUID_NO_FACE_4) photo = photosdb4.get_photo(UUID_NO_FACE_4)
assert photo.face_info == [] assert photo.face_info == []

View File

@ -1,7 +1,6 @@
import pytest import pytest
import osxphotos import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
PHOTOS_DB = "./tests/Test-10.13.6.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.13.6.photoslibrary/database/photos.db"

View File

@ -19,7 +19,7 @@ TEST_IMAGE_DOES_NOT_EXIST = "tests/test-images/NOT-A-FILE.heic"
def test_image_converter_singleton(): def test_image_converter_singleton():
""" test that ImageConverter is a singleton """ """test that ImageConverter is a singleton"""
from osxphotos.imageconverter import ImageConverter from osxphotos.imageconverter import ImageConverter
convert1 = ImageConverter() convert1 = ImageConverter()
@ -29,9 +29,10 @@ def test_image_converter_singleton():
def test_image_converter(): def test_image_converter():
""" test conversion of different image types """ """test conversion of different image types"""
import pathlib import pathlib
import tempfile import tempfile
from osxphotos.imageconverter import ImageConverter from osxphotos.imageconverter import ImageConverter
converter = ImageConverter() converter = ImageConverter()
@ -50,9 +51,10 @@ def test_image_converter():
def test_image_converter_compression_quality(): def test_image_converter_compression_quality():
""" test conversion of different image types with custom compression quality """ """test conversion of different image types with custom compression quality"""
import pathlib import pathlib
import tempfile import tempfile
from osxphotos.imageconverter import ImageConverter from osxphotos.imageconverter import ImageConverter
converter = ImageConverter() converter = ImageConverter()
@ -69,9 +71,10 @@ def test_image_converter_compression_quality():
def test_image_converter_bad_compression_quality(): def test_image_converter_bad_compression_quality():
""" test illegal compression quality """ """test illegal compression quality"""
import pathlib import pathlib
import tempfile import tempfile
from osxphotos.imageconverter import ImageConverter from osxphotos.imageconverter import ImageConverter
converter = ImageConverter() converter = ImageConverter()
@ -86,10 +89,11 @@ def test_image_converter_bad_compression_quality():
def test_image_converter_bad_file(): def test_image_converter_bad_file():
""" Try to convert a file that's not an image """ """Try to convert a file that's not an image"""
import pathlib import pathlib
import tempfile import tempfile
from osxphotos.imageconverter import ImageConverter, ImageConversionError
from osxphotos.imageconverter import ImageConversionError, ImageConverter
converter = ImageConverter() converter = ImageConverter()
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_") tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
@ -101,9 +105,10 @@ def test_image_converter_bad_file():
def test_image_converter_missing_file(): def test_image_converter_missing_file():
""" Try to convert a file that's not an image """ """Try to convert a file that's not an image"""
import pathlib import pathlib
import tempfile import tempfile
from osxphotos.imageconverter import ImageConverter from osxphotos.imageconverter import ImageConverter
converter = ImageConverter() converter = ImageConverter()
@ -113,4 +118,3 @@ def test_image_converter_missing_file():
outfile = pathlib.Path(tempdir.name) / f"{imgfile.stem}.jpeg" outfile = pathlib.Path(tempdir.name) / f"{imgfile.stem}.jpeg"
with pytest.raises(FileNotFoundError): with pytest.raises(FileNotFoundError):
converter.write_jpeg(imgfile, outfile) converter.write_jpeg(imgfile, outfile)

View File

@ -19,6 +19,7 @@ UUID_DICT = {
def photosdb(): def photosdb():
return osxphotos.PhotosDB(dbfile=PHOTOS_DB_CLOUD) return osxphotos.PhotosDB(dbfile=PHOTOS_DB_CLOUD)
def test_incloud(photosdb): def test_incloud(photosdb):
photos = photosdb.photos(uuid=[UUID_DICT["incloud"]]) photos = photosdb.photos(uuid=[UUID_DICT["incloud"]])

View File

@ -9,10 +9,12 @@ UUID_DICT = {
"not_modified": "D05A5FE3-15FB-49A1-A15D-AB3DA6F8B068", "not_modified": "D05A5FE3-15FB-49A1-A15D-AB3DA6F8B068",
} }
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def photosdb(): def photosdb():
return osxphotos.PhotosDB(dbfile=PHOTOS_DB) return osxphotos.PhotosDB(dbfile=PHOTOS_DB)
def test_modified(photosdb): def test_modified(photosdb):
import datetime import datetime

View File

@ -11,6 +11,7 @@ UUID_DICT = {
"not_modified": "35243F7D-88C4-4408-B516-C74406E90C15", "not_modified": "35243F7D-88C4-4408-B516-C74406E90C15",
} }
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def photosdb(): def photosdb():
return osxphotos.PhotosDB(dbfile=PHOTOS_DB) return osxphotos.PhotosDB(dbfile=PHOTOS_DB)

View File

@ -15,6 +15,7 @@ UUID_DICT = {
def test_path_edited1(): def test_path_edited1():
# test a valid edited path # test a valid edited path
import os.path import os.path
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
@ -29,6 +30,7 @@ def test_path_edited1():
def test_path_edited2(): def test_path_edited2():
# test a non-standard (not 00) edited path # test a non-standard (not 00) edited path
import os.path import os.path
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)

View File

@ -232,6 +232,7 @@ def test_init4():
# test invalid db # test invalid db
import os import os
import tempfile import tempfile
import osxphotos import osxphotos
(bad_db, bad_db_name) = tempfile.mkstemp(suffix=".db", prefix="osxphotos-") (bad_db, bad_db_name) = tempfile.mkstemp(suffix=".db", prefix="osxphotos-")
@ -608,7 +609,6 @@ def test_keyword_2(photosdb):
def test_keyword_not_in_album(photosdb): def test_keyword_not_in_album(photosdb):
# find all photos with keyword "Kids" not in the album "Pumpkin Farm" # find all photos with keyword "Kids" not in the album "Pumpkin Farm"
photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos1 = photosdb.photos(albums=["Pumpkin Farm"])
photos2 = photosdb.photos(keywords=["Kids"]) photos2 = photosdb.photos(keywords=["Kids"])
@ -1026,6 +1026,7 @@ def test_date_invalid():
"""Test date is invalid""" """Test date is invalid"""
# doesn't run correctly with the module-level fixture # doesn't run correctly with the module-level fixture
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
import osxphotos import osxphotos
# UUID_DICT["date_invalid"] has an invalid date that's # UUID_DICT["date_invalid"] has an invalid date that's

View File

@ -14,7 +14,7 @@ import pytest
import osxphotos import osxphotos
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
from osxphotos.photoexporter import PhotoExporter from osxphotos.photoexporter import PhotoExporter
from osxphotos.utils import is_macos, get_macos_version from osxphotos.utils import get_macos_version, is_macos
OS_VERSION = get_macos_version() if is_macos else (None, None, None) OS_VERSION = get_macos_version() if is_macos else (None, None, None)
# SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "17" # SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "17"
@ -291,13 +291,11 @@ def test_init5(mocker):
def test_db_len(photosdb): def test_db_len(photosdb):
# assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS
assert len(photosdb) == PHOTOS_DB_LEN assert len(photosdb) == PHOTOS_DB_LEN
def test_db_version(photosdb): def test_db_version(photosdb):
# assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS
assert photosdb.db_version == "6000" assert photosdb.db_version == "6000"
@ -307,46 +305,39 @@ def test_photos_version(photosdb):
def test_persons(photosdb): def test_persons(photosdb):
assert "Katie" in photosdb.persons assert "Katie" in photosdb.persons
assert Counter(PERSONS) == Counter(photosdb.persons) assert Counter(PERSONS) == Counter(photosdb.persons)
def test_keywords(photosdb): def test_keywords(photosdb):
assert "wedding" in photosdb.keywords assert "wedding" in photosdb.keywords
assert Counter(KEYWORDS) == Counter(photosdb.keywords) assert Counter(KEYWORDS) == Counter(photosdb.keywords)
def test_album_names(photosdb): def test_album_names(photosdb):
assert "Pumpkin Farm" in photosdb.albums assert "Pumpkin Farm" in photosdb.albums
assert Counter(ALBUMS) == Counter(photosdb.albums) assert Counter(ALBUMS) == Counter(photosdb.albums)
def test_keywords_dict(photosdb): def test_keywords_dict(photosdb):
keywords = photosdb.keywords_as_dict keywords = photosdb.keywords_as_dict
assert keywords["wedding"] == 3 assert keywords["wedding"] == 3
assert keywords == KEYWORDS_DICT assert keywords == KEYWORDS_DICT
def test_persons_as_dict(photosdb): def test_persons_as_dict(photosdb):
persons = photosdb.persons_as_dict persons = photosdb.persons_as_dict
assert persons["Maria"] == 2 assert persons["Maria"] == 2
assert persons == PERSONS_DICT assert persons == PERSONS_DICT
def test_albums_as_dict(photosdb): def test_albums_as_dict(photosdb):
albums = photosdb.albums_as_dict albums = photosdb.albums_as_dict
assert albums["Pumpkin Farm"] == 3 assert albums["Pumpkin Farm"] == 3
assert albums == ALBUM_DICT assert albums == ALBUM_DICT
def test_album_sort_order(photosdb): def test_album_sort_order(photosdb):
album = [a for a in photosdb.album_info if a.title == "Pumpkin Farm"][0] album = [a for a in photosdb.album_info if a.title == "Pumpkin Farm"][0]
photos = album.photos photos = album.photos
@ -355,14 +346,12 @@ def test_album_sort_order(photosdb):
def test_album_empty_album(photosdb): def test_album_empty_album(photosdb):
album = [a for a in photosdb.album_info if a.title == "EmptyAlbum"][0] album = [a for a in photosdb.album_info if a.title == "EmptyAlbum"][0]
photos = album.photos photos = album.photos
assert photos == [] assert photos == []
def test_attributes(photosdb): def test_attributes(photosdb):
photos = photosdb.photos(uuid=["D79B8D77-BFFC-460B-9312-034F2877D35B"]) photos = photosdb.photos(uuid=["D79B8D77-BFFC-460B-9312-034F2877D35B"])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
@ -434,7 +423,6 @@ def test_attributes_2(photosdb):
def test_missing(photosdb): def test_missing(photosdb):
photos = photosdb.photos(uuid=[UUID_DICT["missing"]]) photos = photosdb.photos(uuid=[UUID_DICT["missing"]])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
@ -443,7 +431,6 @@ def test_missing(photosdb):
def test_favorite(photosdb): def test_favorite(photosdb):
photos = photosdb.photos(uuid=[UUID_DICT["favorite"]]) photos = photosdb.photos(uuid=[UUID_DICT["favorite"]])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
@ -451,7 +438,6 @@ def test_favorite(photosdb):
def test_not_favorite(photosdb): def test_not_favorite(photosdb):
photos = photosdb.photos(uuid=[UUID_DICT["not_favorite"]]) photos = photosdb.photos(uuid=[UUID_DICT["not_favorite"]])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
@ -459,7 +445,6 @@ def test_not_favorite(photosdb):
def test_hidden(photosdb): def test_hidden(photosdb):
photos = photosdb.photos(uuid=[UUID_DICT["hidden"]]) photos = photosdb.photos(uuid=[UUID_DICT["hidden"]])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
@ -467,7 +452,6 @@ def test_hidden(photosdb):
def test_not_hidden(photosdb): def test_not_hidden(photosdb):
photos = photosdb.photos(uuid=[UUID_DICT["not_hidden"]]) photos = photosdb.photos(uuid=[UUID_DICT["not_hidden"]])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
@ -606,7 +590,6 @@ def test_not_ismovie(photosdb):
def test_count(photosdb): def test_count(photosdb):
photos = photosdb.photos() photos = photosdb.photos()
assert len(photos) == PHOTOS_NOT_IN_TRASH_LEN assert len(photos) == PHOTOS_NOT_IN_TRASH_LEN
@ -685,13 +668,11 @@ def test_photoinfo_not_intrash(photosdb):
def test_keyword_2(photosdb): def test_keyword_2(photosdb):
photos = photosdb.photos(keywords=["wedding"]) photos = photosdb.photos(keywords=["wedding"])
assert len(photos) == 2 # won't show the one in the trash assert len(photos) == 2 # won't show the one in the trash
def test_keyword_not_in_album(photosdb): def test_keyword_not_in_album(photosdb):
# find all photos with keyword "Kids" not in the album "Pumpkin Farm" # find all photos with keyword "Kids" not in the album "Pumpkin Farm"
photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos1 = photosdb.photos(albums=["Pumpkin Farm"])
photos2 = photosdb.photos(keywords=["Kids"]) photos2 = photosdb.photos(keywords=["Kids"])
@ -708,20 +689,17 @@ def test_album_folder_name(photosdb):
def test_multi_person(photosdb): def test_multi_person(photosdb):
photos = photosdb.photos(persons=["Katie", "Suzy"]) photos = photosdb.photos(persons=["Katie", "Suzy"])
assert len(photos) == 3 assert len(photos) == 3
def test_get_db_path(photosdb): def test_get_db_path(photosdb):
db_path = photosdb.db_path db_path = photosdb.db_path
assert db_path.endswith(PHOTOS_DB_PATH) assert db_path.endswith(PHOTOS_DB_PATH)
def test_get_library_path(photosdb): def test_get_library_path(photosdb):
lib_path = photosdb.library_path lib_path = photosdb.library_path
assert lib_path.endswith(PHOTOS_LIBRARY_PATH) assert lib_path.endswith(PHOTOS_LIBRARY_PATH)
@ -1028,14 +1006,12 @@ def test_eq_2():
def test_not_eq(photosdb): def test_not_eq(photosdb):
photos1 = photosdb.photos(uuid=[UUID_DICT["export"]]) photos1 = photosdb.photos(uuid=[UUID_DICT["export"]])
photos2 = photosdb.photos(uuid=[UUID_DICT["missing"]]) photos2 = photosdb.photos(uuid=[UUID_DICT["missing"]])
assert photos1[0] != photos2[0] assert photos1[0] != photos2[0]
def test_photosdb_repr(): def test_photosdb_repr():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photosdb2 = eval(repr(photosdb)) photosdb2 = eval(repr(photosdb))
@ -1046,7 +1022,6 @@ def test_photosdb_repr():
def test_photosinfo_repr(photosdb): def test_photosinfo_repr(photosdb):
photos = photosdb.photos(uuid=[UUID_DICT["favorite"]]) photos = photosdb.photos(uuid=[UUID_DICT["favorite"]])
photo = photos[0] photo = photos[0]
photo2 = eval(repr(photo)) photo2 = eval(repr(photo))

View File

@ -33,15 +33,17 @@ def test_db_version():
def test_keywords(): def test_keywords():
import osxphotos
import collections import collections
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
assert "test" in photosdb.keywords assert "test" in photosdb.keywords
def test_attributes(): def test_attributes():
import datetime import datetime
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)

View File

@ -36,15 +36,17 @@ def test_db_version():
def test_keywords(): def test_keywords():
import osxphotos
import collections import collections
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
assert "test" in photosdb.keywords assert "test" in photosdb.keywords
def test_attributes(): def test_attributes():
import datetime import datetime
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)

View File

@ -5,7 +5,6 @@ from osxphotos.path_utils import sanitize_filename
def test_sanitize_filename(): def test_sanitize_filename():
# basic sanitize # basic sanitize
filenames = { filenames = {
"Foobar.txt": "Foobar.txt", "Foobar.txt": "Foobar.txt",

View File

@ -7,15 +7,16 @@ import tempfile
import pytest import pytest
from osxphotos.utils import is_macos from osxphotos.utils import is_macos
if is_macos: if is_macos:
from osxphotos.photokit import ( from osxphotos.photokit import (
PHOTOS_VERSION_CURRENT,
PHOTOS_VERSION_ORIGINAL,
PHOTOS_VERSION_UNADJUSTED,
LivePhotoAsset, LivePhotoAsset,
PhotoAsset, PhotoAsset,
PhotoLibrary, PhotoLibrary,
VideoAsset, VideoAsset,
PHOTOS_VERSION_CURRENT,
PHOTOS_VERSION_ORIGINAL,
PHOTOS_VERSION_UNADJUSTED,
) )
else: else:
pytest.skip(allow_module_level=True) pytest.skip(allow_module_level=True)

View File

@ -1,7 +1,6 @@
""" Test PlaceInfo """ """ Test PlaceInfo """
import pytest import pytest
PHOTOS_DB = "./tests/Test-Places-Catalina-10_15_1.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-Places-Catalina-10_15_1.photoslibrary/database/photos.db"
UUID_DICT = { UUID_DICT = {

View File

@ -1,6 +1,7 @@
""" Test ScoreInfo """ """ Test ScoreInfo """
from math import isclose from math import isclose
import pytest import pytest
from osxphotos.scoreinfo import ScoreInfo from osxphotos.scoreinfo import ScoreInfo
@ -78,7 +79,7 @@ def photosdb():
def test_score_info_v5(photosdb): def test_score_info_v5(photosdb):
""" test score """ """test score"""
# use math.isclose to compare floats # use math.isclose to compare floats
# on MacOS x64 these can probably compared for equality but would possibly # on MacOS x64 these can probably compared for equality but would possibly
# fail if osxphotos ever ported to other platforms # fail if osxphotos ever ported to other platforms
@ -89,7 +90,7 @@ def test_score_info_v5(photosdb):
def test_score_info_v4(): def test_score_info_v4():
""" test version 4, score should be None """ """test version 4, score should be None"""
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_4) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_4)

View File

@ -6,7 +6,6 @@ import pytest
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
LABELS_DICT = { LABELS_DICT = {

View File

@ -4,7 +4,6 @@ import pytest
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
PHOTOS_DB = "./tests/Test-10.15.4.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.15.4.photoslibrary/database/photos.db"
PHOTOS_DB_PATH = "/Test-10.15.4.photoslibrary/database/photos.db" PHOTOS_DB_PATH = "/Test-10.15.4.photoslibrary/database/photos.db"
PHOTOS_LIBRARY_PATH = "/Test-10.15.4.photoslibrary" PHOTOS_LIBRARY_PATH = "/Test-10.15.4.photoslibrary"

View File

@ -4,7 +4,6 @@ import pytest
from osxphotos._constants import _UNKNOWN_PERSON from osxphotos._constants import _UNKNOWN_PERSON
PHOTOS_DB = "./tests/Test-10.15.5.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.15.5.photoslibrary/database/photos.db"
PHOTOS_DB_PATH = "/Test-10.15.5.photoslibrary/database/photos.db" PHOTOS_DB_PATH = "/Test-10.15.5.photoslibrary/database/photos.db"
PHOTOS_LIBRARY_PATH = "/Test-10.15.5.photoslibrary" PHOTOS_LIBRARY_PATH = "/Test-10.15.5.photoslibrary"

View File

@ -1,6 +1,5 @@
import pytest import pytest
PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db" PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
PHOTOS_DB_PATH = "/Test-10.14.6.photoslibrary/database/photos.db" PHOTOS_DB_PATH = "/Test-10.14.6.photoslibrary/database/photos.db"
PHOTOS_LIBRARY_PATH = "/Test-10.14.6.photoslibrary" PHOTOS_LIBRARY_PATH = "/Test-10.14.6.photoslibrary"
@ -18,6 +17,7 @@ PHOTOS_DB_LEN = 13
PHOTOS_NOT_IN_TRASH_LEN = 12 PHOTOS_NOT_IN_TRASH_LEN = 12
PHOTOS_IN_TRASH_LEN = 1 PHOTOS_IN_TRASH_LEN = 1
def test_album_names(): def test_album_names():
import osxphotos import osxphotos

View File

@ -30,6 +30,7 @@ def test_portrait1():
photos = photosdb.photos(uuid=[UUID_DICT["no_specials"]]) photos = photosdb.photos(uuid=[UUID_DICT["no_specials"]])
assert not photos[0].portrait assert not photos[0].portrait
def test_portrait2(): def test_portrait2():
import osxphotos import osxphotos

View File

@ -1,21 +1,19 @@
"""Tests for sqlite_utils """ """Tests for sqlite_utils """
import pytest
import sqlite3 import sqlite3
from osxphotos.sqlite_utils import sqlite_open_ro, sqlite_db_is_locked import pytest
from osxphotos.sqlite_utils import sqlite_db_is_locked, sqlite_open_ro
DB_UNLOCKED_10_15 = "./tests/Test-10.15.1.photoslibrary/database/photos.db" DB_UNLOCKED_10_15 = "./tests/Test-10.15.1.photoslibrary/database/photos.db"
def test_db_is_locked_unlocked(): def test_db_is_locked_unlocked():
assert not sqlite_db_is_locked(DB_UNLOCKED_10_15) assert not sqlite_db_is_locked(DB_UNLOCKED_10_15)
def test_open_sqlite_ro(): def test_open_sqlite_ro():
conn, cur = sqlite_open_ro(DB_UNLOCKED_10_15) conn, cur = sqlite_open_ro(DB_UNLOCKED_10_15)
assert isinstance(conn, sqlite3.Connection) assert isinstance(conn, sqlite3.Connection)
assert isinstance(cur, sqlite3.Cursor) assert isinstance(cur, sqlite3.Cursor)

View File

@ -7,6 +7,7 @@ import pytest
import osxphotos import osxphotos
from osxphotos.exiftool import get_exiftool_path from osxphotos.exiftool import get_exiftool_path
from osxphotos.export_db import ExportDBInMemory from osxphotos.export_db import ExportDBInMemory
from osxphotos.photoinfo import PhotoInfoNone
from osxphotos.phototemplate import ( from osxphotos.phototemplate import (
PUNCTUATION, PUNCTUATION,
TEMPLATE_SUBSTITUTIONS, TEMPLATE_SUBSTITUTIONS,
@ -14,10 +15,10 @@ from osxphotos.phototemplate import (
PhotoTemplate, PhotoTemplate,
RenderOptions, RenderOptions,
) )
from osxphotos.photoinfo import PhotoInfoNone
from osxphotos.utils import is_macos from osxphotos.utils import is_macos
from .photoinfo_mock import PhotoInfoMock
from .locale_util import setlocale from .locale_util import setlocale
from .photoinfo_mock import PhotoInfoMock
try: try:
exiftool = get_exiftool_path() exiftool = get_exiftool_path()

View File

@ -608,7 +608,6 @@ def test_keyword_2(photosdb):
def test_keyword_not_in_album(photosdb): def test_keyword_not_in_album(photosdb):
# find all photos with keyword "Kids" not in the album "Pumpkin Farm" # find all photos with keyword "Kids" not in the album "Pumpkin Farm"
photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos1 = photosdb.photos(albums=["Pumpkin Farm"])
photos2 = photosdb.photos(keywords=["Kids"]) photos2 = photosdb.photos(keywords=["Kids"])

View File

@ -6,7 +6,6 @@ import sys
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
if __name__ == "__main__": if __name__ == "__main__":
url = "https://www.exiftool.org/" url = "https://www.exiftool.org/"
json_file = "exiftool_filetypes.json" json_file = "exiftool_filetypes.json"