Skip to content

Commit

Permalink
Merge pull request #102 from Nautilus-Cyberneering/issue-101-fix-chec…
Browse files Browse the repository at this point in the history
…k-images-action-with-renaming

Fix #101: `check image changes` action fails with renamed files
  • Loading branch information
josecelano authored Mar 2, 2022
2 parents 06becf8 + 83c11d2 commit d7d0b96
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 15 deletions.
41 changes: 31 additions & 10 deletions src/nautilus_librarian/mods/dvc/domain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand All @@ -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": [],
Expand All @@ -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

0 comments on commit d7d0b96

Please sign in to comment.