Skip to content

Commit

Permalink
Added tests for post_function returns ExportResults
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Aug 6, 2023
1 parent 9f10bf8 commit 24766c2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/post_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def post_function(
# simulate doing some processing
new_filename = pathlib.Path(f"{filename}.new")
if new_filename.exists():
verbose(f"Skipping [filepath]{new_filename}[/] as it already exists")
verbose(f"Skipping file [filepath]{new_filename}[/] as it already exists")
post_results.user_skipped.append(new_filename)
else:
verbose(f"Writing [filepath]{new_filename}[/]")
verbose(f"Writing new file [filepath]{new_filename}[/]")
new_filename.touch()
post_results.user_written.append(new_filename)

Expand Down
53 changes: 52 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def _normalize_fs_paths(paths):
"pellentesque eu, pretium q.tif"
]

CLI_EXPORT_UUID = "D79B8D77-BFFC-460B-9312-034F2877D35B"
CLI_EXPORT_UUID = "D79B8D77-BFFC-460B-9312-034F2877D35B" # Pumkins2.jpg
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"
Expand Down Expand Up @@ -8862,6 +8862,57 @@ def test_export_post_function_bad_value():
assert "Could not load function" in result.output


def test_export_post_function_results():
"""Test --post-function with returned ExportResults, uses the post_function in examples/post_function.py"""

runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
tempdir = os.getcwd()
result = runner.invoke(
cli_main,
[
"export",
".",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--name",
"wedding",
"-V",
"--post-function",
f"{cwd}/examples/post_function.py::post_function",
],
)
assert result.exit_code == 0
assert "Writing new file" in result.output
export_files = glob.glob(os.path.join(f"{tempdir}", "*"))
assert os.path.join(tempdir, "wedding.jpg.new") in export_files

# run again with --update and --cleanup
result = runner.invoke(
cli_main,
[
"export",
".",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--name",
"wedding",
"-V",
"--post-function",
f"{cwd}/examples/post_function.py::post_function",
"--update",
"--cleanup",
],
)
assert result.exit_code == 0
assert "Skipping file" in result.output
assert "Deleted: 0 files" in result.output
export_files = glob.glob(os.path.join(f"{tempdir}", "*"))
assert os.path.join(tempdir, "wedding.jpg.new") in export_files


def test_export_directory_template_function():
"""Test --directory with template function"""

Expand Down

0 comments on commit 24766c2

Please sign in to comment.