diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 0f2121a4..639f6176 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.29.10" +__version__ = "0.29.11" diff --git a/osxphotos/photoinfo/_photoinfo_export.py b/osxphotos/photoinfo/_photoinfo_export.py index ce44ff65..e2dd69e8 100644 --- a/osxphotos/photoinfo/_photoinfo_export.py +++ b/osxphotos/photoinfo/_photoinfo_export.py @@ -156,6 +156,46 @@ def _export_photo_uuid_applescript( return None +# _check_export_suffix is not a class method, don't import this into PhotoInfo +def _check_export_suffix(src, dest, edited): + """Helper function for exporting photos to check file extensions of destination path. + + Checks that dst file extension is appropriate for the src. + If edited=True, will use src file extension of ".jpeg" if None provided for src. + + Args: + src: path to source file or None. + dest: path to destination file. + edited: set to True if exporting an edited photo. + + Returns: + True if src and dest extensions are OK, else False. + + Raises: + ValueError if edited is False and src is None + """ + + # check extension of destination + if src is not None: + # use suffix from edited file + actual_suffix = pathlib.Path(src).suffix + elif edited: + # use .jpeg as that's probably correct + actual_suffix = ".jpeg" + else: + raise ValueError("src must not be None if edited=False") + + # Photo's often converts .JPG to .jpeg or .tif to .tiff on import + dest_ext = dest.suffix.lower() + actual_ext = actual_suffix.lower() + suffixes = sorted([dest_ext, actual_ext]) + return ( + dest_ext == actual_ext + or suffixes == [".jpeg", ".jpg"] + or suffixes == [".tif", ".tiff"] + ) + + def export( self, dest, @@ -182,8 +222,11 @@ def export( **NOTE**: if provided, user must ensure file extension (suffix) is correct. For example, if photo is .CR2 file, edited image may be .jpeg. If you provide an extension different than what the actual file is, - export will print a warning but will happily export the photo using the - incorrect file extension. e.g. to get the extension of the edited photo, + export will print a warning but will export the photo using the + incorrect file extension (unless use_photos_export is true, in which case export will + use the extension provided by Photos upon export; in this case, an incorrect extension is + silently ignored). + e.g. to get the extension of the edited photo, reference PhotoInfo.path_edited edited: (boolean, default=False); if True will export the edited version of the photo (or raise exception if no edited version) @@ -260,13 +303,16 @@ def export2( dry_run=False, ): """ export photo, like export but with update and dry_run options - dest: must be valid destination path (or exception raised) + dest: must be valid destination path or exception raised filename: (optional): name of exported picture; if not provided, will use current filename **NOTE**: if provided, user must ensure file extension (suffix) is correct. For example, if photo is .CR2 file, edited image may be .jpeg. If you provide an extension different than what the actual file is, - export will print a warning but will happily export the photo using the - incorrect file extension. e.g. to get the extension of the edited photo, + export will print a warning but will export the photo using the + incorrect file extension (unless use_photos_export is true, in which case export will + use the extension provided by Photos upon export; in this case, an incorrect extension is + silently ignored). + e.g. to get the extension of the edited photo, reference PhotoInfo.path_edited edited: (boolean, default=False); if True will export the edited version of the photo (or raise exception if no edited version) @@ -370,27 +416,6 @@ def export2( fname = pathlib.Path(fname) dest = dest / fname - # check extension of destination - if edited and self.path_edited is not None: - # use suffix from edited file - actual_suffix = pathlib.Path(self.path_edited).suffix - elif edited: - # use .jpeg as that's probably correct - # if edited and path_edited is None, will raise FileNotFoundError below - # unless use_photos_export is True - actual_suffix = ".jpeg" - else: - # use suffix from the non-edited file - actual_suffix = pathlib.Path(self.filename).suffix - - # warn if suffixes don't match but ignore .JPG / .jpeg as - # Photo's often converts .JPG to .jpeg - suffixes = sorted([x.lower() for x in [dest.suffix, actual_suffix]]) - if dest.suffix.lower() != actual_suffix.lower() and suffixes != [".jpeg", ".jpg"]: - logging.warning( - f"Invalid destination suffix: {dest.suffix}, should be {actual_suffix}" - ) - # check to see if file exists and if so, add (1), (2), etc until we find one that works # Photos checks the stem and adds (1), (2), etc which avoids collision with sidecars # e.g. exporting sidecar for file1.png and file1.jpeg @@ -438,6 +463,13 @@ def export2( if not os.path.isfile(src): raise FileNotFoundError(f"{src} does not appear to exist") + if not _check_export_suffix(src, dest, edited): + logging.warning( + f"Invalid destination suffix: {dest.suffix} for {self.path}, " + + f"edited={edited}, path_edited={self.path_edited}, " + + f"original_filename={self.original_filename}, filename={self.filename}" + ) + logging.debug( f"exporting {src} to {dest}, overwrite={overwrite}, increment={increment}, dest exists: {dest.exists()}" ) @@ -757,6 +789,8 @@ def _export_photo( action depending on update, overwrite Assumes destination is the right destination (e.g. UUID matches) sets UUID and JSON info foo exported file using set_uuid_for_file, set_inf_for_uuido + + Args: src: src path (string) dest: dest path (pathlib.Path) update: bool @@ -766,7 +800,9 @@ def _export_photo( export_as_hardlink: bool exiftool: bool fileutil: FileUtil class that conforms to fileutil.FileUtilABC - Returns: ExportResults + + Returns: + ExportResults """ exported_files = [] diff --git a/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-shm b/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-shm index b8232383..7c919e57 100644 Binary files a/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-shm and b/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-shm differ diff --git a/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-wal b/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-wal index e9cc904e..0a0274a5 100644 Binary files a/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-wal and b/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite-wal differ diff --git a/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite.lock b/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite.lock index fc27a08d..2f5f3463 100644 --- a/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite.lock +++ b/tests/Test-10.15.5.photoslibrary/database/Photos.sqlite.lock @@ -7,7 +7,7 @@ hostuuid 9575E48B-8D5F-5654-ABAC-4431B1167324 pid - 4021 + 452 processname photolibraryd uid diff --git a/tests/Test-10.15.5.photoslibrary/database/search/psi.sqlite b/tests/Test-10.15.5.photoslibrary/database/search/psi.sqlite index 256c5336..091b63fb 100644 Binary files a/tests/Test-10.15.5.photoslibrary/database/search/psi.sqlite and b/tests/Test-10.15.5.photoslibrary/database/search/psi.sqlite differ diff --git a/tests/Test-10.15.5.photoslibrary/database/search/synonymsProcess.plist b/tests/Test-10.15.5.photoslibrary/database/search/synonymsProcess.plist index 5a655aa8..79cdd085 100644 Binary files a/tests/Test-10.15.5.photoslibrary/database/search/synonymsProcess.plist and b/tests/Test-10.15.5.photoslibrary/database/search/synonymsProcess.plist differ diff --git a/tests/Test-10.15.5.photoslibrary/database/search/zeroKeywords.data b/tests/Test-10.15.5.photoslibrary/database/search/zeroKeywords.data index ca7a6f09..8f6208e3 100644 Binary files a/tests/Test-10.15.5.photoslibrary/database/search/zeroKeywords.data and b/tests/Test-10.15.5.photoslibrary/database/search/zeroKeywords.data differ diff --git a/tests/Test-10.15.5.photoslibrary/originals/8/8846E3E6-8AC8-4857-8448-E3D025784410.tiff b/tests/Test-10.15.5.photoslibrary/originals/8/8846E3E6-8AC8-4857-8448-E3D025784410.tiff new file mode 100644 index 00000000..69654411 Binary files /dev/null and b/tests/Test-10.15.5.photoslibrary/originals/8/8846E3E6-8AC8-4857-8448-E3D025784410.tiff differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-shm b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-shm index 705fc294..64549f0d 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-shm and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-shm differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-wal b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-wal index 85634ddd..f4a44bf4 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-wal and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.AOI.sqlite-wal differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-shm b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-shm index fd3df647..c1559a14 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-shm and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-shm differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-wal b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-wal index 4155460c..13bbed76 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-wal and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.Nature.sqlite-wal differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm index 62a76fe9..c9b73dea 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal index 5dabc7f9..ac1e064c 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-shm b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-shm index 2d607254..0640a9ed 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-shm and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-shm differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-wal b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-wal index 48b49a83..d41efc35 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-wal and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.ROI.sqlite-wal differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-shm b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-shm index fa02d9fc..5679d295 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-shm and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-shm differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-wal b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-wal index 4c2fa9fe..8ccf8398 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-wal and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSLocationCache.sqlite-wal differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-shm b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-shm index a480ef04..b7edb6d0 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-shm and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-shm differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-wal b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-wal index 312c4c79..d0a926df 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-wal and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGCurationCache.sqlite.sqlite-wal differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGSearchComputationCache.plist b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGSearchComputationCache.plist index 8be6cc7e..0ffe7e55 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGSearchComputationCache.plist and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PGSearchComputationCache.plist differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist index 6316fd20..db72f0ec 100644 --- a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist +++ b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist @@ -3,24 +3,24 @@ BackgroundHighlightCollection - 2020-05-30T01:45:51Z + 2020-06-06T14:26:31Z BackgroundHighlightEnrichment - 2020-05-30T01:45:51Z + 2020-06-06T14:26:29Z BackgroundJobAssetRevGeocode - 2020-05-30T04:01:24Z + 2020-06-06T14:26:31Z BackgroundJobSearch - 2020-05-30T01:45:51Z + 2020-06-06T14:26:31Z BackgroundPeopleSuggestion - 2020-05-30T01:45:51Z + 2020-06-06T14:26:29Z BackgroundUserBehaviorProcessor - 2020-05-29T04:31:38Z + 2020-06-06T14:26:31Z PhotoAnalysisGraphLastBackgroundGraphConsistencyUpdateJobDateKey 2020-05-30T02:16:06Z PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate 2020-05-29T04:31:37Z PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate - 2020-05-30T04:01:24Z + 2020-06-06T14:26:33Z SiriPortraitDonation - 2020-05-29T04:31:38Z + 2020-06-06T14:26:31Z diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb index 5f5c214f..709b91e6 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb differ diff --git a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist index beb22554..22a2691a 100644 Binary files a/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist and b/tests/Test-10.15.5.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/derivatives/8/8846E3E6-8AC8-4857-8448-E3D025784410_1_105_c.jpeg b/tests/Test-10.15.5.photoslibrary/resources/derivatives/8/8846E3E6-8AC8-4857-8448-E3D025784410_1_105_c.jpeg new file mode 100644 index 00000000..539b4e59 Binary files /dev/null and b/tests/Test-10.15.5.photoslibrary/resources/derivatives/8/8846E3E6-8AC8-4857-8448-E3D025784410_1_105_c.jpeg differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/derivatives/masters/8/8846E3E6-8AC8-4857-8448-E3D025784410_4_5005_c.jpeg b/tests/Test-10.15.5.photoslibrary/resources/derivatives/masters/8/8846E3E6-8AC8-4857-8448-E3D025784410_4_5005_c.jpeg new file mode 100644 index 00000000..a2680855 Binary files /dev/null and b/tests/Test-10.15.5.photoslibrary/resources/derivatives/masters/8/8846E3E6-8AC8-4857-8448-E3D025784410_4_5005_c.jpeg differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/3305.ithmb b/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/3305.ithmb index 71616af1..be7bf503 100644 Binary files a/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/3305.ithmb and b/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/3305.ithmb differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4031.ithmb b/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4031.ithmb index 47b6132e..a22b08c3 100644 Binary files a/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4031.ithmb and b/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4031.ithmb differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4132.ithmb b/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4132.ithmb index 2f291986..7cf66c49 100644 Binary files a/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4132.ithmb and b/tests/Test-10.15.5.photoslibrary/resources/derivatives/thumbs/4132.ithmb differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/journals/Asset-change.plj b/tests/Test-10.15.5.photoslibrary/resources/journals/Asset-change.plj new file mode 100644 index 00000000..063b0b7a Binary files /dev/null and b/tests/Test-10.15.5.photoslibrary/resources/journals/Asset-change.plj differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/journals/HistoryToken.plist b/tests/Test-10.15.5.photoslibrary/resources/journals/HistoryToken.plist index 7f5ca8d9..2621d7f7 100644 Binary files a/tests/Test-10.15.5.photoslibrary/resources/journals/HistoryToken.plist and b/tests/Test-10.15.5.photoslibrary/resources/journals/HistoryToken.plist differ diff --git a/tests/Test-10.15.5.photoslibrary/resources/journals/ImportSession-change.plj b/tests/Test-10.15.5.photoslibrary/resources/journals/ImportSession-change.plj new file mode 100644 index 00000000..cdf80364 Binary files /dev/null and b/tests/Test-10.15.5.photoslibrary/resources/journals/ImportSession-change.plj differ diff --git a/tests/test-images/IMG_1693.tif b/tests/test-images/IMG_1693.tif new file mode 100644 index 00000000..69654411 Binary files /dev/null and b/tests/test-images/IMG_1693.tif differ diff --git a/tests/test_catalina_10_15_5.py b/tests/test_catalina_10_15_5.py index 96716dd8..2831952d 100644 --- a/tests/test_catalina_10_15_5.py +++ b/tests/test_catalina_10_15_5.py @@ -7,6 +7,8 @@ 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" +PHOTOS_DB_LEN = 13 + KEYWORDS = [ "Kids", "wedding", @@ -24,7 +26,7 @@ ALBUMS = [ "Pumpkin Farm", "Test Album", "AlbumInFolder", - "Raw" + "Raw", ] # Note: there are 2 albums named "Test Album" for testing duplicate album names KEYWORDS_DICT = { "Kids": 4, @@ -58,6 +60,7 @@ UUID_DICT = { "external_edit": "DC99FBDD-7A52-4100-A5BB-344131646C30", "no_external_edit": "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51", "export": "D79B8D77-BFFC-460B-9312-034F2877D35B", # "Pumkins2.jpg" + "export_tif": "8846E3E6-8AC8-4857-8448-E3D025784410", } @@ -109,14 +112,14 @@ def test_init4(): def test_init5(mocker): # test failed get_last_library_path import osxphotos - + def bad_library(): return None # get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb # because of the layout of photosdb/ need to patch it this way...don't really understand why, but it works mocker.patch("osxphotos.photosdb.photosdb.get_last_library_path", new=bad_library) - + with pytest.raises(Exception): assert osxphotos.PhotosDB() @@ -126,7 +129,7 @@ def test_db_len(): photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS - assert len(photosdb) == 12 + assert len(photosdb) == PHOTOS_DB_LEN def test_db_version(): @@ -378,7 +381,7 @@ def test_count(): photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photos = photosdb.photos() - assert len(photos) == 12 + assert len(photos) == PHOTOS_DB_LEN def test_keyword_2(): @@ -730,6 +733,31 @@ def test_export_13(): assert e.type == type(FileNotFoundError()) +def test_export_14(caplog): + # test export with user provided filename with different (but valid) extension than source + import os + import os.path + import tempfile + import time + + import osxphotos + + tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_") + dest = tempdir.name + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) + photos = photosdb.photos(uuid=[UUID_DICT["export_tif"]]) + + timestamp = time.time() + filename = f"osxphotos-export-2-test-{timestamp}.tif" + expected_dest = os.path.join(dest, filename) + got_dest = photos[0].export(dest, filename)[0] + + assert got_dest == expected_dest + assert os.path.isfile(got_dest) + + assert "Invalid destination suffix" not in caplog.text + + def test_eq(): import osxphotos @@ -781,7 +809,7 @@ def test_from_to_date(): photosdb = osxphotos.PhotosDB(PHOTOS_DB) photos = photosdb.photos(from_date=dt.datetime(2018, 10, 28)) - assert len(photos) ==6 + assert len(photos) == 7 photos = photosdb.photos(to_date=dt.datetime(2018, 10, 28)) assert len(photos) == 6 diff --git a/tests/test_cli.py b/tests/test_cli.py index 90b84534..384137e9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -164,6 +164,7 @@ CLI_EXPORTED_FILENAME_TEMPLATE_FILENAMES2 = [ "Pumpkin Farm-Pumpkins3.jpg", "Test Album-Pumkins1.jpg", "Test Album-Pumkins2.jpg", + "None-IMG_1693.tif", ] CLI_EXPORT_UUID = "D79B8D77-BFFC-460B-9312-034F2877D35B"