Refactor verbose 931 (#960)
* Began refactoring verbose code for #931 * Fixed tests for timewarp due to verbose refactor * Updated test data * More refactoring for #931 * Refactored queryoptions.py * Refactored queryoptions.py * Refactored queryoptions.py * Refactored echo_error * Refactored debug * Refactored debug * Refactored use of verbose in export * Refactored use of verbose in export * Refactred --verbose in add-locations and debug-dump * Refactored --verbose for * Refactored --verbose for osxphotos exportdb * Refactored --verbose for osxphotos import * Refactored --verbose for osxphotos orphans * Refactored --verbose for osxphotos snap-diff * Refactored --verbose for osxphotos sync * Refactored --verbose for osxphotos timewarp * Added default verbose() function to verbose
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -7,7 +7,7 @@
|
||||
<key>hostuuid</key>
|
||||
<string>585B80BF-8D1F-55EF-A9E8-6CF4E5523959</string>
|
||||
<key>pid</key>
|
||||
<integer>1961</integer>
|
||||
<integer>508</integer>
|
||||
<key>processname</key>
|
||||
<string>photolibraryd</string>
|
||||
<key>uid</key>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,12 +2,18 @@
|
||||
|
||||
import datetime
|
||||
import pathlib
|
||||
import time
|
||||
|
||||
from tests.parse_timewarp_output import CompareValues, InspectValues
|
||||
|
||||
TEST_LIBRARY_TIMEWARP = "tests/TestTimeWarp-10.15.7.photoslibrary"
|
||||
|
||||
|
||||
def is_dst() -> bool:
|
||||
"""Return True if daylight savings time is in effect"""
|
||||
return bool(time.localtime().tm_isdst)
|
||||
|
||||
|
||||
def get_file_timestamp(file: str) -> str:
|
||||
"""Get timestamp of file"""
|
||||
return datetime.datetime.fromtimestamp(pathlib.Path(file).stat().st_mtime).strftime(
|
||||
@@ -24,6 +30,7 @@ CATALINA_PHOTOS_5 = {
|
||||
"marigold flowers": "IMG_6517.jpeg",
|
||||
"multi-colored zinnia flowers": "IMG_6506.jpeg",
|
||||
"sunset": "IMG_6551.mov",
|
||||
"palm tree": "20230120_010203-0400.jpg",
|
||||
},
|
||||
"inspect": {
|
||||
# IMG_6501.jpeg
|
||||
@@ -362,4 +369,28 @@ CATALINA_PHOTOS_5 = {
|
||||
"GMT-0700",
|
||||
),
|
||||
},
|
||||
"parse_date": {
|
||||
# 20230120_010203-0400.jpg
|
||||
"uuid": "5285C4E2-BB1A-49DF-AEF5-246AA337ACAB",
|
||||
"expected": InspectValues(
|
||||
"20230120_010203-0400.jpg",
|
||||
"5285C4E2-BB1A-49DF-AEF5-246AA337ACAB",
|
||||
"2023-01-20 01:02:03-0800" if not is_dst() else "2023-01-20 00:02:03-0700",
|
||||
"2023-01-20 01:02:03-0800" if not is_dst() else "2023-01-20 00:02:03-0700",
|
||||
"-0800",
|
||||
"GMT-0800",
|
||||
),
|
||||
},
|
||||
"parse_date_tz": {
|
||||
# 20230120_010203-0400.jpg
|
||||
"uuid": "5285C4E2-BB1A-49DF-AEF5-246AA337ACAB",
|
||||
"expected": InspectValues(
|
||||
"20230120_010203-0400.jpg",
|
||||
"5285C4E2-BB1A-49DF-AEF5-246AA337ACAB",
|
||||
"2023-01-19 21:02:03-0800" if not is_dst() else "2023-01-19 20:02:03-0700",
|
||||
"2023-01-20 01:02:03-0400",
|
||||
"-0400",
|
||||
"GMT-0400",
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -66,19 +66,19 @@ elif OS_VER[0] == "13":
|
||||
TEST_LIBRARY_SYNC = TEST_LIBRARY
|
||||
from tests.config_timewarp_ventura import TEST_LIBRARY_TIMEWARP
|
||||
|
||||
TEST_LIBRARY_ADD_LOCATIONS = None
|
||||
TEST_LIBRARY_ADD_LOCATIONS = "tests/Test-13.0.0.photoslibrary"
|
||||
else:
|
||||
TEST_LIBRARY = None
|
||||
TEST_LIBRARY_TIMEWARP = None
|
||||
TEST_LIBRARY_SYNC = None
|
||||
TEST_LIBRARY_ADD_LOCATIONS = "tests/Test-13.0.0.photoslibrary"
|
||||
TEST_LIBRARY_ADD_LOCATIONS = None
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def setup_photos_timewarp():
|
||||
if not TEST_TIMEWARP:
|
||||
return
|
||||
copy_photos_library(TEST_LIBRARY_TIMEWARP, delay=10)
|
||||
copy_photos_library(TEST_LIBRARY_TIMEWARP, delay=5)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
||||
@@ -24,10 +24,8 @@ CompareValues = namedtuple(
|
||||
|
||||
def parse_inspect_output(output: str) -> List[InspectValues]:
|
||||
"""Parse output of --inspect and return list of InspectValues named tuple"""
|
||||
|
||||
with open(output, "r") as f:
|
||||
lines = f.readlines()
|
||||
lines = [line for line in lines if line.strip()]
|
||||
|
||||
lines = [line for line in output.split("\n") if line.strip()]
|
||||
# remove header
|
||||
lines.pop(0)
|
||||
values = []
|
||||
@@ -40,9 +38,7 @@ def parse_inspect_output(output: str) -> List[InspectValues]:
|
||||
|
||||
def parse_compare_exif(output: str) -> List[CompareValues]:
|
||||
"""Parse output of --compare-exif and return list of CompareValues named tuple"""
|
||||
with open(output, "r") as f:
|
||||
lines = f.readlines()
|
||||
lines = [line for line in lines if line.strip()]
|
||||
lines = [line for line in output.split("\n") if line.strip()]
|
||||
# remove header
|
||||
lines.pop(0)
|
||||
values = []
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -14,9 +14,9 @@ import pytest
|
||||
import osxphotos
|
||||
from osxphotos._constants import _UNKNOWN_PERSON
|
||||
from osxphotos.photoexporter import PhotoExporter
|
||||
from osxphotos.utils import _get_os_version
|
||||
from osxphotos.utils import get_macos_version
|
||||
|
||||
OS_VERSION = _get_os_version()
|
||||
OS_VERSION = get_macos_version()
|
||||
SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "15"
|
||||
PHOTOS_DB_LOCAL = os.path.expanduser("~/Pictures/Photos Library.photoslibrary")
|
||||
|
||||
|
||||
@@ -73,18 +73,18 @@ def test_select_pears(photoslib, suspend_capture):
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_inspect(photoslib, suspend_capture, output_file):
|
||||
def test_inspect(photoslib, suspend_capture):
|
||||
"""Test --inspect. NOTE: this test requires user interaction"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
values = parse_inspect_output(output_file)
|
||||
values = parse_inspect_output(result.output)
|
||||
assert TEST_DATA["inspect"]["expected"] == values
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ def test_date(photoslib, suspend_capture):
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("input_value,expected", TEST_DATA["date_delta"]["parameters"])
|
||||
def test_date_delta(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
def test_date_delta(photoslib, suspend_capture, input_value, expected):
|
||||
"""Test --date-delta"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -129,16 +129,16 @@ def test_date_delta(photoslib, suspend_capture, input_value, expected, output_fi
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("input_value,expected", TEST_DATA["time"]["parameters"])
|
||||
def test_time(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
def test_time(photoslib, suspend_capture, input_value, expected):
|
||||
"""Test --time"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -158,16 +158,16 @@ def test_time(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
# don't use photo.date as it will return local time instead of the time in the timezone
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("input_value,expected", TEST_DATA["time_delta"]["parameters"])
|
||||
def test_time_delta(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
def test_time_delta(photoslib, suspend_capture, input_value, expected):
|
||||
"""Test --time-delta"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -185,10 +185,10 @@ def test_time_delta(photoslib, suspend_capture, input_value, expected, output_fi
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@@ -216,34 +216,28 @@ def test_time_zone(
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected_date
|
||||
assert output_values[0].tz_offset == expected_tz
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("expected", TEST_DATA["compare_exif"]["expected"])
|
||||
def test_compare_exif(photoslib, suspend_capture, expected, output_file):
|
||||
def test_compare_exif(photoslib, suspend_capture, expected):
|
||||
"""Test --compare-exif"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
[
|
||||
"--compare-exif",
|
||||
"--plain",
|
||||
"--force",
|
||||
"-o",
|
||||
output_file,
|
||||
],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == expected
|
||||
|
||||
|
||||
@@ -281,24 +275,24 @@ def test_select_sunflowers(photoslib, suspend_capture):
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("expected", TEST_DATA["compare_exif_3"]["expected"])
|
||||
def test_compare_exif_3(photoslib, suspend_capture, expected, output_file):
|
||||
def test_compare_exif_3(photoslib, suspend_capture, expected):
|
||||
"""Test --compare-exif"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == expected
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("input_value,expected", TEST_DATA["match"]["parameters"])
|
||||
def test_match(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
def test_match(photoslib, suspend_capture, input_value, expected):
|
||||
"""Test --timezone --match"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -317,10 +311,10 @@ def test_match(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@@ -380,10 +374,10 @@ def test_push_exif_1(
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected_date
|
||||
|
||||
photo = photoslib.selection[0]
|
||||
@@ -402,7 +396,7 @@ def test_select_pears_2(photoslib, suspend_capture):
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_push_exif_2(photoslib, suspend_capture, output_file):
|
||||
def test_push_exif_2(photoslib, suspend_capture):
|
||||
"""Test --push-exif"""
|
||||
pre_test = TEST_DATA["push_exif"]["pre"]
|
||||
post_test = TEST_DATA["push_exif"]["post"]
|
||||
@@ -413,10 +407,10 @@ def test_push_exif_2(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -433,15 +427,15 @@ def test_push_exif_2(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_pull_exif_1(photoslib, suspend_capture, output_file):
|
||||
def test_pull_exif_1(photoslib, suspend_capture):
|
||||
"""Test --pull-exif"""
|
||||
pre_test = TEST_DATA["pull_exif_1"]["pre"]
|
||||
post_test = TEST_DATA["pull_exif_1"]["post"]
|
||||
@@ -460,10 +454,10 @@ def test_pull_exif_1(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -480,10 +474,10 @@ def test_pull_exif_1(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@@ -494,7 +488,7 @@ def test_select_apple_tree(photoslib, suspend_capture):
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_pull_exif_no_time(photoslib, suspend_capture, output_file):
|
||||
def test_pull_exif_no_time(photoslib, suspend_capture):
|
||||
"""Test --pull-exif when photo has invalid date/time in EXIF"""
|
||||
pre_test = TEST_DATA["pull_exif_no_time"]["pre"]
|
||||
post_test = TEST_DATA["pull_exif_no_time"]["post"]
|
||||
@@ -505,10 +499,10 @@ def test_pull_exif_no_time(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -525,10 +519,10 @@ def test_pull_exif_no_time(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@@ -539,7 +533,7 @@ def test_select_marigolds(photoslib, suspend_capture):
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_pull_exif_no_offset(photoslib, suspend_capture, output_file):
|
||||
def test_pull_exif_no_offset(photoslib, suspend_capture):
|
||||
"""Test --pull-exif when photo has no offset in EXIF"""
|
||||
pre_test = TEST_DATA["pull_exif_no_offset"]["pre"]
|
||||
post_test = TEST_DATA["pull_exif_no_offset"]["post"]
|
||||
@@ -550,10 +544,10 @@ def test_pull_exif_no_offset(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -570,10 +564,10 @@ def test_pull_exif_no_offset(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@@ -586,7 +580,7 @@ def test_select_zinnias(photoslib, suspend_capture):
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_pull_exif_no_data(photoslib, suspend_capture, output_file):
|
||||
def test_pull_exif_no_data(photoslib, suspend_capture):
|
||||
"""Test --pull-exif when photo has no data in EXIF"""
|
||||
pre_test = TEST_DATA["pull_exif_no_data"]["pre"]
|
||||
post_test = TEST_DATA["pull_exif_no_data"]["post"]
|
||||
@@ -597,10 +591,10 @@ def test_pull_exif_no_data(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -618,15 +612,15 @@ def test_pull_exif_no_data(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_pull_exif_no_data_use_file_time(photoslib, suspend_capture, output_file):
|
||||
def test_pull_exif_no_data_use_file_time(photoslib, suspend_capture):
|
||||
"""Test --pull-exif when photo has no data in EXIF with --use-file-time"""
|
||||
pre_test = TEST_DATA["pull_exif_no_data_use_file_time"]["pre"]
|
||||
post_test = TEST_DATA["pull_exif_no_data_use_file_time"]["post"]
|
||||
@@ -637,10 +631,10 @@ def test_pull_exif_no_data_use_file_time(photoslib, suspend_capture, output_file
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -659,10 +653,10 @@ def test_pull_exif_no_data_use_file_time(photoslib, suspend_capture, output_file
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@@ -674,7 +668,7 @@ def test_select_sunset_video(photoslib, suspend_capture):
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("expected", TEST_DATA["compare_video_1"]["expected"])
|
||||
def test_video_compare_exif(photoslib, suspend_capture, expected, output_file):
|
||||
def test_video_compare_exif(photoslib, suspend_capture, expected):
|
||||
"""Test --compare-exif with video"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -685,13 +679,11 @@ def test_video_compare_exif(photoslib, suspend_capture, expected, output_file):
|
||||
"--compare-exif",
|
||||
"--plain",
|
||||
"--force",
|
||||
"-o",
|
||||
output_file,
|
||||
],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == expected
|
||||
|
||||
|
||||
@@ -708,22 +700,17 @@ def test_video_date_delta(
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
[
|
||||
"--date-delta",
|
||||
input_value,
|
||||
"--plain",
|
||||
"--force",
|
||||
],
|
||||
["--date-delta", input_value, "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@@ -751,16 +738,16 @@ def test_video_time_delta(
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("input_value,expected", TEST_DATA["video_date"]["parameters"])
|
||||
def test_video_date(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
def test_video_date(photoslib, suspend_capture, input_value, expected):
|
||||
"""Test --date with video"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -780,16 +767,16 @@ def test_video_date(photoslib, suspend_capture, input_value, expected, output_fi
|
||||
# don't use photo.date as it will return local time instead of the time in the timezone
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("input_value,expected", TEST_DATA["video_time"]["parameters"])
|
||||
def test_video_time(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
def test_video_time(photoslib, suspend_capture, input_value, expected):
|
||||
"""Test --time with video"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -809,10 +796,10 @@ def test_video_time(photoslib, suspend_capture, input_value, expected, output_fi
|
||||
# don't use photo.date as it will return local time instead of the time in the timezone
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@@ -840,17 +827,17 @@ def test_video_time_zone(
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected_date
|
||||
assert output_values[0].tz_offset == expected_tz
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.parametrize("input_value,expected", TEST_DATA["video_match"]["parameters"])
|
||||
def test_video_match(photoslib, suspend_capture, input_value, expected, output_file):
|
||||
def test_video_match(photoslib, suspend_capture, input_value, expected):
|
||||
"""Test --timezone --match with video"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -869,15 +856,15 @@ def test_video_match(photoslib, suspend_capture, input_value, expected, output_f
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_tz == expected
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_video_push_exif(photoslib, suspend_capture, output_file):
|
||||
def test_video_push_exif(photoslib, suspend_capture):
|
||||
"""Test --push-exif with video"""
|
||||
pre_test = TEST_DATA["video_push_exif"]["pre"]
|
||||
post_test = TEST_DATA["video_push_exif"]["post"]
|
||||
@@ -888,10 +875,10 @@ def test_video_push_exif(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -908,15 +895,15 @@ def test_video_push_exif(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_video_pull_exif(photoslib, suspend_capture, output_file):
|
||||
def test_video_pull_exif(photoslib, suspend_capture):
|
||||
"""Test --pull-exif with video"""
|
||||
pre_test = TEST_DATA["video_pull_exif"]["pre"]
|
||||
post_test = TEST_DATA["video_pull_exif"]["post"]
|
||||
@@ -946,10 +933,10 @@ def test_video_pull_exif(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == pre_test
|
||||
|
||||
result = runner.invoke(
|
||||
@@ -966,10 +953,10 @@ def test_video_pull_exif(photoslib, suspend_capture, output_file):
|
||||
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--compare-exif", "--plain", "--force", "-o", output_file],
|
||||
["--compare-exif", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_compare_exif(output_file)
|
||||
output_values = parse_compare_exif(result.output)
|
||||
assert output_values[0] == post_test
|
||||
|
||||
|
||||
@@ -980,7 +967,7 @@ def test_select_pears_3(photoslib, suspend_capture):
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
def test_function(photoslib, suspend_capture, output_file):
|
||||
def test_function(photoslib, suspend_capture):
|
||||
"""Test timewarp function"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -999,10 +986,10 @@ def test_function(photoslib, suspend_capture, output_file):
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0] == expected
|
||||
|
||||
|
||||
@@ -1013,8 +1000,7 @@ def test_select_palm_tree_1(photoslib, suspend_capture):
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.skipif(get_os_version()[0] != "13", reason="test requires macOS 13")
|
||||
def test_parse_date(photoslib, suspend_capture, output_file):
|
||||
def test_parse_date(photoslib, suspend_capture):
|
||||
"""Test --parse-date"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -1033,18 +1019,17 @@ def test_parse_date(photoslib, suspend_capture, output_file):
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_local == expected.date_local
|
||||
assert output_values[0].date_tz == expected.date_tz
|
||||
assert output_values[0].tz_offset == expected.tz_offset
|
||||
|
||||
|
||||
@pytest.mark.timewarp
|
||||
@pytest.mark.skipif(get_os_version()[0] != "13", reason="test requires macOS 13")
|
||||
def test_parse_date_tz(photoslib, suspend_capture, output_file):
|
||||
def test_parse_date_tz(photoslib, suspend_capture):
|
||||
"""Test --parse-date with a timezone"""
|
||||
from osxphotos.cli.timewarp import timewarp
|
||||
|
||||
@@ -1063,10 +1048,10 @@ def test_parse_date_tz(photoslib, suspend_capture, output_file):
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
timewarp,
|
||||
["--inspect", "--plain", "--force", "-o", output_file],
|
||||
["--inspect", "--plain", "--force"],
|
||||
terminal_width=TERMINAL_WIDTH,
|
||||
)
|
||||
output_values = parse_inspect_output(output_file)
|
||||
output_values = parse_inspect_output(result.output)
|
||||
assert output_values[0].date_local == expected.date_local
|
||||
assert output_values[0].date_tz == expected.date_tz
|
||||
assert output_values[0].tz_offset == expected.tz_offset
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from osxphotos.queryoptions import load_uuid_from_file
|
||||
|
||||
UUID_FILE = "tests/uuid_from_file.txt"
|
||||
MISSING_UUID_FILE = "tests/uuid_not_found.txt"
|
||||
|
||||
@@ -13,8 +15,7 @@ UUID_EXPECTED_FROM_FILE = [
|
||||
|
||||
|
||||
def test_load_uuid_from_file():
|
||||
"""Test load_uuid_from_file function """
|
||||
from osxphotos.cli import load_uuid_from_file
|
||||
"""Test load_uuid_from_file function"""
|
||||
|
||||
uuid_got = load_uuid_from_file(UUID_FILE)
|
||||
assert uuid_got == UUID_EXPECTED_FROM_FILE
|
||||
@@ -22,7 +23,6 @@ def test_load_uuid_from_file():
|
||||
|
||||
def test_load_uuid_from_file_filenotfound():
|
||||
"""Test load_uuid_from_file function raises error if file not found"""
|
||||
from osxphotos.cli import load_uuid_from_file
|
||||
|
||||
with pytest.raises(FileNotFoundError) as err:
|
||||
uuid_got = load_uuid_from_file(MISSING_UUID_FILE)
|
||||
|
||||
116
tests/test_cli_verbose.py
Normal file
116
tests/test_cli_verbose.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""Test verbose functions"""
|
||||
|
||||
import re
|
||||
from io import StringIO
|
||||
|
||||
|
||||
from osxphotos.cli.verbose import (
|
||||
get_verbose_level,
|
||||
set_verbose_level,
|
||||
verbose,
|
||||
verbose_print,
|
||||
_reset_verbose_globals,
|
||||
)
|
||||
|
||||
|
||||
def test_set_get_verbose_level(capsys):
|
||||
"""Test verbose_print"""
|
||||
set_verbose_level(2)
|
||||
assert get_verbose_level() == 2
|
||||
|
||||
|
||||
def test_verbose_print_no_rich(capsys):
|
||||
"""Test verbose_print"""
|
||||
set_verbose_level(1)
|
||||
verbose = verbose_print(1, False, False)
|
||||
verbose("test")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "test"
|
||||
|
||||
verbose("test2", level=1)
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "test2"
|
||||
|
||||
verbose("test3", level=2)
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == ""
|
||||
|
||||
|
||||
def test_verbose_print_rich(capsys):
|
||||
"""Test verbose with rich"""
|
||||
set_verbose_level(1)
|
||||
verbose = verbose_print(1, False, True)
|
||||
verbose("test")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "test"
|
||||
|
||||
verbose("test2", level=1)
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "test2"
|
||||
|
||||
verbose("test3", level=2)
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == ""
|
||||
|
||||
|
||||
def test_verbose_print_timestamp(capsys):
|
||||
"""Test verbose with timestamp"""
|
||||
set_verbose_level(1)
|
||||
verbose = verbose_print(1, True, False)
|
||||
verbose("test")
|
||||
captured = capsys.readouterr()
|
||||
|
||||
# regex to match timestamp in this format: 2023-01-25 06:40:18.216297
|
||||
assert re.match(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{6}", captured.out.strip())
|
||||
assert captured.out.strip().endswith("test")
|
||||
|
||||
verbose("test2", level=1)
|
||||
captured = capsys.readouterr()
|
||||
assert re.match(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{6}", captured.out.strip())
|
||||
assert captured.out.strip().endswith("test2")
|
||||
|
||||
verbose("test3", level=2)
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == ""
|
||||
|
||||
|
||||
def test_verbose_print_file():
|
||||
"""Test verbose with file"""
|
||||
set_verbose_level(1)
|
||||
stream = StringIO()
|
||||
verbose = verbose_print(1, False, False, file=stream)
|
||||
verbose("test")
|
||||
assert stream.getvalue().strip() == "test"
|
||||
|
||||
|
||||
def test_verbose_print_noop(capsys):
|
||||
"""Test verbose with noop"""
|
||||
set_verbose_level(1)
|
||||
verbose = verbose_print(0, False, False)
|
||||
verbose("test")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == ""
|
||||
|
||||
|
||||
def test_verbose(capsys):
|
||||
""" "Test verbose()"""
|
||||
# reset verbose module globals for testing
|
||||
_reset_verbose_globals()
|
||||
set_verbose_level(0)
|
||||
verbose("test")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == ""
|
||||
|
||||
set_verbose_level(1)
|
||||
verbose("test")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "test"
|
||||
|
||||
verbose("test2", level=2)
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == ""
|
||||
|
||||
set_verbose_level(2)
|
||||
verbose("test2", level=2)
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "test2"
|
||||
@@ -7,14 +7,29 @@ from osxphotos.debug import is_debug, set_debug
|
||||
|
||||
|
||||
def test_debug_enable():
|
||||
"""test set_debug()"""
|
||||
set_debug(True)
|
||||
logger = osxphotos._get_logger()
|
||||
assert logger.isEnabledFor(logging.DEBUG)
|
||||
assert osxphotos.logger.isEnabledFor(logging.DEBUG)
|
||||
assert is_debug()
|
||||
|
||||
|
||||
def test_debug_disable():
|
||||
"""test set_debug()"""
|
||||
set_debug(False)
|
||||
logger = osxphotos._get_logger()
|
||||
assert not logger.isEnabledFor(logging.DEBUG)
|
||||
assert not osxphotos.logger.isEnabledFor(logging.DEBUG)
|
||||
assert not is_debug()
|
||||
|
||||
|
||||
def test_debug_print_true(caplog):
|
||||
"""test debug()"""
|
||||
set_debug(True)
|
||||
logger = osxphotos.logger
|
||||
logger.debug("test debug")
|
||||
assert "test debug" in caplog.text
|
||||
|
||||
|
||||
def test_debug_print_false(caplog):
|
||||
set_debug(False)
|
||||
logger = osxphotos.logger
|
||||
logger.debug("test debug")
|
||||
assert caplog.text == ""
|
||||
|
||||
@@ -2,9 +2,9 @@ import os
|
||||
import pytest
|
||||
|
||||
from osxphotos._constants import _UNKNOWN_PERSON
|
||||
from osxphotos.utils import _get_os_version
|
||||
from osxphotos.utils import get_macos_version
|
||||
|
||||
OS_VERSION = _get_os_version()
|
||||
OS_VERSION = get_macos_version()
|
||||
SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "15"
|
||||
PHOTOS_DB = os.path.expanduser("~/Pictures/Photos Library.photoslibrary")
|
||||
pytestmark = pytest.mark.skipif(
|
||||
|
||||
@@ -14,9 +14,9 @@ import pytest
|
||||
import osxphotos
|
||||
from osxphotos._constants import _UNKNOWN_PERSON
|
||||
from osxphotos.photoexporter import PhotoExporter
|
||||
from osxphotos.utils import _get_os_version
|
||||
from osxphotos.utils import get_macos_version
|
||||
|
||||
OS_VERSION = _get_os_version()
|
||||
OS_VERSION = get_macos_version()
|
||||
# SKIP_TEST = "OSXPHOTOS_TEST_EXPORT" not in os.environ or OS_VERSION[1] != "17"
|
||||
SKIP_TEST = True # don't run any of the local library tests
|
||||
PHOTOS_DB_LOCAL = os.path.expanduser("~/Pictures/Photos Library.photoslibrary")
|
||||
|
||||
Reference in New Issue
Block a user