Added --alt-copy method for #807 (#835)

This commit is contained in:
Rhet Turnbull
2022-11-14 21:42:02 -08:00
committed by GitHub
parent ea76297800
commit a727dc9294
4 changed files with 118 additions and 7 deletions

View File

@@ -1397,6 +1397,20 @@ def test_export():
assert sorted(files) == sorted(CLI_EXPORT_FILENAMES)
def test_export_alt_copy():
"""test basic export with --alt-copy"""
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), ".", "--alt-copy", "-V"]
)
assert result.exit_code == 0
files = glob.glob("*")
assert sorted(files) == sorted(CLI_EXPORT_FILENAMES)
def test_export_tmpdir():
"""test basic export with --tmpdir"""
runner = CliRunner()
@@ -4862,7 +4876,7 @@ def test_export_then_hardlink():
def test_export_dry_run():
"""test export with dry-run flag"""
"""test export with --dry-run flag"""
runner = CliRunner()
cwd = os.getcwd()
@@ -4881,6 +4895,27 @@ def test_export_dry_run():
assert not os.path.isfile(normalize_fs_path(filepath))
def test_export_dry_run_alt_copy():
"""test export with --dry-run flag and --alt-copy"""
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", "--alt-copy", "--dry-run"],
)
assert result.exit_code == 0
assert (
f"Processed: {PHOTOS_NOT_IN_TRASH_LEN_15_7} photos, exported: {PHOTOS_NOT_IN_TRASH_LEN_15_7+PHOTOS_EDITED_15_7}, missing: 3, error: 0"
in result.output
)
for filepath in CLI_EXPORT_FILENAMES_DRY_RUN:
assert re.search(r"Exported.*" + f"{re.escape(filepath)}", result.output)
assert not os.path.isfile(normalize_fs_path(filepath))
def test_export_update_edits_dry_run():
"""test export then update after removing and editing files with dry-run flag"""

View File

@@ -5,7 +5,7 @@ import pathlib
import pytest
from osxphotos.fileutil import FileUtil
from osxphotos.fileutil import FileUtil, FileUtilShUtil
TEST_HEIC = "tests/test-images/IMG_3092.heic"
TEST_RAW = "tests/test-images/DSC03584.dng"
@@ -38,6 +38,33 @@ def test_copy_file_invalid():
assert e.type == OSError
def test_copy_file_valid_shutil():
# copy file with valid src, dest with the shutil implementation
import os.path
import tempfile
from osxphotos.fileutil import FileUtil
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
src = "tests/test-images/wedding.jpg"
result = FileUtilShUtil.copy(src, temp_dir.name)
assert result
assert os.path.isfile(os.path.join(temp_dir.name, "wedding.jpg"))
def test_copy_file_invalid_shutil():
# copy file with invalid src with the shutil implementation
import tempfile
from osxphotos.fileutil import FileUtil
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
with pytest.raises(Exception) as e:
src = "tests/test-images/wedding_DOES_NOT_EXIST.jpg"
assert FileUtilShUtil.copy(src, temp_dir.name)
assert e.type == OSError
def test_hardlink_file_valid():
# hardlink file with valid src, dest
import os.path