Updated tests
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
""" Basic tests for Photos 5 on MacOS 10.15.6 """
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
import pytest
|
||||
|
||||
from osxphotos._constants import _UNKNOWN_PERSON
|
||||
|
||||
|
||||
PHOTOS_DB = "tests/Test-10.15.6.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_PATH = "/Test-10.15.6.photoslibrary/database/photos.db"
|
||||
PHOTOS_LIBRARY_PATH = "/Test-10.15.6.photoslibrary"
|
||||
@@ -109,6 +109,63 @@ UTI_ORIGINAL_DICT = {
|
||||
}
|
||||
|
||||
|
||||
RawInfo = namedtuple(
|
||||
"RawInfo",
|
||||
[
|
||||
"comment",
|
||||
"original_filename",
|
||||
"has_raw",
|
||||
"israw",
|
||||
"raw_original",
|
||||
"uti",
|
||||
"uti_original",
|
||||
"uti_raw",
|
||||
],
|
||||
)
|
||||
RAW_DICT = {
|
||||
"D05A5FE3-15FB-49A1-A15D-AB3DA6F8B068": RawInfo(
|
||||
"raw image, no jpeg pair",
|
||||
"DSC03584.dng",
|
||||
False,
|
||||
True,
|
||||
False,
|
||||
"com.adobe.raw-image",
|
||||
"com.adobe.raw-image",
|
||||
None,
|
||||
),
|
||||
"A92D9C26-3A50-4197-9388-CB5F7DB9FA91": RawInfo(
|
||||
"raw+jpeg, jpeg original",
|
||||
"IMG_1994.JPG",
|
||||
True,
|
||||
False,
|
||||
False,
|
||||
"public.jpeg",
|
||||
"public.jpeg",
|
||||
"com.canon.cr2-raw-image",
|
||||
),
|
||||
"4D521201-92AC-43E5-8F7C-59BC41C37A96": RawInfo(
|
||||
"raw+jpeg, raw original",
|
||||
"IMG_1997.JPG",
|
||||
True,
|
||||
False,
|
||||
True,
|
||||
"public.jpeg",
|
||||
"public.jpeg",
|
||||
"com.canon.cr2-raw-image",
|
||||
),
|
||||
"E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51": RawInfo(
|
||||
"jpeg, no raw",
|
||||
"wedding.jpg",
|
||||
False,
|
||||
False,
|
||||
False,
|
||||
"public.jpeg",
|
||||
"public.jpeg",
|
||||
None,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def test_init1():
|
||||
# test named argument
|
||||
import osxphotos
|
||||
@@ -137,6 +194,7 @@ def test_init4():
|
||||
# test invalid db
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import osxphotos
|
||||
|
||||
(bad_db, bad_db_name) = tempfile.mkstemp(suffix=".db", prefix="osxphotos-")
|
||||
@@ -186,27 +244,30 @@ def test_db_version():
|
||||
|
||||
|
||||
def test_persons():
|
||||
import osxphotos
|
||||
import collections
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
assert "Katie" in photosdb.persons
|
||||
assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons)
|
||||
|
||||
|
||||
def test_keywords():
|
||||
import osxphotos
|
||||
import collections
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
assert "wedding" in photosdb.keywords
|
||||
assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords)
|
||||
|
||||
|
||||
def test_album_names():
|
||||
import osxphotos
|
||||
import collections
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
assert "Pumpkin Farm" in photosdb.albums
|
||||
assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums)
|
||||
@@ -261,6 +322,7 @@ def test_album_empty_album():
|
||||
|
||||
def test_attributes():
|
||||
import datetime
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
@@ -286,6 +348,7 @@ def test_attributes():
|
||||
def test_attributes_2():
|
||||
""" Test attributes including height, width, etc """
|
||||
import datetime
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
@@ -449,6 +512,7 @@ def test_external_edit2():
|
||||
def test_path_edited1():
|
||||
# test a valid edited path
|
||||
import os.path
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
@@ -629,9 +693,10 @@ def test_get_library_path():
|
||||
|
||||
def test_get_db_connection():
|
||||
""" Test PhotosDB.get_db_connection """
|
||||
import osxphotos
|
||||
import sqlite3
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
conn, cursor = photosdb.get_db_connection()
|
||||
|
||||
@@ -1033,9 +1098,10 @@ def test_photosdb_repr():
|
||||
|
||||
|
||||
def test_photosinfo_repr():
|
||||
import osxphotos
|
||||
import datetime
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
photos = photosdb.photos(uuid=[UUID_DICT["favorite"]])
|
||||
photo = photos[0]
|
||||
@@ -1118,6 +1184,7 @@ def test_from_to_date_tz():
|
||||
def test_date_invalid():
|
||||
""" Test date is invalid """
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
@@ -1132,6 +1199,7 @@ def test_date_invalid():
|
||||
def test_date_modified_invalid():
|
||||
""" Test date modified is invalid """
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
@@ -1154,6 +1222,7 @@ def test_import_session_count():
|
||||
def test_import_session_photo():
|
||||
""" Test photo.import_session """
|
||||
import datetime
|
||||
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
@@ -1203,3 +1272,18 @@ def test_uti():
|
||||
assert photo.uti == uti
|
||||
assert photo.uti_original == UTI_ORIGINAL_DICT[uuid]
|
||||
|
||||
|
||||
def test_raw():
|
||||
""" Test various raw properties """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
|
||||
for uuid, rawinfo in RAW_DICT.items():
|
||||
photo = photosdb.get_photo(uuid)
|
||||
assert photo.original_filename == rawinfo.original_filename
|
||||
assert photo.has_raw == rawinfo.has_raw
|
||||
assert photo.israw == rawinfo.israw
|
||||
assert photo.uti == rawinfo.uti
|
||||
assert photo.uti_original == rawinfo.uti_original
|
||||
assert photo.uti_raw == rawinfo.uti_raw
|
||||
|
||||
@@ -3093,8 +3093,8 @@ def test_export_touch_files_update():
|
||||
)
|
||||
|
||||
|
||||
# @pytest.mark.skip("TODO: This fails on some machines but not all")
|
||||
@pytest.mark.skipif(exiftool is None, reason="exiftool not installed")
|
||||
@pytest.mark.skip("TODO: This fails on some machines but not all")
|
||||
# @pytest.mark.skipif(exiftool is None, reason="exiftool not installed")
|
||||
def test_export_touch_files_exiftool_update():
|
||||
""" test complex export scenario with --update, --exiftool, and --touch-files """
|
||||
import os
|
||||
|
||||
Reference in New Issue
Block a user