Fix for #515, updated tests

This commit is contained in:
Rhet Turnbull
2021-09-14 17:24:02 -07:00
parent 93bf0c210c
commit 59c31ff88d
15 changed files with 166 additions and 58 deletions

View File

@@ -93,6 +93,12 @@ CLI_EXPORT_FILENAMES = [
"screenshot-really-a-png.jpeg",
"winebottle.jpeg",
"winebottle (1).jpeg",
"Frítest.jpg",
"Frítest (1).jpg",
"Frítest (2).jpg",
"Frítest (3).jpg",
"Frítest_edited.jpeg",
"Frítest_edited (1).jpeg",
]
@@ -120,6 +126,8 @@ CLI_EXPORT_FILENAMES_DRY_RUN = [
"screenshot-really-a-png.jpeg",
"winebottle.jpeg",
"winebottle.jpeg",
"Frítest.jpg",
"Frítest_edited.jpeg",
]
CLI_EXPORT_IGNORE_SIGNATURE_FILENAMES = ["Tulips.jpg", "wedding.jpg"]
@@ -160,6 +168,12 @@ CLI_EXPORT_FILENAMES_EDITED_SUFFIX = [
"screenshot-really-a-png.jpeg",
"winebottle.jpeg",
"winebottle (1).jpeg",
"Frítest.jpg",
"Frítest (1).jpg",
"Frítest (2).jpg",
"Frítest (3).jpg",
"Frítest_bearbeiten.jpeg",
"Frítest_bearbeiten (1).jpeg",
]
CLI_EXPORT_FILENAMES_EDITED_SUFFIX_TEMPLATE = [
@@ -186,6 +200,12 @@ CLI_EXPORT_FILENAMES_EDITED_SUFFIX_TEMPLATE = [
"screenshot-really-a-png.jpeg",
"winebottle.jpeg",
"winebottle (1).jpeg",
"Frítest.jpg",
"Frítest (1).jpg",
"Frítest (2).jpg",
"Frítest (3).jpg",
"Frítest_edited.jpeg",
"Frítest_edited (1).jpeg",
]
CLI_EXPORT_FILENAMES_ORIGINAL_SUFFIX = [
@@ -212,6 +232,12 @@ CLI_EXPORT_FILENAMES_ORIGINAL_SUFFIX = [
"screenshot-really-a-png_original.jpeg",
"winebottle_original.jpeg",
"winebottle_original (1).jpeg",
"Frítest_original.jpg",
"Frítest_original (1).jpg",
"Frítest_original (2).jpg",
"Frítest_original (3).jpg",
"Frítest_edited.jpeg",
"Frítest_edited (1).jpeg",
]
CLI_EXPORT_FILENAMES_ORIGINAL_SUFFIX_TEMPLATE = [
@@ -238,6 +264,12 @@ CLI_EXPORT_FILENAMES_ORIGINAL_SUFFIX_TEMPLATE = [
"screenshot-really-a-png.jpeg",
"winebottle.jpeg",
"winebottle (1).jpeg",
"Frítest.jpg",
"Frítest (1).jpg",
"Frítest_original.jpg",
"Frítest_edited.jpeg",
"Frítest_original (1).jpg",
"Frítest_edited (1).jpeg",
]
CLI_EXPORT_FILENAMES_CURRENT = [
@@ -264,6 +296,12 @@ CLI_EXPORT_FILENAMES_CURRENT = [
"D1359D09-1373-4F3B-B0E3-1A4DE573E4A3.mp4",
"E2078879-A29C-4D6F-BACB-E3BBE6C3EB91.jpeg",
"52083079-73D5-4921-AC1B-FE76F279133F.jpeg",
"B13F4485-94E0-41CD-AF71-913095D62E31.jpeg", # Frítest.jpg
"1793FAAB-DE75-4E25-886C-2BD66C780D6A.jpeg", # Frítest.jpg
"1793FAAB-DE75-4E25-886C-2BD66C780D6A_edited.jpeg", # Frítest.jpg
"A8266C97-9BAF-4AF4-99F3-0013832869B8.jpeg", # Frítest.jpg
"D1D4040D-D141-44E8-93EA-E403D9F63E07.jpeg", # Frítest.jpg
"D1D4040D-D141-44E8-93EA-E403D9F63E07_edited.jpeg", # Frítest.jpg
]
CLI_EXPORT_FILENAMES_CONVERT_TO_JPEG = [
@@ -290,6 +328,12 @@ CLI_EXPORT_FILENAMES_CONVERT_TO_JPEG = [
"screenshot-really-a-png.jpeg",
"winebottle.jpeg",
"winebottle (1).jpeg",
"Frítest.jpg",
"Frítest (1).jpg",
"Frítest (2).jpg",
"Frítest (3).jpg",
"Frítest_edited (1).jpeg",
"Frítest_edited.jpeg",
]
CLI_EXPORT_FILENAMES_CONVERT_TO_JPEG_SKIP_RAW = [
@@ -314,6 +358,12 @@ CLI_EXPORT_FILENAMES_CONVERT_TO_JPEG_SKIP_RAW = [
"screenshot-really-a-png.jpeg",
"winebottle.jpeg",
"winebottle (1).jpeg",
"Frítest.jpg",
"Frítest (1).jpg",
"Frítest (2).jpg",
"Frítest (3).jpg",
"Frítest_edited.jpeg",
"Frítest_edited (1).jpeg",
]
CLI_EXPORT_CONVERT_TO_JPEG_LARGE_FILE = "DSC03584.jpeg"
@@ -486,10 +536,10 @@ PHOTOS_NOT_IN_TRASH_LEN_14_6 = 12
PHOTOS_IN_TRASH_LEN_14_6 = 1
PHOTOS_MISSING_14_6 = 1
PHOTOS_NOT_IN_TRASH_LEN_15_7 = 19
PHOTOS_NOT_IN_TRASH_LEN_15_7 = 23
PHOTOS_IN_TRASH_LEN_15_7 = 2
PHOTOS_MISSING_15_7 = 2
PHOTOS_EDITED_15_7 = 4
PHOTOS_EDITED_15_7 = 6
CLI_PLACES_JSON = """{"places": {"_UNKNOWN_": 1, "Maui, Wailea, Hawai'i, United States": 1, "Washington, District of Columbia, United States": 1}}"""
@@ -645,6 +695,15 @@ KEYWORDS_JSON = {
"Val d'Isère": 2,
"Drink": 2,
"Wine Bottle": 2,
"Food": 2,
"Furniture": 2,
"Pizza": 2,
"Table": 2,
"Cloudy": 2,
"Cord": 2,
"Outdoor": 2,
"Sky": 2,
"Sunset Sunrise": 2,
}
}
@@ -762,6 +821,10 @@ UUID_NOT_IN_ALBUM = [
"8846E3E6-8AC8-4857-8448-E3D025784410",
"7F74DD34-5920-4DA3-B284-479887A34F66",
"52083079-73D5-4921-AC1B-FE76F279133F",
"B13F4485-94E0-41CD-AF71-913095D62E31", # Frítest.jpg
"1793FAAB-DE75-4E25-886C-2BD66C780D6A", # Frítest.jpg
"A8266C97-9BAF-4AF4-99F3-0013832869B8", # Frítest.jpg
"D1D4040D-D141-44E8-93EA-E403D9F63E07", # Frítest.jpg
]
UUID_DUPLICATES = [
@@ -4297,7 +4360,7 @@ def test_export_update_basic():
)
assert result.exit_code == 0
assert (
"Processed: 19 photos, exported: 0, updated: 0, skipped: 23, updated EXIF data: 0, missing: 2, error: 0"
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: 0, updated: 0, skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, updated EXIF data: 0, missing: 2, error: 0"
in result.output
)
@@ -4381,7 +4444,7 @@ def test_export_update_exiftool():
)
assert result.exit_code == 0
assert (
"Processed: 19 photos, exported: 0, updated: 23, skipped: 0, updated EXIF data: 23, missing: 2, error: 1"
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: 0, updated: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, skipped: 0, updated EXIF data: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, missing: 2, error: 1"
in result.output
)
@@ -4391,7 +4454,7 @@ def test_export_update_exiftool():
)
assert result.exit_code == 0
assert (
"Processed: 19 photos, exported: 0, updated: 0, skipped: 23, updated EXIF data: 0, missing: 2, error: 0"
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: 0, updated: 0, skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, updated EXIF data: 0, missing: 2, error: 0"
in result.output
)
@@ -4428,7 +4491,7 @@ def test_export_update_hardlink():
)
assert result.exit_code == 0
assert (
"Processed: 19 photos, exported: 0, updated: 23, skipped: 0, updated EXIF data: 0, missing: 2, error: 0"
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: 0, updated: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, skipped: 0, updated EXIF data: 0, missing: 2, error: 0"
in result.output
)
assert not os.path.samefile(CLI_EXPORT_UUID_FILENAME, photo.path)
@@ -4467,7 +4530,7 @@ def test_export_update_hardlink_exiftool():
)
assert result.exit_code == 0
assert (
"Processed: 19 photos, exported: 0, updated: 23, skipped: 0, updated EXIF data: 23, missing: 2, error: 1"
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: 0, updated: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, skipped: 0, updated EXIF data: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, missing: 2, error: 1"
in result.output
)
assert not os.path.samefile(CLI_EXPORT_UUID_FILENAME, photo.path)
@@ -4553,7 +4616,7 @@ def test_export_update_only_new():
],
)
assert result.exit_code == 0
assert "exported: 1" in result.output
assert "exported: 7" in result.output
# --update with --only-new
result = runner.invoke(
@@ -4561,7 +4624,7 @@ def test_export_update_only_new():
[os.path.join(cwd, PHOTOS_DB_15_7), ".", "-V", "--update", "--only-new"],
)
assert result.exit_code == 0
assert "exported: 1" in result.output
assert "exported: 7" in result.output
# --update with --only-new, should export nothing
result = runner.invoke(
@@ -4603,7 +4666,7 @@ def test_export_update_no_db():
# edited files will be re-exported because there won't be an edited signature
# in the database
assert (
"Processed: 19 photos, exported: 0, updated: 4, skipped: 19, updated EXIF data: 0, missing: 2, error: 0"
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: 0, updated: {PHOTOS_EDITED_15_7}, skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7}, updated EXIF data: 0, missing: 2, error: 0"
in result.output
)
assert os.path.isfile(OSXPHOTOS_EXPORT_DB)
@@ -4643,7 +4706,8 @@ def test_export_then_hardlink():
)
assert result.exit_code == 0
assert (
"Processed: 19 photos, exported: 23, missing: 2, error: 0" in result.output
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, missing: 2, error: 0"
in result.output
)
assert os.path.samefile(CLI_EXPORT_UUID_FILENAME, photo.path)
@@ -4656,6 +4720,7 @@ def test_export_dry_run():
import osxphotos
from osxphotos.cli import export
from osxphotos.utils import normalize_fs_path
runner = CliRunner()
cwd = os.getcwd()
@@ -4666,11 +4731,12 @@ def test_export_dry_run():
)
assert result.exit_code == 0
assert (
"Processed: 19 photos, exported: 23, missing: 2, error: 0" in result.output
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, missing: 2, error: 0"
in result.output
)
for filepath in CLI_EXPORT_FILENAMES_DRY_RUN:
assert re.search(r"Exported.*" + f"{filepath}", result.output)
assert not os.path.isfile(filepath)
assert not os.path.isfile(normalize_fs_path(filepath))
def test_export_update_edits_dry_run():
@@ -4747,7 +4813,10 @@ def test_export_directory_template_1_dry_run():
],
)
assert result.exit_code == 0
assert "exported: 23" in result.output
assert (
f"exported: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
workdir = os.getcwd()
for filepath in CLI_EXPORTED_DIRECTORY_TEMPLATE_FILENAMES1:
assert re.search(r"Exported.*" + f"{filepath}", result.output)
@@ -4783,8 +4852,14 @@ def test_export_touch_files():
)
assert result.exit_code == 0
assert "exported: 23" in result.output
assert "touched date: 21" in result.output
assert (
f"exported: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
assert (
f"touched date: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7-2}"
in result.output
)
for fname, mtime in zip(CLI_EXPORT_BY_DATE, CLI_EXPORT_BY_DATE_TOUCH_TIMES):
st = os.stat(fname)
@@ -4816,7 +4891,10 @@ def test_export_touch_files_update():
)
assert result.exit_code == 0
assert "exported: 23" in result.output
assert (
f"exported: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
assert not pathlib.Path(CLI_EXPORT_BY_DATE[0]).is_file()
@@ -4826,7 +4904,10 @@ def test_export_touch_files_update():
)
assert result.exit_code == 0
assert "exported: 23" in result.output
assert (
f"exported: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
assert pathlib.Path(CLI_EXPORT_BY_DATE[0]).is_file()
@@ -4837,7 +4918,10 @@ def test_export_touch_files_update():
)
assert result.exit_code == 0
assert "skipped: 23" in result.output
assert (
f"skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
# --update --touch-file --dry-run
result = runner.invoke(
@@ -4852,8 +4936,14 @@ def test_export_touch_files_update():
],
)
assert result.exit_code == 0
assert "skipped: 23" in result.output
assert "touched date: 21" in result.output
assert (
f"skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
assert (
f"touched date: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7-2}"
in result.output
)
for fname, mtime in zip(
CLI_EXPORT_BY_DATE_NEED_TOUCH, CLI_EXPORT_BY_DATE_NEED_TOUCH_TIMES
@@ -4873,8 +4963,14 @@ def test_export_touch_files_update():
],
)
assert result.exit_code == 0
assert "skipped: 23" in result.output
assert "touched date: 21" in result.output
assert (
f"skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
assert (
f"touched date: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7-2}"
in result.output
)
for fname, mtime in zip(
CLI_EXPORT_BY_DATE_NEED_TOUCH, CLI_EXPORT_BY_DATE_NEED_TOUCH_TIMES
@@ -4897,7 +4993,7 @@ def test_export_touch_files_update():
],
)
assert result.exit_code == 0
assert "updated: 1, skipped: 22" in result.output
assert f"updated: 1, skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7-1}" in result.output
assert "touched date: 1" in result.output
for fname, mtime in zip(CLI_EXPORT_BY_DATE, CLI_EXPORT_BY_DATE_TOUCH_TIMES):
@@ -4911,7 +5007,10 @@ def test_export_touch_files_update():
)
assert result.exit_code == 0
assert "skipped: 23" in result.output
assert (
f"skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}"
in result.output
)
@pytest.mark.skip("TODO: This fails on some machines but not all")
@@ -6551,7 +6650,7 @@ def test_query_min_size_1():
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 2
assert len(json_got) == 4
def test_query_min_size_2():
@@ -6578,7 +6677,7 @@ def test_query_min_size_2():
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 2
assert len(json_got) == 4
def test_query_max_size_1():
@@ -6599,7 +6698,7 @@ def test_query_max_size_1():
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 1
assert len(json_got) == 3
def test_query_max_size_2():
@@ -6620,7 +6719,7 @@ def test_query_max_size_2():
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 1
assert len(json_got) == 3
def test_query_min_max_size():