Added --preview-if-missing, #446

This commit is contained in:
Rhet Turnbull
2021-07-04 10:03:36 -07:00
parent 675371f0d7
commit 632169f277
11 changed files with 169 additions and 133 deletions

View File

@@ -787,7 +787,7 @@ def test_export_7(photosdb):
def test_export_8(photosdb):
# try to export missing file
# should raise exception
# should return empty list
import os
import os.path
import tempfile
@@ -796,11 +796,7 @@ def test_export_8(photosdb):
dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["missing"]])
filename = photos[0].filename
with pytest.raises(Exception) as e:
assert photos[0].export(dest)[0]
assert e.type == type(FileNotFoundError())
assert photos[0].export(dest) == []
def test_export_9(photosdb):

View File

@@ -866,17 +866,12 @@ def test_export_7(photosdb):
def test_export_8(photosdb):
# try to export missing file
# should raise exception
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["missing"]])
filename = photos[0].filename
with pytest.raises(Exception) as e:
assert photos[0].export(dest)[0]
assert e.type == type(FileNotFoundError())
assert photos[0].export(dest) == []
def test_export_9(photosdb):

View File

@@ -777,6 +777,12 @@ UUID_DUPLICATES = [
UUID_LOCATION = "D79B8D77-BFFC-460B-9312-034F2877D35B" # Pumkins2.jpg
UUID_NO_LOCATION = "6191423D-8DB8-4D4C-92BE-9BBBA308AAC4" # Tulips.jpg"
UUID_DICT_MISSING = {
"8E1D7BC9-9321-44F9-8CFB-4083F6B9232A": "IMG_2000.jpeg", # missing
"A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C": "Pumpkins4.jpeg", # missing
"D79B8D77-BFFC-460B-9312-034F2877D35B": "Pumkins2.jpg", # not missing
}
def modify_file(filename):
"""appends data to a file to modify it"""
@@ -1305,6 +1311,40 @@ def test_export_preview_suffix():
assert CLI_EXPORT_UUID_FILENAME_PREVIEW_TEMPLATE in files
def test_export_preview_if_missing():
"""test export with --preview_if_missing"""
import glob
import os
import os.path
import osxphotos
from osxphotos.cli import export
runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
uuid_options = []
for uuid in UUID_DICT_MISSING:
uuid_options.extend(["--uuid", uuid])
result = runner.invoke(
export,
[
os.path.join(cwd, CLI_PHOTOS_DB),
".",
"-V",
"--preview-if-missing",
"--preview-suffix",
"",
*uuid_options,
],
)
assert result.exit_code == 0
files = glob.glob("*")
expected_files = list(UUID_DICT_MISSING.values())
assert sorted(files) == sorted(expected_files)
def test_export_as_hardlink():
import glob
import os

View File

@@ -240,7 +240,6 @@ def test_export_7(photosdb):
def test_export_8(photosdb):
# try to export missing file
# should raise exception
import os
import os.path
import tempfile
@@ -249,12 +248,7 @@ def test_export_8(photosdb):
dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["missing"]])
filename = photos[0].filename
expected_dest = os.path.join(dest, filename)
with pytest.raises(Exception) as e:
assert photos[0].export(dest)
assert e.type == type(FileNotFoundError())
assert photos[0].export(dest) == []
def test_export_9(photosdb):

View File

@@ -211,7 +211,6 @@ def test_export_7(photosdb):
def test_export_8(photosdb):
# try to export missing file
# should raise exception
import os
import os.path
import tempfile
@@ -220,12 +219,7 @@ def test_export_8(photosdb):
dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["missing"]])
filename = photos[0].filename
expected_dest = os.path.join(dest, filename)
with pytest.raises(Exception) as e:
assert photos[0].export(dest)[0]
assert e.type == type(FileNotFoundError())
assert photos[0].export(dest) == []
def test_export_9(photosdb):

View File

@@ -863,17 +863,12 @@ def test_export_7(photosdb):
def test_export_8(photosdb):
# try to export missing file
# should raise exception
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
dest = tempdir.name
photos = photosdb.photos(uuid=[UUID_DICT["missing"]])
filename = photos[0].filename
with pytest.raises(Exception) as e:
assert photos[0].export(dest)[0]
assert e.type == type(FileNotFoundError())
assert photos[0].export(dest) == []
def test_export_9(photosdb):

View File

@@ -31,7 +31,7 @@ def test_dd_to_dms():
assert _dd_to_dms(-0.001) == (0, 0, -3.6)
@pytest.mark.skip(reason="Fails on some machines")
def test_get_system_library_path():
import osxphotos