fixed formatting (#1096)
This commit is contained in:
parent
492e1edb7f
commit
2c80226ec8
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
@ -2,9 +2,10 @@
|
||||
|
||||
import sys
|
||||
|
||||
import osxphotos
|
||||
import click
|
||||
|
||||
import osxphotos
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("album1")
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import osxphotos
|
||||
import os.path
|
||||
|
||||
import osxphotos
|
||||
|
||||
|
||||
def main():
|
||||
db = osxphotos.utils.get_system_library_path()
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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}")
|
||||
|
||||
@ -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)
|
||||
"""
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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()
|
||||
main()
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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():
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
"""query command for osxphotos CLI"""
|
||||
|
||||
import sys
|
||||
|
||||
import click
|
||||
|
||||
import osxphotos
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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}"
|
||||
)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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,
|
||||
)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -18,7 +18,6 @@ if is_macos:
|
||||
|
||||
from osxphotos.exiftool import _ExifToolProc
|
||||
|
||||
|
||||
# run timewarp tests (configured with --timewarp)
|
||||
TEST_TIMEWARP = False
|
||||
|
||||
|
||||
@ -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_)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -6,6 +6,7 @@ import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from osxphotos.utils import is_macos
|
||||
|
||||
if is_macos:
|
||||
import photoscript
|
||||
else:
|
||||
|
||||
@ -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():
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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():
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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)
|
||||
assert dt == datetime.datetime(2020, 9, 1, 21, 0, 0, tzinfo=tz)
|
||||
|
||||
@ -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 == []
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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"]])
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
""" test ExportResults class """
|
||||
|
||||
import pytest
|
||||
|
||||
from osxphotos.photoexporter import ExportResults
|
||||
|
||||
EXPORT_RESULT_ATTRIBUTES = ExportResults().attributes
|
||||
|
||||
@ -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 == []
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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"]])
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -5,7 +5,6 @@ from osxphotos.path_utils import sanitize_filename
|
||||
|
||||
|
||||
def test_sanitize_filename():
|
||||
|
||||
# basic sanitize
|
||||
filenames = {
|
||||
"Foobar.txt": "Foobar.txt",
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
""" Test PlaceInfo """
|
||||
import pytest
|
||||
|
||||
|
||||
PHOTOS_DB = "./tests/Test-Places-Catalina-10_15_1.photoslibrary/database/photos.db"
|
||||
|
||||
UUID_DICT = {
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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"])
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user