From 2e32d62237f59b16a9be422104347d6a1332865c Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sun, 4 Jul 2021 12:25:24 -0700 Subject: [PATCH] Added test for try/except block in cli export --- tests/test_cli.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index ebe15ba1..d9dd7ee4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3859,6 +3859,31 @@ def test_export_deleted_only_2(): assert len(files) == PHOTOS_IN_TRASH_LEN_14_6 +def test_export_error(monkeypatch): + """Test that export catches errors thrown by export2""" + # Note: I often comment out the try/except block in cli.py::export_photo_with_template when + # debugging to see exactly where the error is + # this test verifies I've re-enabled that code + import osxphotos + from osxphotos.cli import export + + runner = CliRunner() + cwd = os.getcwd() + # pylint: disable=not-context-manager + + def throw_error(*args, **kwargs): + raise ValueError("Argh!") + + monkeypatch.setattr(osxphotos.PhotoInfo, "export2", throw_error) + with runner.isolated_filesystem(): + result = runner.invoke( + export, + [os.path.join(cwd, PHOTOS_DB_15_7), ".", "-V", "--uuid", CLI_EXPORT_UUID], + ) + assert result.exit_code == 0 + assert "Error exporting" in result.output + + def test_places(): import json import os