diff --git a/examples/batch_edit.py b/examples/batch_edit.py index 046715d6..3ceac85d 100644 --- a/examples/batch_edit.py +++ b/examples/batch_edit.py @@ -21,7 +21,6 @@ from osxphotos.sqlitekvstore import SQLiteKVStore class Latitude(click.ParamType): - name = "Latitude" def convert(self, value, param, ctx): @@ -37,7 +36,6 @@ class Latitude(click.ParamType): class Longitude(click.ParamType): - name = "Longitude" def convert(self, value, param, ctx): diff --git a/examples/cli_example_3.py b/examples/cli_example_3.py index 50236758..b8fdb4ae 100644 --- a/examples/cli_example_3.py +++ b/examples/cli_example_3.py @@ -23,10 +23,7 @@ to your function. You can then do whatever you want with the photos. from __future__ import annotations import osxphotos -from osxphotos.cli import ( - selection_command, - verbose, -) +from osxphotos.cli import selection_command, verbose @selection_command diff --git a/examples/compare_albums.py b/examples/compare_albums.py index 53c8f394..20eecfac 100644 --- a/examples/compare_albums.py +++ b/examples/compare_albums.py @@ -2,9 +2,10 @@ import sys -import osxphotos import click +import osxphotos + @click.command() @click.argument("album1") diff --git a/examples/examples.py b/examples/examples.py index 83fa1723..b6dc1be2 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -1,6 +1,7 @@ -import osxphotos import os.path +import osxphotos + def main(): db = osxphotos.utils.get_system_library_path() diff --git a/examples/export_by_album.py b/examples/export_by_album.py index cb5db5d9..0021ac71 100644 --- a/examples/export_by_album.py +++ b/examples/export_by_album.py @@ -32,7 +32,7 @@ import osxphotos default=False, ) 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) library_path = os.path.expanduser(library_path) if library_path else None @@ -66,11 +66,11 @@ def export(export_path, default_album, library_path, edited): os.makedirs(dest_dir) filename = p.original_filename - # export the photo but only if --edited, photo has adjustments, and + # export the photo but only if --edited, photo has adjustments, and # path_edited is not None (can be None if edited photo is missing) if edited and p.hasadjustments and p.path_edited: # export edited version - # use original filename with _edited appended but make sure suffix is + # use original filename with _edited appended but make sure suffix is # same as edited file edited_filename = f"{pathlib.Path(filename).stem}_edited{pathlib.Path(p.path_edited).suffix}" exported = p.export(dest_dir, edited_filename, edited=True) diff --git a/examples/export_faces.py b/examples/export_faces.py index ec991c14..688ad2b5 100644 --- a/examples/export_faces.py +++ b/examples/export_faces.py @@ -32,7 +32,7 @@ import osxphotos default=None, ) 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 if library_path is not None: photosdb = osxphotos.PhotosDB(library_path) @@ -61,7 +61,7 @@ def export(export_path, library_path, uuid): 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: xy: tuple of x, y coordinates diff --git a/examples/export_template.py b/examples/export_template.py index 14d41c58..3232b0cb 100644 --- a/examples/export_template.py +++ b/examples/export_template.py @@ -77,7 +77,9 @@ def place_folder(photo: osxphotos.PhotoInfo) -> str: 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 Args: diff --git a/examples/force_download.py b/examples/force_download.py index 73883d43..db5fb97a 100644 --- a/examples/force_download.py +++ b/examples/force_download.py @@ -29,7 +29,9 @@ def main(): exported = photo.export(tempdir.name, use_photos_export=True, timeout=300) if photo.hasadjustments: 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: print(f"Removing temporary file {filename}") diff --git a/examples/get_shared_photo_comments.py b/examples/get_shared_photo_comments.py index 6b65e868..58ba7569 100644 --- a/examples/get_shared_photo_comments.py +++ b/examples/get_shared_photo_comments.py @@ -10,7 +10,7 @@ from osxphotos._constants import TIME_DELTA @dataclass class Comment: - """ Class for shared photo comments """ + """Class for shared photo comments""" uuid: str sort_fok: int @@ -22,7 +22,7 @@ class Comment: @dataclass class Like: - """ Class for shared photo likes """ + """Class for shared photo likes""" uuid: str sort_fok: int @@ -32,10 +32,10 @@ class Like: def get_shared_person_info(photosdb, hashed_person_id): - """ returns tuple of (first name, last name, full name) - for person invited to shared album with + """returns tuple of (first name, last name, full name) + for person invited to shared album with ZINVITEEHASHEDPERSONID = hashed_person_id - + Args: photosdb: a osxphotos.PhotosDB object hashed_person_id: str, value of ZINVITEEHASHEDPERSONID to lookup @@ -66,12 +66,12 @@ def get_shared_person_info(photosdb, hashed_person_id): 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: photosdb: a osxphotos.PhotosDB object uuid: uuid of the photo - + Returns: tuple of (list of comments as Comment objects or [] if no comments, list of likes as Like objects or [] if no likes) """ diff --git a/examples/photos_repl.py b/examples/photos_repl.py index 093df530..8f3bfef4 100755 --- a/examples/photos_repl.py +++ b/examples/photos_repl.py @@ -15,14 +15,14 @@ import time import click import osxphotos -from osxphotos.cli import get_photos_db, _list_libraries +from osxphotos.cli import _list_libraries, get_photos_db def show(photo): - """ open image with default image viewer - - Note: This is for debugging only -- it will actually open any filetype which could - be very, very bad. + """open image with default image viewer + + Note: This is for debugging only -- it will actually open any filetype which could + be very, very bad. Args: photo: PhotoInfo object or a path to a photo on disk diff --git a/examples/post_function_import.py b/examples/post_function_import.py index b734b720..6ed81163 100644 --- a/examples/post_function_import.py +++ b/examples/post_function_import.py @@ -1,8 +1,10 @@ """ Example function for use with osxphotos import --post-function option """ -import typing as t -import photoscript import pathlib +import typing as t + +import photoscript + from osxphotos.cli.import_cli import ReportRecord diff --git a/examples/simple_example.py b/examples/simple_example.py index 7f07137a..236454b8 100644 --- a/examples/simple_example.py +++ b/examples/simple_example.py @@ -3,6 +3,7 @@ import os.path import osxphotos + def main(): db = os.path.expanduser("~/Pictures/Photos Library.photoslibrary") photosdb = osxphotos.PhotosDB(db) @@ -15,11 +16,14 @@ def main(): print(photosdb.albums_as_dict) # 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 - photos = [p for p in photosdb.photos(persons=["Alice Smith"]) - if p not in photosdb.photos(keywords=["Bar"]) ] + photos = [ + p + for p in photosdb.photos(persons=["Alice Smith"]) + if p not in photosdb.photos(keywords=["Bar"]) + ] for p in photos: print( p.uuid, @@ -34,5 +38,6 @@ def main(): p.path, ) + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/examples/template_filter.py b/examples/template_filter.py index 454d345d..1c9bd552 100644 --- a/examples/template_filter.py +++ b/examples/template_filter.py @@ -10,8 +10,8 @@ from typing import List + 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] return values - diff --git a/osxphotos/cli/__init__.py b/osxphotos/cli/__init__.py index e591bd40..d4779607 100644 --- a/osxphotos/cli/__init__.py +++ b/osxphotos/cli/__init__.py @@ -5,7 +5,6 @@ import sys from rich import print from rich.traceback import install as install_traceback -from osxphotos.utils import is_macos from osxphotos.debug import ( debug_breakpoint, debug_watch, @@ -14,6 +13,7 @@ from osxphotos.debug import ( set_debug, wrap_function, ) +from osxphotos.utils import is_macos # apply any debug functions # need to do this before importing anything else so that the debug functions diff --git a/osxphotos/cli/cli_params.py b/osxphotos/cli/cli_params.py index 487887ee..dbebbbb3 100644 --- a/osxphotos/cli/cli_params.py +++ b/osxphotos/cli/cli_params.py @@ -3,11 +3,12 @@ from __future__ import annotations -import functools -from typing import Any, Callable -import click import contextlib +import functools from textwrap import dedent +from typing import Any, Callable + +import click from ..utils import is_macos from .common import OSXPHOTOS_HIDDEN, print_version diff --git a/osxphotos/cli/darkmode.py b/osxphotos/cli/darkmode.py index 7372a4de..49934be0 100644 --- a/osxphotos/cli/darkmode.py +++ b/osxphotos/cli/darkmode.py @@ -2,10 +2,9 @@ from osxphotos.utils import is_macos - if is_macos: - import objc import Foundation + import objc def theme(): with objc.autorelease_pool(): diff --git a/osxphotos/cli/exportdb.py b/osxphotos/cli/exportdb.py index d47632c3..f656a2d0 100644 --- a/osxphotos/cli/exportdb.py +++ b/osxphotos/cli/exportdb.py @@ -19,14 +19,14 @@ from osxphotos.export_db_utils import ( export_db_backup, export_db_check_signatures, export_db_get_errors, + export_db_get_last_library, export_db_get_last_run, export_db_get_version, + export_db_migrate_photos_library, export_db_save_config_to_file, export_db_touch_files, export_db_update_signatures, export_db_vacuum, - export_db_migrate_photos_library, - export_db_get_last_library, ) from osxphotos.utils import pluralize diff --git a/osxphotos/cli/query.py b/osxphotos/cli/query.py index fe28ce7b..5a6a631b 100644 --- a/osxphotos/cli/query.py +++ b/osxphotos/cli/query.py @@ -1,6 +1,7 @@ """query command for osxphotos CLI""" import sys + import click import osxphotos diff --git a/osxphotos/cli/show_command.py b/osxphotos/cli/show_command.py index d8969b08..7c39723e 100644 --- a/osxphotos/cli/show_command.py +++ b/osxphotos/cli/show_command.py @@ -8,7 +8,7 @@ import click from osxphotos._constants import UUID_PATTERN from osxphotos.export_db_utils import get_uuid_for_filepath 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() diff --git a/osxphotos/cli/timewarp.py b/osxphotos/cli/timewarp.py index b8fd6b13..e7a6d4d1 100644 --- a/osxphotos/cli/timewarp.py +++ b/osxphotos/cli/timewarp.py @@ -30,6 +30,7 @@ from osxphotos.utils import assert_macos, noop, pluralize assert_macos() from photoscript import PhotosLibrary + from osxphotos.photosalbum import PhotosAlbumPhotoScript from .cli_params import THEME_OPTION, TIMESTAMP_OPTION, VERBOSE_OPTION diff --git a/osxphotos/cli/version.py b/osxphotos/cli/version.py index 40e64e4b..c8751678 100644 --- a/osxphotos/cli/version.py +++ b/osxphotos/cli/version.py @@ -1,11 +1,14 @@ """about command for osxphotos CLI""" -import click import os + +import click +import packaging + from osxphotos._constants import OSXPHOTOS_URL from osxphotos._version import __version__ + from .common import get_latest_version -import packaging @click.command(name="version") diff --git a/osxphotos/compare_exif.py b/osxphotos/compare_exif.py index f44e0e18..05581d40 100644 --- a/osxphotos/compare_exif.py +++ b/osxphotos/compare_exif.py @@ -12,6 +12,7 @@ from .utils import assert_macos, noop assert_macos() from photoscript import Photo + from .exif_datetime_updater import get_exif_date_time_offset from .phototz import PhotoTimeZone diff --git a/osxphotos/imageconverter.py b/osxphotos/imageconverter.py index 2580659d..265b9cd6 100644 --- a/osxphotos/imageconverter.py +++ b/osxphotos/imageconverter.py @@ -13,8 +13,8 @@ from wurlitzer import pipes from .utils import is_macos if is_macos: - import objc import Metal + import objc import Quartz from Cocoa import NSURL from Foundation import NSDictionary diff --git a/osxphotos/photosalbum.py b/osxphotos/photosalbum.py index 1a0cbba4..ef76ad09 100644 --- a/osxphotos/photosalbum.py +++ b/osxphotos/photosalbum.py @@ -101,7 +101,9 @@ class PhotosAlbum: try: photos.append(photoscript.Photo(p.uuid)) 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( f"Error creating Photo object for photo {self._format_uuid(p.uuid)}: {e}" ) diff --git a/osxphotos/photosdb/__init__.py b/osxphotos/photosdb/__init__.py index 3147548d..ee6ca14c 100644 --- a/osxphotos/photosdb/__init__.py +++ b/osxphotos/photosdb/__init__.py @@ -4,4 +4,4 @@ Processes a Photos.app library database to extract information about photos """ 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 diff --git a/osxphotos/photosdb/_photosdb_process_comments.py b/osxphotos/photosdb/_photosdb_process_comments.py index 73f92e8d..931699c8 100644 --- a/osxphotos/photosdb/_photosdb_process_comments.py +++ b/osxphotos/photosdb/_photosdb_process_comments.py @@ -6,8 +6,8 @@ import datetime from dataclasses import dataclass from .._constants import _DB_TABLE_NAMES, _PHOTOS_4_VERSION, TIME_DELTA -from ..utils import normalize_unicode from ..sqlite_utils import sqlite_open_ro +from ..utils import normalize_unicode def _process_comments(self): diff --git a/osxphotos/photosdb/_photosdb_process_exif.py b/osxphotos/photosdb/_photosdb_process_exif.py index ef4f40f3..46726dfc 100644 --- a/osxphotos/photosdb/_photosdb_process_exif.py +++ b/osxphotos/photosdb/_photosdb_process_exif.py @@ -4,7 +4,7 @@ import logging 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 diff --git a/osxphotos/photosdb/_photosdb_process_syndicationinfo.py b/osxphotos/photosdb/_photosdb_process_syndicationinfo.py index 0e48d3da..327ef0b2 100644 --- a/osxphotos/photosdb/_photosdb_process_syndicationinfo.py +++ b/osxphotos/photosdb/_photosdb_process_syndicationinfo.py @@ -2,11 +2,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from .._constants import _DB_TABLE_NAMES from ..sqlite_utils import sqlite_open_ro -from typing import TYPE_CHECKING - if TYPE_CHECKING: from osxphotos.photosdb import PhotosDB diff --git a/osxphotos/photosdb/photosdb.py b/osxphotos/photosdb/photosdb.py index 736faee5..f9457b86 100644 --- a/osxphotos/photosdb/photosdb.py +++ b/osxphotos/photosdb/photosdb.py @@ -61,9 +61,9 @@ from ..rich_utils import add_rich_markup_tag from ..sqlite_utils import sqlite_db_is_locked, sqlite_open_ro from ..utils import ( _check_file_exists, - is_macos, - get_macos_version, get_last_library_path, + get_macos_version, + is_macos, noop, normalize_unicode, ) diff --git a/osxphotos/scoreinfo.py b/osxphotos/scoreinfo.py index f6b0ef11..01caf151 100644 --- a/osxphotos/scoreinfo.py +++ b/osxphotos/scoreinfo.py @@ -1,6 +1,6 @@ """ 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 diff --git a/osxphotos/timeutils.py b/osxphotos/timeutils.py index e3472aa5..ffd0095a 100644 --- a/osxphotos/timeutils.py +++ b/osxphotos/timeutils.py @@ -1,9 +1,8 @@ """Utilities for working with datetimes""" import datetime -from typing import Optional - import re +from typing import Optional def utc_offset_string_to_seconds(utc_offset: str) -> int: diff --git a/osxphotos/uti.py b/osxphotos/uti.py index 3ab194e0..5abbc115 100644 --- a/osxphotos/uti.py +++ b/osxphotos/uti.py @@ -24,7 +24,7 @@ import subprocess import sys 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: import CoreServices diff --git a/tests/conftest.py b/tests/conftest.py index 6c645be1..271388aa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,7 +18,6 @@ if is_macos: from osxphotos.exiftool import _ExifToolProc - # run timewarp tests (configured with --timewarp) TEST_TIMEWARP = False diff --git a/tests/generate_sidecars_for_test.py b/tests/generate_sidecars_for_test.py index 37c4ff88..32295533 100644 --- a/tests/generate_sidecars_for_test.py +++ b/tests/generate_sidecars_for_test.py @@ -7,7 +7,7 @@ import pathlib 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_14_6 = "./tests/Test-10.14.6.photoslibrary/database/photos.db" @@ -92,9 +92,7 @@ def generate_sidecars(dbname, uuid_dict): # ignore_date_modified sidecar = str(pathlib.Path(SIDECAR_DIR) / f"{uuid}_ignore_date_modified.json") - json_ = exporter.exiftool_json_sidecar( - ExportOptions(ignore_date_modified=True) - ) + json_ = exporter.exiftool_json_sidecar(ExportOptions(ignore_date_modified=True)) with open(sidecar, "w") as file: file.write(json_) diff --git a/tests/hyphen-dir/template_function.py b/tests/hyphen-dir/template_function.py index 849d61f5..f20ffe47 100644 --- a/tests/hyphen-dir/template_function.py +++ b/tests/hyphen-dir/template_function.py @@ -7,7 +7,7 @@ import osxphotos def foo(photo: osxphotos.PhotoInfo, **kwargs) -> Union[List, str]: - """ example function for {function} template + """example function for {function} template Args: photo: osxphotos.PhotoInfo object diff --git a/tests/tempdiskimage.py b/tests/tempdiskimage.py index 6147f3db..a6737e29 100644 --- a/tests/tempdiskimage.py +++ b/tests/tempdiskimage.py @@ -8,11 +8,11 @@ import time class TempDiskImage: - """ Create and mount a temporary disk image """ + """Create and mount a temporary disk image""" def __init__(self, size=100, prefix=None): - """ Create and mount a temporary disk image. - + """Create and mount a temporary disk image. + Args: size: int; size in MB of disk image, default = 100 prefix: str; optional prefix to prepend to name of the temporary disk image @@ -59,7 +59,7 @@ class TempDiskImage: self._mount_point, self.name = self._mount_image(self.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( ["/usr/bin/hdiutil", "attach", image_path], check=True, diff --git a/tests/template_filter.py b/tests/template_filter.py index 454d345d..1c9bd552 100644 --- a/tests/template_filter.py +++ b/tests/template_filter.py @@ -10,8 +10,8 @@ from typing import List + 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] return values - diff --git a/tests/template_function.py b/tests/template_function.py index 849d61f5..f20ffe47 100644 --- a/tests/template_function.py +++ b/tests/template_function.py @@ -7,7 +7,7 @@ import osxphotos def foo(photo: osxphotos.PhotoInfo, **kwargs) -> Union[List, str]: - """ example function for {function} template + """example function for {function} template Args: photo: osxphotos.PhotoInfo object diff --git a/tests/test_10_12_6.py b/tests/test_10_12_6.py index d22ff909..e3e311ab 100644 --- a/tests/test_10_12_6.py +++ b/tests/test_10_12_6.py @@ -62,7 +62,6 @@ def test_photos_version(photosdb): def test_persons(photosdb): - assert "Katie" in photosdb.persons assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons) diff --git a/tests/test_albums_folders_catalina_10_15_7.py b/tests/test_albums_folders_catalina_10_15_7.py index 5f3e3cba..dd349cd2 100644 --- a/tests/test_albums_folders_catalina_10_15_7.py +++ b/tests/test_albums_folders_catalina_10_15_7.py @@ -1,7 +1,6 @@ import pytest import osxphotos - from osxphotos._constants import _UNKNOWN_PERSON, AlbumSortOrder PHOTOS_DB = "./tests/Test-10.15.7.photoslibrary/database/photos.db" diff --git a/tests/test_albums_folders_high_sierra_10_13_6.py b/tests/test_albums_folders_high_sierra_10_13_6.py index e8c0eba2..fb9084a4 100644 --- a/tests/test_albums_folders_high_sierra_10_13_6.py +++ b/tests/test_albums_folders_high_sierra_10_13_6.py @@ -1,7 +1,6 @@ import pytest import osxphotos - from osxphotos._constants import _UNKNOWN_PERSON PHOTOS_DB = "./tests/Test-10.13.6.photoslibrary/database/photos.db" diff --git a/tests/test_albums_folders_mojave_10_14_6.py b/tests/test_albums_folders_mojave_10_14_6.py index ede20265..c357f53b 100644 --- a/tests/test_albums_folders_mojave_10_14_6.py +++ b/tests/test_albums_folders_mojave_10_14_6.py @@ -1,7 +1,6 @@ import pytest import osxphotos - from osxphotos._constants import _UNKNOWN_PERSON PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db" diff --git a/tests/test_bigsur_10_16_0_1.py b/tests/test_bigsur_10_16_0_1.py index c0c913cb..81f6fe42 100644 --- a/tests/test_bigsur_10_16_0_1.py +++ b/tests/test_bigsur_10_16_0_1.py @@ -226,6 +226,7 @@ def test_init4(): # test invalid db import os import tempfile + import 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): - # find all photos with keyword "Kids" not in the album "Pumpkin Farm" photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos2 = photosdb.photos(keywords=["Kids"]) @@ -1024,6 +1024,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 # UUID_DICT["date_invalid"] has an invalid date that's diff --git a/tests/test_catalina_10_15_7.py b/tests/test_catalina_10_15_7.py index 48ab92ca..ad73e67d 100644 --- a/tests/test_catalina_10_15_7.py +++ b/tests/test_catalina_10_15_7.py @@ -15,7 +15,7 @@ import pytest import osxphotos from osxphotos._constants import _UNKNOWN_PERSON 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) SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "15" diff --git a/tests/test_cli.py b/tests/test_cli.py index 80485d46..6866673d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,9 +14,9 @@ import subprocess import tempfile import time from tempfile import TemporaryDirectory -from bitmath import contextlib import pytest +from bitmath import contextlib from click.testing import CliRunner import osxphotos diff --git a/tests/test_cli_add_locations.py b/tests/test_cli_add_locations.py index 875375f4..c9508f51 100644 --- a/tests/test_cli_add_locations.py +++ b/tests/test_cli_add_locations.py @@ -4,8 +4,10 @@ import pytest from click.testing import CliRunner from osxphotos.utils import is_macos + if is_macos: import photoscript + from osxphotos.cli.add_locations import add_locations else: pytest.skip(allow_module_level=True) diff --git a/tests/test_cli_add_to_album.py b/tests/test_cli_add_to_album.py index 197b1f40..38b05f4a 100644 --- a/tests/test_cli_add_to_album.py +++ b/tests/test_cli_add_to_album.py @@ -6,6 +6,7 @@ import pytest from click.testing import CliRunner from osxphotos.utils import is_macos + if is_macos: import photoscript else: diff --git a/tests/test_cli_all_commands.py b/tests/test_cli_all_commands.py index 06ff724e..04bf5538 100644 --- a/tests/test_cli_all_commands.py +++ b/tests/test_cli_all_commands.py @@ -24,6 +24,7 @@ TEST_RUN_SCRIPT = "examples/cli_example_1.py" def runner() -> CliRunner: return CliRunner() + from osxphotos.cli import ( about, albums, @@ -43,7 +44,6 @@ from osxphotos.cli import ( tutorial, version, ) - from osxphotos.utils import is_macos if is_macos: @@ -72,7 +72,8 @@ def test_about(runner: CliRunner): places, tutorial, version, - ] + ([uuid] if is_macos else []), + ] + + ([uuid] if is_macos else []), ) def test_cli_comands(runner: CliRunner, command: Callable[..., Any]): with runner.isolated_filesystem(): diff --git a/tests/test_cli_batch_edit.py b/tests/test_cli_batch_edit.py index 4be0b6c2..a9be7a5c 100644 --- a/tests/test_cli_batch_edit.py +++ b/tests/test_cli_batch_edit.py @@ -13,6 +13,7 @@ from osxphotos.utils import is_macos if is_macos: import photoscript + from osxphotos.cli.batch_edit import batch_edit else: pytest.skip(allow_module_level=True) diff --git a/tests/test_cli_dump.py b/tests/test_cli_dump.py index fc280266..50661d5e 100644 --- a/tests/test_cli_dump.py +++ b/tests/test_cli_dump.py @@ -91,11 +91,12 @@ def test_dump_field(photos): "name", "{photo.original_filename}", ], - ) + ) assert result.exit_code == 0 for photo in photos: assert f"{photo.uuid},{photo.original_filename}" in result.output + def test_dump_field_json(photos): """Test osxphotos dump --field --jso""" runner = CliRunner() @@ -117,7 +118,7 @@ def test_dump_field_json(photos): "{photo.original_filename}", "--json", ], - ) + ) assert result.exit_code == 0 json_data = {record["uuid"]: record for record in json.loads(result.output)} for photo in photos: diff --git a/tests/test_cli_import.py b/tests/test_cli_import.py index 48e9320e..1182e48f 100644 --- a/tests/test_cli_import.py +++ b/tests/test_cli_import.py @@ -14,7 +14,6 @@ from tempfile import TemporaryDirectory from typing import Dict import pytest - from click.testing import CliRunner from pytest import MonkeyPatch, approx @@ -27,6 +26,7 @@ from tests.conftest import get_os_version if is_macos: from photoscript import Photo + from osxphotos.cli.import_cli import import_cli else: pytest.skip(allow_module_level=True) diff --git a/tests/test_cli_param_types.py b/tests/test_cli_param_types.py index 4a74d7a1..dbcfac98 100644 --- a/tests/test_cli_param_types.py +++ b/tests/test_cli_param_types.py @@ -1,12 +1,9 @@ """ Test custom click paramater types used by osxphotos CLI""" import datetime -from bitmath import MB import pytest - -from osxphotos.timezones import Timezone - +from bitmath import MB from click.exceptions import BadParameter from osxphotos.cli.param_types import ( @@ -21,6 +18,7 @@ from osxphotos.cli.param_types import ( TimeString, UTCOffset, ) +from osxphotos.timezones import Timezone def test_date_offset(): diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py index a7399b8d..9515ccf5 100644 --- a/tests/test_cli_sync.py +++ b/tests/test_cli_sync.py @@ -1,13 +1,16 @@ """Test osxphotos sync command""" -import os import json +import os + import pytest from click.testing import CliRunner from osxphotos.utils import is_macos + if is_macos: import photoscript + from osxphotos.cli.sync import sync else: pytest.skip(allow_module_level=True) diff --git a/tests/test_cli_verbose.py b/tests/test_cli_verbose.py index 1b95c54a..ef975a48 100644 --- a/tests/test_cli_verbose.py +++ b/tests/test_cli_verbose.py @@ -3,13 +3,12 @@ import re from io import StringIO - from osxphotos.cli.verbose import ( + _reset_verbose_globals, get_verbose_level, set_verbose_level, verbose, verbose_print, - _reset_verbose_globals, ) diff --git a/tests/test_datetime_formatter.py b/tests/test_datetime_formatter.py index 3500172c..f476e598 100644 --- a/tests/test_datetime_formatter.py +++ b/tests/test_datetime_formatter.py @@ -5,9 +5,10 @@ from .locale_util import setlocale def test_datetime_formatter_1(): - """Test DateTimeFormatter """ + """Test DateTimeFormatter""" import datetime import locale + from osxphotos.datetime_formatter import DateTimeFormatter setlocale(locale.LC_ALL, "en_US") @@ -29,9 +30,10 @@ def test_datetime_formatter_1(): def test_datetime_formatter_2(): - """Test DateTimeFormatter with hour > 12 """ + """Test DateTimeFormatter with hour > 12""" import datetime import locale + from osxphotos.datetime_formatter import DateTimeFormatter setlocale(locale.LC_ALL, "en_US") @@ -53,9 +55,10 @@ def test_datetime_formatter_2(): def test_datetime_formatter_3(): - """Test DateTimeFormatter zero-padding """ + """Test DateTimeFormatter zero-padding""" import datetime import locale + from osxphotos.datetime_formatter import DateTimeFormatter setlocale(locale.LC_ALL, "en_US") diff --git a/tests/test_datetime_utils.py b/tests/test_datetime_utils.py index d31182f7..5fc40fb7 100644 --- a/tests/test_datetime_utils.py +++ b/tests/test_datetime_utils.py @@ -1,4 +1,5 @@ from datetime import date, timezone + import pytest from osxphotos.datetime_utils import * @@ -93,4 +94,4 @@ def test_datetime_utc_to_local_2(): tz = datetime.timezone(offset=datetime.timedelta(seconds=7200)) utc = datetime.datetime(2020, 9, 1, 19, 0, 0, tzinfo=datetime.timezone.utc) dt = datetime_utc_to_local(utc) - assert dt == datetime.datetime(2020, 9, 1, 21, 0, 0, tzinfo=tz) \ No newline at end of file + assert dt == datetime.datetime(2020, 9, 1, 21, 0, 0, tzinfo=tz) diff --git a/tests/test_empty_library_4_0.py b/tests/test_empty_library_4_0.py index 7121e11d..b980a0e6 100644 --- a/tests/test_empty_library_4_0.py +++ b/tests/test_empty_library_4_0.py @@ -30,25 +30,28 @@ def test_db_version(): def test_persons(): - import osxphotos import collections + import osxphotos + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) assert photosdb.persons == [] def test_keywords(): - import osxphotos import collections + import osxphotos + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) assert photosdb.keywords == [] def test_album_names(): - import osxphotos import collections + import osxphotos + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) assert photosdb.albums == [] diff --git a/tests/test_exiftool_caching.py b/tests/test_exiftool_caching.py index 26c5d7ed..ccafd3b7 100644 --- a/tests/test_exiftool_caching.py +++ b/tests/test_exiftool_caching.py @@ -1,4 +1,5 @@ import pytest + from osxphotos.exiftool import get_exiftool_path TEST_FILE_ONE_KEYWORD = "tests/test-images/wedding.jpg" @@ -107,7 +108,7 @@ def test_version(): def test_singleton(): - """ tests per-file singleton behavior """ + """tests per-file singleton behavior""" import osxphotos.exiftool exif1 = osxphotos.exiftool.ExifToolCaching(TEST_FILE_ONE_KEYWORD) @@ -131,6 +132,7 @@ def test_setvalue_1(): # test setting a tag value import os.path import tempfile + import osxphotos.exiftool from osxphotos.fileutil import FileUtil @@ -147,6 +149,7 @@ def test_setvalue_cache(): # test setting a tag value doesn't affect cached value import os.path import tempfile + import osxphotos.exiftool from osxphotos.fileutil import FileUtil @@ -174,6 +177,7 @@ def test_setvalue_context_manager(): # test setting a tag value as context manager import os.path import tempfile + import osxphotos.exiftool from osxphotos.fileutil import FileUtil @@ -190,6 +194,7 @@ def test_flags(): # test that flags raise error import os.path import tempfile + import osxphotos.exiftool from osxphotos.fileutil import FileUtil @@ -207,6 +212,7 @@ def test_clear_value(): # test clearing a tag value import os.path import tempfile + import osxphotos.exiftool from osxphotos.fileutil import FileUtil @@ -224,6 +230,7 @@ def test_addvalues_1(): # test setting a tag value import os.path import tempfile + import osxphotos.exiftool from osxphotos.fileutil import FileUtil @@ -276,9 +283,10 @@ def test_as_dict_no_tag_groups(): def test_json(): - import osxphotos.exiftool import json + import osxphotos.exiftool + exif1 = osxphotos.exiftool.ExifToolCaching(TEST_FILE_ONE_KEYWORD) exifdata = json.loads(exif1.json()) assert exifdata[0]["XMP:TagsList"] == "wedding" @@ -293,7 +301,7 @@ def test_str(): def test_photoinfo_exiftool(): - """ test PhotoInfo.exiftool which returns ExifTool object for photo """ + """test PhotoInfo.exiftool which returns ExifTool object for photo""" import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) @@ -306,7 +314,7 @@ def test_photoinfo_exiftool(): 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 photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) diff --git a/tests/test_export_catalina_10_15_7.py b/tests/test_export_catalina_10_15_7.py index b522bf7b..31261e02 100644 --- a/tests/test_export_catalina_10_15_7.py +++ b/tests/test_export_catalina_10_15_7.py @@ -357,7 +357,6 @@ def test_export_13(photosdb): def test_dd_to_dms_str_1(): - lat_str, lon_str = dd_to_dms_str( 34.559331096, 69.206499174 ) # 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(): - lat_str, lon_str = dd_to_dms_str( -34.601997592, -58.375665164 ) # 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(): - lat_str, lon_str = dd_to_dms_str( -1.2666656, 36.7999968 ) # 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(): - lat_str, lon_str = dd_to_dms_str( 38.889248, -77.050636 ) # 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): - uuid = EXIF_JSON_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): - uuid = EXIF_JSON_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 - def test_exiftool_json_sidecar_keyword_template(photosdb): - uuid = EXIF_JSON_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): - uuid = UUID_DICT["xmp"] 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): - uuid = UUID_DICT["xmp"] photo = photosdb.get_photo(uuid) @@ -550,7 +540,6 @@ def test_xmp_sidecar_is_valid(tmp_path, photosdb): def test_xmp_sidecar(photosdb): - uuid = UUID_DICT["xmp"] photos = photosdb.photos(uuid=[uuid]) @@ -575,7 +564,6 @@ def test_xmp_sidecar_extension(photosdb): def test_xmp_sidecar_use_persons_keyword(photosdb): - uuid = UUID_DICT["xmp"] 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): - uuid = UUID_DICT["xmp"] photo = photosdb.get_photo(uuid) @@ -616,7 +603,6 @@ def test_xmp_sidecar_gps(photosdb): def test_xmp_sidecar_keyword_template(photosdb): - uuid = UUID_DICT["location"] photo = photosdb.get_photo(uuid) diff --git a/tests/test_export_catalina_10_15_7_use_photos_export.py b/tests/test_export_catalina_10_15_7_use_photos_export.py index d03be1b1..15c5567b 100644 --- a/tests/test_export_catalina_10_15_7_use_photos_export.py +++ b/tests/test_export_catalina_10_15_7_use_photos_export.py @@ -1,8 +1,9 @@ import os + import pytest 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) 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): # test export edited file + import logging import os import os.path import pathlib @@ -131,8 +133,6 @@ def test_export_edited_exiftool(photosdb): import osxphotos import osxphotos.exiftool - import logging - tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_") dest = tempdir.name photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]]) diff --git a/tests/test_export_db.py b/tests/test_export_db.py index 5afed657..f29b1d96 100644 --- a/tests/test_export_db.py +++ b/tests/test_export_db.py @@ -2,9 +2,9 @@ import os import pathlib +import shutil import sqlite3 import tempfile -import shutil import pytest diff --git a/tests/test_export_mojave_10_14_6.py b/tests/test_export_mojave_10_14_6.py index 1ca259db..8ba52c26 100644 --- a/tests/test_export_mojave_10_14_6.py +++ b/tests/test_export_mojave_10_14_6.py @@ -330,7 +330,6 @@ def test_export_13(photosdb): def test_exiftool_json_sidecar(photosdb): - uuid = UUID_DICT["location"] photo = photosdb.get_photo(uuid) @@ -344,7 +343,6 @@ def test_exiftool_json_sidecar(photosdb): def test_xmp_sidecar(photosdb): - uuid = UUID_DICT["xmp"] photo = photosdb.get_photo(uuid) @@ -357,7 +355,6 @@ def test_xmp_sidecar(photosdb): def test_xmp_sidecar_keyword_template(photosdb): - uuid = UUID_DICT["xmp"] photo = photosdb.get_photo(uuid) diff --git a/tests/test_export_raw_catalina_10_15_1.py b/tests/test_export_raw_catalina_10_15_1.py index a24165ea..2066d9e1 100644 --- a/tests/test_export_raw_catalina_10_15_1.py +++ b/tests/test_export_raw_catalina_10_15_1.py @@ -66,9 +66,9 @@ def test_export_edited_name(): # export edited file with name provided import os import os.path + import pathlib import tempfile import time - import pathlib import osxphotos @@ -109,10 +109,10 @@ def test_export_edited_wrong_suffix(): # should produce a warning via logging.warning import os import os.path + import pathlib import sys import tempfile import time - import pathlib import osxphotos diff --git a/tests/test_exportresults.py b/tests/test_exportresults.py index b9eee465..6f1a61bf 100644 --- a/tests/test_exportresults.py +++ b/tests/test_exportresults.py @@ -1,6 +1,7 @@ """ test ExportResults class """ import pytest + from osxphotos.photoexporter import ExportResults EXPORT_RESULT_ATTRIBUTES = ExportResults().attributes diff --git a/tests/test_faceinfo.py b/tests/test_faceinfo.py index 3f72a47b..c5628946 100644 --- a/tests/test_faceinfo.py +++ b/tests/test_faceinfo.py @@ -4074,7 +4074,7 @@ def photosdb4(): @pytest.mark.parametrize("uuid_dict", UUID_LIST_5) def test_faceinfo_v5(photosdb5, uuid_dict): - """ Test FaceInfo object """ + """Test FaceInfo object""" import json for uuid in uuid_dict: @@ -4084,23 +4084,23 @@ def test_faceinfo_v5(photosdb5, uuid_dict): for face in faces: assert face.uuid in uuid_dict[uuid] # test by keys instead of dict == dict because Monterey+ dropped support for some of the face details - # and I didn't want to regenerate all the test data (e.g.eye, mouth coordinates) + # and I didn't want to regenerate all the test data (e.g.eye, mouth coordinates) face_dict = face.asdict() for key in face_dict: 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] 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) assert photo.face_info == [] @pytest.mark.parametrize("uuid_dict", UUID_LIST_4) def test_faceinfo_v4(photosdb4, uuid_dict): - """ Test FaceInfo object """ + """Test FaceInfo object""" import json for uuid in uuid_dict: @@ -4110,13 +4110,13 @@ def test_faceinfo_v4(photosdb4, uuid_dict): for face in faces: assert face.uuid in uuid_dict[uuid] # test by keys instead of dict == dict because Monterey+ dropped support for some of the face details - # and I didn't want to regenerate all the test data (e.g.eye, mouth coordinates) + # and I didn't want to regenerate all the test data (e.g.eye, mouth coordinates) face_dict = face.asdict() for key in face_dict: assert face_dict[key] == uuid_dict[uuid][face.uuid][key] 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) assert photo.face_info == [] diff --git a/tests/test_highsierra.py b/tests/test_highsierra.py index fc607db3..aed632bc 100644 --- a/tests/test_highsierra.py +++ b/tests/test_highsierra.py @@ -1,7 +1,6 @@ import pytest import osxphotos - from osxphotos._constants import _UNKNOWN_PERSON PHOTOS_DB = "./tests/Test-10.13.6.photoslibrary/database/photos.db" diff --git a/tests/test_image_converter.py b/tests/test_image_converter.py index 350ec554..3d3cb73c 100644 --- a/tests/test_image_converter.py +++ b/tests/test_image_converter.py @@ -19,7 +19,7 @@ TEST_IMAGE_DOES_NOT_EXIST = "tests/test-images/NOT-A-FILE.heic" def test_image_converter_singleton(): - """ test that ImageConverter is a singleton """ + """test that ImageConverter is a singleton""" from osxphotos.imageconverter import ImageConverter convert1 = ImageConverter() @@ -29,9 +29,10 @@ def test_image_converter_singleton(): def test_image_converter(): - """ test conversion of different image types """ + """test conversion of different image types""" import pathlib import tempfile + from osxphotos.imageconverter import ImageConverter converter = ImageConverter() @@ -50,9 +51,10 @@ def test_image_converter(): 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 tempfile + from osxphotos.imageconverter import ImageConverter converter = ImageConverter() @@ -69,9 +71,10 @@ def test_image_converter_compression_quality(): def test_image_converter_bad_compression_quality(): - """ test illegal compression quality """ + """test illegal compression quality""" import pathlib import tempfile + from osxphotos.imageconverter import ImageConverter converter = ImageConverter() @@ -86,10 +89,11 @@ def test_image_converter_bad_compression_quality(): 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 tempfile - from osxphotos.imageconverter import ImageConverter, ImageConversionError + + from osxphotos.imageconverter import ImageConversionError, ImageConverter converter = ImageConverter() tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_") @@ -101,9 +105,10 @@ def test_image_converter_bad_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 tempfile + from osxphotos.imageconverter import ImageConverter converter = ImageConverter() @@ -113,4 +118,3 @@ def test_image_converter_missing_file(): outfile = pathlib.Path(tempdir.name) / f"{imgfile.stem}.jpeg" with pytest.raises(FileNotFoundError): converter.write_jpeg(imgfile, outfile) - diff --git a/tests/test_incloud_mojave_10_14_6.py b/tests/test_incloud_mojave_10_14_6.py index 13f9da28..05871362 100644 --- a/tests/test_incloud_mojave_10_14_6.py +++ b/tests/test_incloud_mojave_10_14_6.py @@ -19,6 +19,7 @@ UUID_DICT = { def photosdb(): return osxphotos.PhotosDB(dbfile=PHOTOS_DB_CLOUD) + def test_incloud(photosdb): photos = photosdb.photos(uuid=[UUID_DICT["incloud"]]) diff --git a/tests/test_modified_date_catalina_10_15_7.py b/tests/test_modified_date_catalina_10_15_7.py index 9c585faf..5a849dfb 100644 --- a/tests/test_modified_date_catalina_10_15_7.py +++ b/tests/test_modified_date_catalina_10_15_7.py @@ -9,10 +9,12 @@ UUID_DICT = { "not_modified": "D05A5FE3-15FB-49A1-A15D-AB3DA6F8B068", } + @pytest.fixture(scope="module") def photosdb(): return osxphotos.PhotosDB(dbfile=PHOTOS_DB) + def test_modified(photosdb): import datetime diff --git a/tests/test_modified_date_mojave_10_14_6.py b/tests/test_modified_date_mojave_10_14_6.py index 162ada0c..6096efa8 100644 --- a/tests/test_modified_date_mojave_10_14_6.py +++ b/tests/test_modified_date_mojave_10_14_6.py @@ -11,6 +11,7 @@ UUID_DICT = { "not_modified": "35243F7D-88C4-4408-B516-C74406E90C15", } + @pytest.fixture(scope="module") def photosdb(): return osxphotos.PhotosDB(dbfile=PHOTOS_DB) diff --git a/tests/test_mojave_10_14_6_path_edited.py b/tests/test_mojave_10_14_6_path_edited.py index 4acbb687..0545bcc6 100644 --- a/tests/test_mojave_10_14_6_path_edited.py +++ b/tests/test_mojave_10_14_6_path_edited.py @@ -15,6 +15,7 @@ UUID_DICT = { def test_path_edited1(): # test a valid edited path import os.path + import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) @@ -29,6 +30,7 @@ def test_path_edited1(): def test_path_edited2(): # test a non-standard (not 00) edited path import os.path + import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) diff --git a/tests/test_monterey_12_0_1.py b/tests/test_monterey_12_0_1.py index 10c89b86..d6bb2f72 100644 --- a/tests/test_monterey_12_0_1.py +++ b/tests/test_monterey_12_0_1.py @@ -232,6 +232,7 @@ def test_init4(): # test invalid db import os import tempfile + import 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): - # find all photos with keyword "Kids" not in the album "Pumpkin Farm" photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos2 = photosdb.photos(keywords=["Kids"]) @@ -1026,6 +1026,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 # UUID_DICT["date_invalid"] has an invalid date that's diff --git a/tests/test_monterey_dev_beta_12_0_0.py b/tests/test_monterey_dev_beta_12_0_0.py index 7f02ec70..ac0ac82a 100644 --- a/tests/test_monterey_dev_beta_12_0_0.py +++ b/tests/test_monterey_dev_beta_12_0_0.py @@ -14,7 +14,7 @@ import pytest import osxphotos from osxphotos._constants import _UNKNOWN_PERSON 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) # 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): - # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS assert len(photosdb) == PHOTOS_DB_LEN def test_db_version(photosdb): - # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS assert photosdb.db_version == "6000" @@ -307,46 +305,39 @@ def test_photos_version(photosdb): def test_persons(photosdb): - assert "Katie" in photosdb.persons assert Counter(PERSONS) == Counter(photosdb.persons) def test_keywords(photosdb): - assert "wedding" in photosdb.keywords assert Counter(KEYWORDS) == Counter(photosdb.keywords) def test_album_names(photosdb): - assert "Pumpkin Farm" in photosdb.albums assert Counter(ALBUMS) == Counter(photosdb.albums) def test_keywords_dict(photosdb): - keywords = photosdb.keywords_as_dict assert keywords["wedding"] == 3 assert keywords == KEYWORDS_DICT def test_persons_as_dict(photosdb): - persons = photosdb.persons_as_dict assert persons["Maria"] == 2 assert persons == PERSONS_DICT def test_albums_as_dict(photosdb): - albums = photosdb.albums_as_dict assert albums["Pumpkin Farm"] == 3 assert albums == ALBUM_DICT def test_album_sort_order(photosdb): - album = [a for a in photosdb.album_info if a.title == "Pumpkin Farm"][0] photos = album.photos @@ -355,14 +346,12 @@ def test_album_sort_order(photosdb): def test_album_empty_album(photosdb): - album = [a for a in photosdb.album_info if a.title == "EmptyAlbum"][0] photos = album.photos assert photos == [] def test_attributes(photosdb): - photos = photosdb.photos(uuid=["D79B8D77-BFFC-460B-9312-034F2877D35B"]) assert len(photos) == 1 p = photos[0] @@ -434,7 +423,6 @@ def test_attributes_2(photosdb): def test_missing(photosdb): - photos = photosdb.photos(uuid=[UUID_DICT["missing"]]) assert len(photos) == 1 p = photos[0] @@ -443,7 +431,6 @@ def test_missing(photosdb): def test_favorite(photosdb): - photos = photosdb.photos(uuid=[UUID_DICT["favorite"]]) assert len(photos) == 1 p = photos[0] @@ -451,7 +438,6 @@ def test_favorite(photosdb): def test_not_favorite(photosdb): - photos = photosdb.photos(uuid=[UUID_DICT["not_favorite"]]) assert len(photos) == 1 p = photos[0] @@ -459,7 +445,6 @@ def test_not_favorite(photosdb): def test_hidden(photosdb): - photos = photosdb.photos(uuid=[UUID_DICT["hidden"]]) assert len(photos) == 1 p = photos[0] @@ -467,7 +452,6 @@ def test_hidden(photosdb): def test_not_hidden(photosdb): - photos = photosdb.photos(uuid=[UUID_DICT["not_hidden"]]) assert len(photos) == 1 p = photos[0] @@ -606,7 +590,6 @@ def test_not_ismovie(photosdb): def test_count(photosdb): - photos = photosdb.photos() assert len(photos) == PHOTOS_NOT_IN_TRASH_LEN @@ -685,13 +668,11 @@ def test_photoinfo_not_intrash(photosdb): def test_keyword_2(photosdb): - photos = photosdb.photos(keywords=["wedding"]) assert len(photos) == 2 # won't show the one in the trash def test_keyword_not_in_album(photosdb): - # find all photos with keyword "Kids" not in the album "Pumpkin Farm" photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos2 = photosdb.photos(keywords=["Kids"]) @@ -708,20 +689,17 @@ def test_album_folder_name(photosdb): def test_multi_person(photosdb): - photos = photosdb.photos(persons=["Katie", "Suzy"]) assert len(photos) == 3 def test_get_db_path(photosdb): - db_path = photosdb.db_path assert db_path.endswith(PHOTOS_DB_PATH) def test_get_library_path(photosdb): - lib_path = photosdb.library_path assert lib_path.endswith(PHOTOS_LIBRARY_PATH) @@ -1028,14 +1006,12 @@ def test_eq_2(): def test_not_eq(photosdb): - photos1 = photosdb.photos(uuid=[UUID_DICT["export"]]) photos2 = photosdb.photos(uuid=[UUID_DICT["missing"]]) assert photos1[0] != photos2[0] def test_photosdb_repr(): - photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb2 = eval(repr(photosdb)) @@ -1046,7 +1022,6 @@ def test_photosdb_repr(): def test_photosinfo_repr(photosdb): - photos = photosdb.photos(uuid=[UUID_DICT["favorite"]]) photo = photos[0] photo2 = eval(repr(photo)) diff --git a/tests/test_movies_4_0.py b/tests/test_movies_4_0.py index e95ca680..32e2569b 100644 --- a/tests/test_movies_4_0.py +++ b/tests/test_movies_4_0.py @@ -33,15 +33,17 @@ def test_db_version(): def test_keywords(): - import osxphotos import collections + import osxphotos + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) assert "test" in photosdb.keywords def test_attributes(): import datetime + import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) diff --git a/tests/test_movies_5_0.py b/tests/test_movies_5_0.py index e07e2a7a..c25d1b52 100644 --- a/tests/test_movies_5_0.py +++ b/tests/test_movies_5_0.py @@ -36,15 +36,17 @@ def test_db_version(): def test_keywords(): - import osxphotos import collections + import osxphotos + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) assert "test" in photosdb.keywords def test_attributes(): import datetime + import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) diff --git a/tests/test_path_utils.py b/tests/test_path_utils.py index a31ed4a3..09013453 100644 --- a/tests/test_path_utils.py +++ b/tests/test_path_utils.py @@ -5,7 +5,6 @@ from osxphotos.path_utils import sanitize_filename def test_sanitize_filename(): - # basic sanitize filenames = { "Foobar.txt": "Foobar.txt", diff --git a/tests/test_photokit.py b/tests/test_photokit.py index 8e31d4fc..e9545685 100644 --- a/tests/test_photokit.py +++ b/tests/test_photokit.py @@ -7,15 +7,16 @@ import tempfile import pytest from osxphotos.utils import is_macos + if is_macos: from osxphotos.photokit import ( + PHOTOS_VERSION_CURRENT, + PHOTOS_VERSION_ORIGINAL, + PHOTOS_VERSION_UNADJUSTED, LivePhotoAsset, PhotoAsset, PhotoLibrary, VideoAsset, - PHOTOS_VERSION_CURRENT, - PHOTOS_VERSION_ORIGINAL, - PHOTOS_VERSION_UNADJUSTED, ) else: pytest.skip(allow_module_level=True) diff --git a/tests/test_places_catalina_10_15_1.py b/tests/test_places_catalina_10_15_1.py index 3e6d9d79..5bba0b19 100644 --- a/tests/test_places_catalina_10_15_1.py +++ b/tests/test_places_catalina_10_15_1.py @@ -1,7 +1,6 @@ """ Test PlaceInfo """ import pytest - PHOTOS_DB = "./tests/Test-Places-Catalina-10_15_1.photoslibrary/database/photos.db" UUID_DICT = { diff --git a/tests/test_score_info.py b/tests/test_score_info.py index fd7660dd..941faa04 100644 --- a/tests/test_score_info.py +++ b/tests/test_score_info.py @@ -1,6 +1,7 @@ """ Test ScoreInfo """ from math import isclose + import pytest from osxphotos.scoreinfo import ScoreInfo @@ -78,7 +79,7 @@ def photosdb(): def test_score_info_v5(photosdb): - """ test score """ + """test score""" # use math.isclose to compare floats # on MacOS x64 these can probably compared for equality but would possibly # fail if osxphotos ever ported to other platforms @@ -89,7 +90,7 @@ def test_score_info_v5(photosdb): def test_score_info_v4(): - """ test version 4, score should be None """ + """test version 4, score should be None""" import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_4) diff --git a/tests/test_search_info_10_14_6.py b/tests/test_search_info_10_14_6.py index 167a108e..632701b0 100644 --- a/tests/test_search_info_10_14_6.py +++ b/tests/test_search_info_10_14_6.py @@ -6,7 +6,6 @@ import pytest from osxphotos._constants import _UNKNOWN_PERSON - PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db" LABELS_DICT = { diff --git a/tests/test_search_info_10_15_4.py b/tests/test_search_info_10_15_4.py index 95633846..8ae93736 100644 --- a/tests/test_search_info_10_15_4.py +++ b/tests/test_search_info_10_15_4.py @@ -4,7 +4,6 @@ import pytest from osxphotos._constants import _UNKNOWN_PERSON - PHOTOS_DB = "./tests/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" diff --git a/tests/test_search_info_10_15_5.py b/tests/test_search_info_10_15_5.py index 91dcd957..06eb5af4 100644 --- a/tests/test_search_info_10_15_5.py +++ b/tests/test_search_info_10_15_5.py @@ -4,7 +4,6 @@ import pytest from osxphotos._constants import _UNKNOWN_PERSON - PHOTOS_DB = "./tests/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" diff --git a/tests/test_shared_mojave_10_14_6.py b/tests/test_shared_mojave_10_14_6.py index 3dbd0803..f7a75b79 100644 --- a/tests/test_shared_mojave_10_14_6.py +++ b/tests/test_shared_mojave_10_14_6.py @@ -1,6 +1,5 @@ import pytest - PHOTOS_DB = "./tests/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" @@ -18,6 +17,7 @@ PHOTOS_DB_LEN = 13 PHOTOS_NOT_IN_TRASH_LEN = 12 PHOTOS_IN_TRASH_LEN = 1 + def test_album_names(): import osxphotos diff --git a/tests/test_specials_bigsur_10_16_0.py b/tests/test_specials_bigsur_10_16_0.py index 9796dc69..7c864a8b 100644 --- a/tests/test_specials_bigsur_10_16_0.py +++ b/tests/test_specials_bigsur_10_16_0.py @@ -30,6 +30,7 @@ def test_portrait1(): photos = photosdb.photos(uuid=[UUID_DICT["no_specials"]]) assert not photos[0].portrait + def test_portrait2(): import osxphotos diff --git a/tests/test_sqlite_utils.py b/tests/test_sqlite_utils.py index a7507e48..82d778b9 100644 --- a/tests/test_sqlite_utils.py +++ b/tests/test_sqlite_utils.py @@ -1,21 +1,19 @@ """Tests for sqlite_utils """ -import pytest 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" def test_db_is_locked_unlocked(): - assert not sqlite_db_is_locked(DB_UNLOCKED_10_15) def test_open_sqlite_ro(): - conn, cur = sqlite_open_ro(DB_UNLOCKED_10_15) assert isinstance(conn, sqlite3.Connection) assert isinstance(cur, sqlite3.Cursor) diff --git a/tests/test_template.py b/tests/test_template.py index aef3823c..f73dc5fa 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -7,6 +7,7 @@ import pytest import osxphotos from osxphotos.exiftool import get_exiftool_path from osxphotos.export_db import ExportDBInMemory +from osxphotos.photoinfo import PhotoInfoNone from osxphotos.phototemplate import ( PUNCTUATION, TEMPLATE_SUBSTITUTIONS, @@ -14,10 +15,10 @@ from osxphotos.phototemplate import ( PhotoTemplate, RenderOptions, ) -from osxphotos.photoinfo import PhotoInfoNone from osxphotos.utils import is_macos -from .photoinfo_mock import PhotoInfoMock + from .locale_util import setlocale +from .photoinfo_mock import PhotoInfoMock try: exiftool = get_exiftool_path() diff --git a/tests/test_ventura_dev_preview_13_0_0.py b/tests/test_ventura_dev_preview_13_0_0.py index 295ba139..813cfaee 100644 --- a/tests/test_ventura_dev_preview_13_0_0.py +++ b/tests/test_ventura_dev_preview_13_0_0.py @@ -608,7 +608,6 @@ def test_keyword_2(photosdb): def test_keyword_not_in_album(photosdb): - # find all photos with keyword "Kids" not in the album "Pumpkin Farm" photos1 = photosdb.photos(albums=["Pumpkin Farm"]) photos2 = photosdb.photos(keywords=["Kids"]) diff --git a/utils/exiftool_supported_types.py b/utils/exiftool_supported_types.py index fa4b1995..a937b2f4 100644 --- a/utils/exiftool_supported_types.py +++ b/utils/exiftool_supported_types.py @@ -6,7 +6,6 @@ import sys import requests from bs4 import BeautifulSoup - if __name__ == "__main__": url = "https://www.exiftool.org/" json_file = "exiftool_filetypes.json"