Skip to content

Commit d7d0b96

Browse files
authored
Merge pull request #102 from Nautilus-Cyberneering/issue-101-fix-check-images-action-with-renaming
Fix #101: `check image changes` action fails with renamed files
2 parents 06becf8 + 83c11d2 commit d7d0b96

File tree

2 files changed

+89
-15
lines changed

2 files changed

+89
-15
lines changed

src/nautilus_librarian/mods/dvc/domain/utils.py

+31-10
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,20 @@ def extract_all_changed_files_from_dvc_diff(dvc_diff_json, only_basename=True):
4141
Output: ['data/000001/32/000001-32.600.2.tif']
4242
"""
4343
dvc_diff = DvcDiffParser.from_json(dvc_diff_json)
44-
all_files = dvc_diff.filter(only_basename=only_basename)
44+
all_files_except_renamed = dvc_diff.filter(
45+
exclude_added=False,
46+
exclude_modified=False,
47+
exclude_deleted=False,
48+
exclude_renamed=True,
49+
only_basename=only_basename,
50+
)
51+
52+
flat_renamed_files = extract_flat_list_of_renamed_files(dvc_diff_json)
53+
54+
all_files = all_files_except_renamed + flat_renamed_files
55+
4556
files = filter_media_library_files(all_files)
57+
4658
return files
4759

4860

@@ -153,20 +165,13 @@ def extract_renamed_files_from_dvc_diff(dvc_diff_json, only_basename=True):
153165
media_files = list(
154166
filter(lambda filename: is_a_library_file(filename["new"]), all_files)
155167
)
168+
156169
return media_files
157170

158171

159-
def extract_list_of_new_or_renamed_files_from_dvc_diff_output(dvc_diff_json):
172+
def extract_flat_list_of_renamed_files(dvc_diff_json):
160173
dvc_diff = DvcDiffParser.from_json(dvc_diff_json)
161174

162-
added_files = dvc_diff.filter(
163-
exclude_added=False,
164-
exclude_modified=True,
165-
exclude_deleted=True,
166-
exclude_renamed=True,
167-
only_basename=False,
168-
)
169-
170175
renamed_files = dvc_diff.filter(
171176
exclude_added=True,
172177
exclude_modified=True,
@@ -184,6 +189,22 @@ def extract_list_of_new_or_renamed_files_from_dvc_diff_output(dvc_diff_json):
184189

185190
flat_renamed_files = map(lambda file: file["new"], renamed_files)
186191

192+
return list(flat_renamed_files)
193+
194+
195+
def extract_list_of_new_or_renamed_files_from_dvc_diff_output(dvc_diff_json):
196+
dvc_diff = DvcDiffParser.from_json(dvc_diff_json)
197+
198+
added_files = dvc_diff.filter(
199+
exclude_added=False,
200+
exclude_modified=True,
201+
exclude_deleted=True,
202+
exclude_renamed=True,
203+
only_basename=False,
204+
)
205+
206+
flat_renamed_files = extract_flat_list_of_renamed_files(dvc_diff_json)
207+
187208
all_files = added_files + list(flat_renamed_files)
188209

189210
files = filter_media_library_files(all_files)

tests/test_nautilus_librarian/test_typer/test_commands/test_workflows/test_actions/test_check_images_changes.py

+58-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
)
77

88

9-
def given_a_diff_structure_with_no_changes_it_should_return_an_exit_result_code():
9+
def given_an_empty_dvc_diff_it_should_exit():
10+
11+
dvc_diff_with_added_gold_image = {}
12+
13+
result = check_images_changes(compact_json(dvc_diff_with_added_gold_image))
14+
15+
assert result.code == ResultCode.EXIT
16+
17+
18+
def given_a_diff_structure_with_no_changes_it_should_exit():
1019

1120
dvc_diff_with_added_gold_image = {
1221
"added": [],
@@ -20,16 +29,23 @@ def given_a_diff_structure_with_no_changes_it_should_return_an_exit_result_code(
2029
assert result.code == ResultCode.EXIT
2130

2231

23-
def given_an_empty_structure_it_should_return_an_exit_result_code():
32+
def given_a_diff_structure_with_added_files_it_should_continue():
2433

25-
dvc_diff_with_added_gold_image = {}
34+
dvc_diff_with_added_gold_image = {
35+
"added": [
36+
{"path": "data/000001/52/000001-52.600.2.tif"},
37+
],
38+
"deleted": [],
39+
"modified": [],
40+
"renamed": [],
41+
}
2642

2743
result = check_images_changes(compact_json(dvc_diff_with_added_gold_image))
2844

29-
assert result.code == ResultCode.EXIT
45+
assert result.code == ResultCode.CONTINUE
3046

3147

32-
def given_a_diff_structure_with_changes_it_should_return_an_continue_result_code():
48+
def given_a_diff_structure_with_deleted_files_it_should_continue():
3349

3450
dvc_diff_with_added_gold_image = {
3551
"added": [],
@@ -43,3 +59,40 @@ def given_a_diff_structure_with_changes_it_should_return_an_continue_result_code
4359
result = check_images_changes(compact_json(dvc_diff_with_added_gold_image))
4460

4561
assert result.code == ResultCode.CONTINUE
62+
63+
64+
def given_a_diff_structure_with_modified_files_it_should_continue():
65+
66+
dvc_diff_with_added_gold_image = {
67+
"added": [],
68+
"deleted": [],
69+
"modified": [
70+
{"path": "data/000001/52/000001-52.600.2.tif"},
71+
],
72+
"renamed": [],
73+
}
74+
75+
result = check_images_changes(compact_json(dvc_diff_with_added_gold_image))
76+
77+
assert result.code == ResultCode.CONTINUE
78+
79+
80+
def given_a_diff_structure_with_renamed_files_it_should_continue():
81+
82+
dvc_diff_with_added_gold_image = {
83+
"added": [],
84+
"deleted": [],
85+
"modified": [],
86+
"renamed": [
87+
{
88+
"path": {
89+
"old": "data/000001/32/000001-32.600.2.tif",
90+
"new": "data/000002/32/000002-32.600.2.tif",
91+
}
92+
}
93+
],
94+
}
95+
96+
result = check_images_changes(compact_json(dvc_diff_with_added_gold_image))
97+
98+
assert result.code == ResultCode.CONTINUE

0 commit comments

Comments
 (0)