Fix for #516
This commit is contained in:
@@ -479,6 +479,7 @@ CLI_EXPORT_UUID = "D79B8D77-BFFC-460B-9312-034F2877D35B"
|
||||
CLI_EXPORT_UUID_STATUE = "3DD2C897-F19E-4CA6-8C22-B027D5A71907"
|
||||
CLI_EXPORT_UUID_KEYWORD_PATHSEP = "7783E8E6-9CAC-40F3-BE22-81FB7051C266"
|
||||
CLI_EXPORT_UUID_LONG_DESCRIPTION = "8846E3E6-8AC8-4857-8448-E3D025784410"
|
||||
CLI_EXPORT_UUID_MISSING = "8E1D7BC9-9321-44F9-8CFB-4083F6B9232A" # IMG_2000.JPG
|
||||
|
||||
CLI_EXPORT_UUID_FILENAME = "Pumkins2.jpg"
|
||||
CLI_EXPORT_UUID_FILENAME_PREVIEW = "Pumkins2_preview.jpeg"
|
||||
@@ -1375,6 +1376,48 @@ def test_export_preview():
|
||||
assert CLI_EXPORT_UUID_FILENAME_PREVIEW in files
|
||||
|
||||
|
||||
def test_export_preview_file_exists():
|
||||
"""test export with --preview when preview images already exist, issue #516"""
|
||||
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():
|
||||
result = runner.invoke(
|
||||
export,
|
||||
[
|
||||
os.path.join(cwd, CLI_PHOTOS_DB),
|
||||
".",
|
||||
"-V",
|
||||
"--preview",
|
||||
"--uuid",
|
||||
CLI_EXPORT_UUID_MISSING,
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
|
||||
# export again
|
||||
result = runner.invoke(
|
||||
export,
|
||||
[
|
||||
os.path.join(cwd, CLI_PHOTOS_DB),
|
||||
".",
|
||||
"-V",
|
||||
"--preview",
|
||||
"--uuid",
|
||||
CLI_EXPORT_UUID_MISSING,
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert "Error exporting photo" not in result.output
|
||||
|
||||
|
||||
def test_export_preview_suffix():
|
||||
"""test export with --preview and --preview-suffix"""
|
||||
import glob
|
||||
@@ -4993,7 +5036,10 @@ def test_export_touch_files_update():
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert f"updated: 1, skipped: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7-1}" 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):
|
||||
|
||||
@@ -8,18 +8,20 @@ UTI_DICT = {"public.jpeg": "jpeg", "com.canon.cr2-raw-image": "cr2"}
|
||||
|
||||
|
||||
def test_debug_enable():
|
||||
import osxphotos
|
||||
import logging
|
||||
|
||||
import osxphotos
|
||||
|
||||
osxphotos._set_debug(True)
|
||||
logger = osxphotos._get_logger()
|
||||
assert logger.isEnabledFor(logging.DEBUG)
|
||||
|
||||
|
||||
def test_debug_disable():
|
||||
import osxphotos
|
||||
import logging
|
||||
|
||||
import osxphotos
|
||||
|
||||
osxphotos._set_debug(False)
|
||||
logger = osxphotos._get_logger()
|
||||
assert not logger.isEnabledFor(logging.DEBUG)
|
||||
@@ -31,6 +33,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
|
||||
@@ -54,9 +57,11 @@ def test_db_is_locked_unlocked():
|
||||
|
||||
assert not osxphotos.utils._db_is_locked(DB_UNLOCKED_10_15)
|
||||
|
||||
|
||||
def test_findfiles():
|
||||
import tempfile
|
||||
import os.path
|
||||
import tempfile
|
||||
|
||||
from osxphotos.utils import findfiles
|
||||
|
||||
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
@@ -72,9 +77,48 @@ def test_findfiles():
|
||||
|
||||
def test_findfiles_invalid_dir():
|
||||
import tempfile
|
||||
import os.path
|
||||
|
||||
from osxphotos.utils import findfiles
|
||||
|
||||
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
files = findfiles("*.jpg", f"{temp_dir.name}/no_such_dir" )
|
||||
files = findfiles("*.jpg", f"{temp_dir.name}/no_such_dir")
|
||||
assert len(files) == 0
|
||||
|
||||
|
||||
def test_increment_filename():
|
||||
# test that increment_filename works
|
||||
import pathlib
|
||||
import tempfile
|
||||
|
||||
from osxphotos.utils import increment_filename, increment_filename_with_count
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="osxphotos_") as temp_dir:
|
||||
temp_dir = pathlib.Path(temp_dir)
|
||||
filename = str(temp_dir / "file.jpg")
|
||||
assert increment_filename(filename) == str(temp_dir / "file.jpg")
|
||||
|
||||
new_file = temp_dir / "file.jpg"
|
||||
new_file.touch()
|
||||
assert increment_filename(filename) == str(temp_dir / "file (1).jpg")
|
||||
|
||||
# test pathlib.Path as argument
|
||||
assert increment_filename(pathlib.Path(filename)) == str(
|
||||
temp_dir / "file (1).jpg"
|
||||
)
|
||||
|
||||
new_file = temp_dir / "file (1).jpg"
|
||||
new_file.touch()
|
||||
assert increment_filename(filename) == str(temp_dir / "file (2).jpg")
|
||||
|
||||
# test increment_filename_with_count
|
||||
filename = str(temp_dir / "file2.jpg")
|
||||
assert increment_filename_with_count(filename, count=2) == (
|
||||
str(temp_dir / "file2 (2).jpg"),
|
||||
2,
|
||||
)
|
||||
new_file = temp_dir / "file2 (2).jpg"
|
||||
new_file.touch()
|
||||
assert increment_filename_with_count(filename, count=2) == (
|
||||
str(temp_dir / "file2 (3).jpg"),
|
||||
3,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user