diff --git a/src/nautilus_librarian/mods/dvc/domain/utils.py b/src/nautilus_librarian/mods/dvc/domain/utils.py index ad8b5ff..1ba02f2 100644 --- a/src/nautilus_librarian/mods/dvc/domain/utils.py +++ b/src/nautilus_librarian/mods/dvc/domain/utils.py @@ -41,8 +41,20 @@ def extract_all_changed_files_from_dvc_diff(dvc_diff_json, only_basename=True): Output: ['data/000001/32/000001-32.600.2.tif'] """ dvc_diff = DvcDiffParser.from_json(dvc_diff_json) - all_files = dvc_diff.filter(only_basename=only_basename) + all_files_except_renamed = dvc_diff.filter( + exclude_added=False, + exclude_modified=False, + exclude_deleted=False, + exclude_renamed=True, + only_basename=only_basename, + ) + + flat_renamed_files = extract_flat_list_of_renamed_files(dvc_diff_json) + + all_files = all_files_except_renamed + flat_renamed_files + files = filter_media_library_files(all_files) + return files @@ -153,20 +165,13 @@ def extract_renamed_files_from_dvc_diff(dvc_diff_json, only_basename=True): media_files = list( filter(lambda filename: is_a_library_file(filename["new"]), all_files) ) + return media_files -def extract_list_of_new_or_renamed_files_from_dvc_diff_output(dvc_diff_json): +def extract_flat_list_of_renamed_files(dvc_diff_json): dvc_diff = DvcDiffParser.from_json(dvc_diff_json) - added_files = dvc_diff.filter( - exclude_added=False, - exclude_modified=True, - exclude_deleted=True, - exclude_renamed=True, - only_basename=False, - ) - renamed_files = dvc_diff.filter( exclude_added=True, exclude_modified=True, @@ -184,6 +189,22 @@ def extract_list_of_new_or_renamed_files_from_dvc_diff_output(dvc_diff_json): flat_renamed_files = map(lambda file: file["new"], renamed_files) + return list(flat_renamed_files) + + +def extract_list_of_new_or_renamed_files_from_dvc_diff_output(dvc_diff_json): + dvc_diff = DvcDiffParser.from_json(dvc_diff_json) + + added_files = dvc_diff.filter( + exclude_added=False, + exclude_modified=True, + exclude_deleted=True, + exclude_renamed=True, + only_basename=False, + ) + + flat_renamed_files = extract_flat_list_of_renamed_files(dvc_diff_json) + all_files = added_files + list(flat_renamed_files) files = filter_media_library_files(all_files) diff --git a/tests/test_nautilus_librarian/test_typer/test_commands/test_workflows/test_actions/test_check_images_changes.py b/tests/test_nautilus_librarian/test_typer/test_commands/test_workflows/test_actions/test_check_images_changes.py index 35e033d..b48d6c1 100644 --- a/tests/test_nautilus_librarian/test_typer/test_commands/test_workflows/test_actions/test_check_images_changes.py +++ b/tests/test_nautilus_librarian/test_typer/test_commands/test_workflows/test_actions/test_check_images_changes.py @@ -6,7 +6,16 @@ ) -def given_a_diff_structure_with_no_changes_it_should_return_an_exit_result_code(): +def given_an_empty_dvc_diff_it_should_exit(): + + dvc_diff_with_added_gold_image = {} + + result = check_images_changes(compact_json(dvc_diff_with_added_gold_image)) + + assert result.code == ResultCode.EXIT + + +def given_a_diff_structure_with_no_changes_it_should_exit(): dvc_diff_with_added_gold_image = { "added": [], @@ -20,16 +29,23 @@ def given_a_diff_structure_with_no_changes_it_should_return_an_exit_result_code( assert result.code == ResultCode.EXIT -def given_an_empty_structure_it_should_return_an_exit_result_code(): +def given_a_diff_structure_with_added_files_it_should_continue(): - dvc_diff_with_added_gold_image = {} + dvc_diff_with_added_gold_image = { + "added": [ + {"path": "data/000001/52/000001-52.600.2.tif"}, + ], + "deleted": [], + "modified": [], + "renamed": [], + } result = check_images_changes(compact_json(dvc_diff_with_added_gold_image)) - assert result.code == ResultCode.EXIT + assert result.code == ResultCode.CONTINUE -def given_a_diff_structure_with_changes_it_should_return_an_continue_result_code(): +def given_a_diff_structure_with_deleted_files_it_should_continue(): dvc_diff_with_added_gold_image = { "added": [], @@ -43,3 +59,40 @@ def given_a_diff_structure_with_changes_it_should_return_an_continue_result_code result = check_images_changes(compact_json(dvc_diff_with_added_gold_image)) assert result.code == ResultCode.CONTINUE + + +def given_a_diff_structure_with_modified_files_it_should_continue(): + + dvc_diff_with_added_gold_image = { + "added": [], + "deleted": [], + "modified": [ + {"path": "data/000001/52/000001-52.600.2.tif"}, + ], + "renamed": [], + } + + result = check_images_changes(compact_json(dvc_diff_with_added_gold_image)) + + assert result.code == ResultCode.CONTINUE + + +def given_a_diff_structure_with_renamed_files_it_should_continue(): + + dvc_diff_with_added_gold_image = { + "added": [], + "deleted": [], + "modified": [], + "renamed": [ + { + "path": { + "old": "data/000001/32/000001-32.600.2.tif", + "new": "data/000002/32/000002-32.600.2.tif", + } + } + ], + } + + result = check_images_changes(compact_json(dvc_diff_with_added_gold_image)) + + assert result.code == ResultCode.CONTINUE