From c719b21d7899e809eeac66380d2290c61a64dd1e Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sun, 15 Sep 2024 17:49:20 -0500 Subject: [PATCH] Test updates --- tests/test_modified_date_mojave_10_14_6.py | 14 +++++++++++--- tests/test_monterey_dev_beta_12_0_0.py | 14 +++++++++++--- tests/test_photodates.py | 5 ++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/test_modified_date_mojave_10_14_6.py b/tests/test_modified_date_mojave_10_14_6.py index 49ff35e5..4be8b1b3 100644 --- a/tests/test_modified_date_mojave_10_14_6.py +++ b/tests/test_modified_date_mojave_10_14_6.py @@ -1,4 +1,6 @@ import datetime +from unittest import mock +from zoneinfo import ZoneInfo import pytest @@ -23,9 +25,15 @@ def photosdb(): def test_modified(photosdb): photos = photosdb.photos(uuid=[UUID_DICT["modified"]]) - assert photos[0].date_modified == dt_to_local( - datetime.datetime.fromisoformat("2019-12-01T09:43:45.714123-04:00") - ) + mock_local_timezone = ZoneInfo("America/Chicago") + with mock.patch("datetime.datetime", wraps=datetime.datetime) as mock_datetime: + mock_datetime.now.return_value = datetime.datetime( + 2019, 12, 1, 9, 43, 45, 714123, tzinfo=mock_local_timezone + ) + expected = datetime.datetime( + 2019, 12, 1, 9, 43, 45, 714123, tzinfo=mock_local_timezone + ) + assert photos[0].date_modified == expected # no non-modified photos in the 10.14.6 database diff --git a/tests/test_monterey_dev_beta_12_0_0.py b/tests/test_monterey_dev_beta_12_0_0.py index 7fe3860c..eec61d33 100644 --- a/tests/test_monterey_dev_beta_12_0_0.py +++ b/tests/test_monterey_dev_beta_12_0_0.py @@ -9,6 +9,8 @@ import tempfile import time from collections import Counter, namedtuple +from unittest import mock +from zoneinfo import ZoneInfo import pytest @@ -651,9 +653,15 @@ def test_photoinfo_intrash_1(photosdb): p = photosdb.photos(uuid=[UUID_DICT["intrash"]], intrash=True)[0] assert p.intrash - assert dt_to_local(p.date_trashed) == dt_to_local( - datetime.datetime.fromisoformat("2120-06-10T11:24:47.685857-05:00") - ) + mock_local_timezone = ZoneInfo("America/Chicago") + with mock.patch("datetime.datetime", wraps=datetime.datetime) as mock_datetime: + mock_datetime.now.return_value = datetime.datetime( + 2120, 6, 10, 11, 24, 47, 685857, tzinfo=mock_local_timezone + ) + expected = datetime.datetime( + 2120, 6, 10, 11, 24, 47, 685857, tzinfo=mock_local_timezone + ) + assert p.date_trashed == expected def test_photoinfo_intrash_2(photosdb): diff --git a/tests/test_photodates.py b/tests/test_photodates.py index 2aba1152..fc993417 100644 --- a/tests/test_photodates.py +++ b/tests/test_photodates.py @@ -4,8 +4,6 @@ # library be active in the Photos library (uses AppleScript) - - import datetime import zoneinfo @@ -17,9 +15,10 @@ if not is_macos: pytest.skip("Skipping macOS only tests", allow_module_level=True) -from osxphotos.photodates import get_photo_date_added, get_photo_date_original from photoscript import Photo +from osxphotos.photodates import get_photo_date_added, get_photo_date_original + if int(get_os_version()[0]) < 13: pytest.skip("Skipping; requires macOS >= 13.0 (Ventura)", allow_module_level=True)