Skip to content

Commit 7871bce

Browse files
authored
Merge pull request #93 from Nautilus-Cyberneering/issue-92
New Base image purpose code (52)
2 parents a636117 + 5b75e64 commit 7871bce

23 files changed

+72
-70
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ def get_files_to_commit(self, base_img_relative_path) -> List[str]:
125125
126126
For example:
127127
128-
For the Base image "data/000001/42/000001-42.600.2.tif", these are
128+
For the Base image "data/000001/52/000001-52.600.2.tif", these are
129129
the files tracked on the git repo:
130130
131-
- data/000001/42/.gitignore
132-
- data/000001/42/000001-42.600.2.tif.dvc
131+
- data/000001/52/.gitignore
132+
- data/000001/52/000001-52.600.2.tif.dvc
133133
"""
134134
base_img_dir = os.path.dirname(base_img_relative_path)
135135

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def extract_added_files_from_dvc_diff(dvc_diff_json):
151151
{
152152
"added": [
153153
{"path": "data/000001/32/000001-32.600.2.tif"},
154-
{"path": "data/000001/42/000001-42.600.2.tif"},
154+
{"path": "data/000001/52/000001-52.600.2.tif"},
155155
],
156156
"deleted": [],
157157
"modified": [],

src/nautilus_librarian/mods/namecodes/domain/filename.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ class PurposeCode(Enum):
66
GOLD_INDEX = 30
77
GOLD_METADATA = 31
88
GOLD_IMAGE = 32
9-
BASE_INDEX = 40
10-
BASE_METADATA = 41
11-
BASE_IMAGE = 42
9+
BASE_INDEX = 50
10+
BASE_METADATA = 51
11+
BASE_IMAGE = 52
1212

1313
def __str__(self):
1414
return "%s" % self.value

src/nautilus_librarian/mods/namecodes/domain/validate_filenames.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ def validate_artwork_id(artwork_id):
2828
def validate_purpose_code(purpose_code):
2929
if purpose_code == "":
3030
raise FilenameException(
31-
"Missing purpose code. Purpose code should be: 32 or 42"
31+
"Missing purpose code. Purpose code should be: 32 (Gold) or 52 (Base)"
32+
)
33+
if int(purpose_code) not in [32, 52]:
34+
raise FilenameException(
35+
"Wrong purpose code. Purpose code should be: 32 (Gold) or 52 (Base)"
3236
)
33-
if int(purpose_code) not in [32, 42]:
34-
raise FilenameException("Wrong purpose code. Purpose code should be: 32 or 42")
3537

3638

3739
def validate_transformation_code(transformation_code):

src/nautilus_librarian/mods/namecodes/typer/commands.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def validate_filename_command(filename: str):
2222
2323
More information about the specification on: https://github.com/da2ce7/nautilus-namecodes.
2424
25-
Filename examples: 000000-32.600.2.tif, 000001-42.600.2.tif.
25+
Filename examples: 000000-32.600.2.tif, 000001-52.600.2.tif.
2626
2727
EXAMPLES:
2828

tests/test_nautilus_librarian/test_domain/test_file_locator.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ def test_gold_image_localization():
1414

1515

1616
def test_base_image_localization():
17-
gold_image_filename = Filename("000001-42.600.2.tif")
17+
gold_image_filename = Filename("000001-52.600.2.tif")
1818

1919
folder = file_locator(gold_image_filename)
2020

21-
assert folder == "data/000001/42"
21+
assert folder == "data/000001/52"
2222

2323

2424
def it_should_return_the_corresponding_base_image_filename_from_the_gold_image():
2525
gold_image_filename = Filename("000001-32.600.2.tif")
2626

2727
base_image_filename = get_base_image_filename_from_gold_image(gold_image_filename)
2828

29-
assert base_image_filename == Filename("000001-42.600.2.tif")
29+
assert base_image_filename == Filename("000001-52.600.2.tif")

tests/test_nautilus_librarian/test_domain/test_validate_filepaths.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ def test_valid_folder_for_gold_image():
1111

1212

1313
def test_valid_folder_for_base_image():
14-
validate_filepath("data/000001/42/000001-42.600.2.tif")
14+
validate_filepath("data/000001/52/000001-52.600.2.tif")
1515

1616

1717
def test_invalid_folder_for_gold_image():
1818
with pytest.raises(InvalidImageFolderException):
19-
validate_filepath("data/000001/42/000001-32.600.2.tif")
19+
validate_filepath("data/000001/52/000001-32.600.2.tif")
2020

2121

2222
def test_invalid_folder_for_base_image():
2323
with pytest.raises(InvalidImageFolderException):
24-
validate_filepath("data/000001/32/000001-42.600.2.tif")
24+
validate_filepath("data/000001/32/000001-52.600.2.tif")

tests/test_nautilus_librarian/test_mods/test_dvc/test_domain/test_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ def test_files_to_commit(temp_dvc_dir_with_test_content):
147147

148148
api = DvcApiWrapper(temp_dvc_dir_with_test_content)
149149

150-
filepaths = api.get_files_to_commit("data/000001/42/000001-42.600.2.tif")
150+
filepaths = api.get_files_to_commit("data/000001/52/000001-52.600.2.tif")
151151

152152
assert filepaths == [
153-
"data/000001/42/.gitignore",
154-
"data/000001/42/000001-42.600.2.tif.dvc",
153+
"data/000001/52/.gitignore",
154+
"data/000001/52/000001-52.600.2.tif.dvc",
155155
]
156156

157157

tests/test_nautilus_librarian/test_mods/test_dvc/test_domain/test_dvc_services_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def test_files_to_commit(temp_dvc_dir_with_librarian_test_content):
116116

117117
api = DvcServicesApi(temp_dvc_dir_with_librarian_test_content)
118118

119-
filepaths = api.get_files_to_commit("data/000001/42/000001-42.600.2.tif")
119+
filepaths = api.get_files_to_commit("data/000001/52/000001-52.600.2.tif")
120120

121121
assert filepaths == [
122-
"data/000001/42/.gitignore",
123-
"data/000001/42/000001-42.600.2.tif.dvc",
122+
"data/000001/52/.gitignore",
123+
"data/000001/52/000001-52.600.2.tif.dvc",
124124
]

tests/test_nautilus_librarian/test_mods/test_dvc/test_domain/test_utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_extract_added_files_from_dvc_diff():
3232
dvc_diff = {
3333
"added": [
3434
{"path": "data/000001/32/000001-32.600.2.tif"},
35-
{"path": "data/000001/42/000001-42.600.2.tif"},
35+
{"path": "data/000001/52/000001-52.600.2.tif"},
3636
],
3737
"deleted": [],
3838
"modified": [],
@@ -43,7 +43,7 @@ def test_extract_added_files_from_dvc_diff():
4343

4444
assert result == [
4545
"data/000001/32/000001-32.600.2.tif",
46-
"data/000001/42/000001-42.600.2.tif",
46+
"data/000001/52/000001-52.600.2.tif",
4747
]
4848

4949

@@ -54,7 +54,7 @@ def test_modified_files_from_dvc_diff():
5454
"deleted": [],
5555
"modified": [
5656
{"path": "data/000001/32/000001-32.600.2.tif"},
57-
{"path": "data/000001/42/000001-42.600.2.tif"},
57+
{"path": "data/000001/52/000001-52.600.2.tif"},
5858
],
5959
"renamed": [],
6060
}
@@ -63,7 +63,7 @@ def test_modified_files_from_dvc_diff():
6363

6464
assert result == [
6565
"000001-32.600.2.tif",
66-
"000001-42.600.2.tif",
66+
"000001-52.600.2.tif",
6767
]
6868

6969

@@ -72,7 +72,7 @@ def test_extract_deleted_files_from_dvc_diff():
7272
dvc_diff = {
7373
"deleted": [
7474
{"path": "data/000001/32/000001-32.600.2.tif"},
75-
{"path": "data/000001/42/000001-42.600.2.tif"},
75+
{"path": "data/000001/52/000001-52.600.2.tif"},
7676
],
7777
"added": [],
7878
"modified": [],
@@ -85,7 +85,7 @@ def test_extract_deleted_files_from_dvc_diff():
8585

8686
assert result == [
8787
"data/000001/32/000001-32.600.2.tif",
88-
"data/000001/42/000001-42.600.2.tif",
88+
"data/000001/52/000001-52.600.2.tif",
8989
]
9090

9191

tests/test_nautilus_librarian/test_mods/test_namecodes/test_domain/test_filename.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_base_image_instantiation_from_gold_image():
2626

2727
base_image = gold_image_filename.generate_base_image_filename()
2828

29-
assert str(base_image) == str(Filename("000001-42.600.2.tif"))
29+
assert str(base_image) == str(Filename("000001-52.600.2.tif"))
3030

3131

3232
def test_invalid_filename():

tests/test_nautilus_librarian/test_mods/test_namecodes/test_domain/test_filename_filters.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_filter_gold_images_from_file_list():
6262

6363
original_file_list = [
6464
"data/000001/32/000001-32.600.2.tif",
65-
"data/000001/42/000001-42.600.2.tif",
65+
"data/000001/52/000001-52.600.2.tif",
6666
]
6767

6868
filtered_file_list = filter_gold_images(original_file_list)
@@ -76,11 +76,11 @@ def test_filter_base_images_from_file_list():
7676

7777
original_file_list = [
7878
"data/000001/32/000001-32.600.2.tif",
79-
"data/000001/42/000001-42.600.2.tif",
79+
"data/000001/52/000001-52.600.2.tif",
8080
]
8181

8282
filtered_file_list = filter_base_images(original_file_list)
8383

84-
expected_file_list = ["data/000001/42/000001-42.600.2.tif"]
84+
expected_file_list = ["data/000001/52/000001-52.600.2.tif"]
8585

8686
assert filtered_file_list == expected_file_list

tests/test_nautilus_librarian/test_mods/test_namecodes/test_domain/test_validate_filenames.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_invalid_artwork_id(filename):
2222
validate_filename(filename)
2323

2424

25-
@pytest.mark.parametrize("filename", [("000001-32.600.2.tif"), ("000001-42.600.2.tif")])
25+
@pytest.mark.parametrize("filename", [("000001-32.600.2.tif"), ("000001-52.600.2.tif")])
2626
def test_valid_purpose_code(filename):
2727
validate_filename(filename)
2828

tests/test_nautilus_librarian/test_typer/test_commands/test_workflows/fixtures/workflows_fixtures.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def sample_gold_image_relative_path():
3535

3636
@pytest.fixture(scope="session")
3737
def sample_base_image_absolute_path(workflows_fixtures_dir):
38-
base_image_path = f"{workflows_fixtures_dir}/images/000001-42.600.2.tif"
38+
base_image_path = f"{workflows_fixtures_dir}/images/000001-52.600.2.tif"
3939
return base_image_path
4040

4141

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

+22-22
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_get_new_gold_images_from_dvc_diff():
2323
dvc_diff = {
2424
"added": [
2525
{"path": "data/000001/32/000001-32.600.2.tif"},
26-
{"path": "data/000001/42/000001-42.600.2.tif"},
26+
{"path": "data/000001/52/000001-52.600.2.tif"},
2727
],
2828
"deleted": [],
2929
"modified": [],
@@ -44,28 +44,28 @@ def test_calculate_the_corresponding_base_image_from_gold_image():
4444
)
4545

4646
assert base_image_path == (
47-
"data/000001/42/000001-42.600.2.tif", # relative path
48-
"/home/repo/data/000001/42/000001-42.600.2.tif", # absolute path
47+
"data/000001/52/000001-52.600.2.tif", # relative path
48+
"/home/repo/data/000001/52/000001-52.600.2.tif", # absolute path
4949
)
5050

5151

5252
def remove_base_image_dvc_files(temp_git_dir):
53-
os.remove(f"{temp_git_dir}/data/000001/42/000001-42.600.2.tif.dvc")
54-
os.remove(f"{temp_git_dir}/data/000001/42/.gitignore")
53+
os.remove(f"{temp_git_dir}/data/000001/52/000001-52.600.2.tif.dvc")
54+
os.remove(f"{temp_git_dir}/data/000001/52/.gitignore")
5555

5656

5757
def overwrite_base_image(fixtures_dir, temp_git_dir):
5858
shutil.copyfile(
59-
f"{fixtures_dir}/images/000001-42.600.2-modified.tif",
60-
f"{temp_git_dir}/data/000001/42/000001-42.600.2.tif",
59+
f"{fixtures_dir}/images/000001-52.600.2-modified.tif",
60+
f"{temp_git_dir}/data/000001/52/000001-52.600.2.tif",
6161
)
6262

6363

6464
def rename_base_image(temp_git_dir):
6565
execute_shell_command(
6666
"""
67-
mkdir -p data/000002/42
68-
dvc move data/000001/42/000001-42.600.2.tif data/000002/42/000002-42.600.2.tif
67+
mkdir -p data/000002/52
68+
dvc move data/000001/52/000001-52.600.2.tif data/000002/52/000002-52.600.2.tif
6969
""",
7070
cwd=temp_git_dir,
7171
print_output=True,
@@ -75,7 +75,7 @@ def rename_base_image(temp_git_dir):
7575
def add_base_image_to_dvc(temp_git_dir):
7676
execute_shell_command(
7777
"""
78-
dvc add data/000001/42/000001-42.600.2.tif
78+
dvc add data/000001/52/000001-52.600.2.tif
7979
""",
8080
cwd=temp_git_dir,
8181
print_output=True,
@@ -145,12 +145,12 @@ def given_a_dvc_diff_object_with_a_new_gold_image_it_should_commit_the_added_bas
145145
repo = Repo(temp_git_dir)
146146
commit = repo.commit(repo.heads[0].commit) # latest commit on the branch
147147

148-
assert_commit_summary(commit, "feat: new base image: 000001-42.600.2.tif")
148+
assert_commit_summary(commit, "feat: new base image: 000001-52.600.2.tif")
149149

150150
# Assert the commit contains the right files
151151
expected_commit_stats_files = {
152-
"data/000001/42/.gitignore": {"insertions": 1, "deletions": 0, "lines": 1},
153-
"data/000001/42/000001-42.600.2.tif.dvc": {
152+
"data/000001/52/.gitignore": {"insertions": 1, "deletions": 0, "lines": 1},
153+
"data/000001/52/000001-52.600.2.tif.dvc": {
154154
"insertions": 4,
155155
"deletions": 0,
156156
"lines": 4,
@@ -201,11 +201,11 @@ def given_a_dvc_diff_object_with_a_gold_image_deleton_it_should_commit_the_base_
201201
repo = Repo(temp_git_dir)
202202
commit = repo.commit(repo.heads[0].commit) # latest commit on the branch
203203

204-
assert_commit_summary(commit, "feat: deleted base image: 000001-42.600.2.tif")
204+
assert_commit_summary(commit, "feat: deleted base image: 000001-52.600.2.tif")
205205

206206
expected_commit_stats_files = {
207-
"data/000001/42/.gitignore": {"insertions": 0, "deletions": 1, "lines": 1},
208-
"data/000001/42/000001-42.600.2.tif.dvc": {
207+
"data/000001/52/.gitignore": {"insertions": 0, "deletions": 1, "lines": 1},
208+
"data/000001/52/000001-52.600.2.tif.dvc": {
209209
"insertions": 0,
210210
"deletions": 4,
211211
"lines": 4,
@@ -257,16 +257,16 @@ def given_a_dvc_diff_object_with_a_gold_image_rename_it_should_commit_the_base_i
257257
commit = repo.commit(repo.heads[0].commit)
258258

259259
expected_commit_stats_files = {
260-
"data/000001/42/.gitignore": {"insertions": 0, "deletions": 1, "lines": 1},
261-
"data/000002/42/.gitignore": {"insertions": 3, "deletions": 0, "lines": 3},
262-
"data/{000001/42/000001-42.600.2.tif.dvc => 000002/42/000002-42.600.2.tif.dvc}": {
260+
"data/000001/52/.gitignore": {"insertions": 0, "deletions": 1, "lines": 1},
261+
"data/000002/52/.gitignore": {"insertions": 3, "deletions": 0, "lines": 3},
262+
"data/{000001/52/000001-52.600.2.tif.dvc => 000002/52/000002-52.600.2.tif.dvc}": {
263263
"insertions": 1,
264264
"deletions": 1,
265265
"lines": 2,
266266
},
267267
}
268268
assert_commit_summary(
269-
commit, "feat: renamed base image: 000001-42.600.2.tif -> 000002-42.600.2.tif"
269+
commit, "feat: renamed base image: 000001-52.600.2.tif -> 000002-52.600.2.tif"
270270
)
271271
assert_commit_content(commit, expected_commit_stats_files, git_user)
272272
assert_commit_signingkey(commit, temp_git_dir, git_user)
@@ -309,10 +309,10 @@ def given_a_dvc_diff_object_with_a_gold_image_modification_it_should_commit_the_
309309

310310
commit = repo.commit(repo.heads[0].commit)
311311

312-
assert_commit_summary(commit, "feat: modified base image: 000001-42.600.2.tif")
312+
assert_commit_summary(commit, "feat: modified base image: 000001-52.600.2.tif")
313313

314314
expected_commit_stats_files = {
315-
"data/000001/42/000001-42.600.2.tif.dvc": {
315+
"data/000001/52/000001-52.600.2.tif.dvc": {
316316
"insertions": 2,
317317
"deletions": 2,
318318
"lines": 4,

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ def given_a_diff_structure_with_deleted_gold_image_it_should_delete_base_images(
4848
execute_shell_command(
4949
"""
5050
ls -la
51-
dvc add data/000001/42/000001-42.600.2.tif
51+
dvc add data/000001/52/000001-52.600.2.tif
5252
""",
5353
cwd=temp_git_dir,
5454
)
5555

56-
assert path.exists(f"{temp_git_dir}/data/000001/42/000001-42.600.2.tif.dvc")
56+
assert path.exists(f"{temp_git_dir}/data/000001/52/000001-52.600.2.tif.dvc")
5757

5858
result = delete_base_images(
5959
compact_json(dvc_diff_with_added_gold_image), temp_git_dir
6060
)
6161

6262
assert result.code == ResultCode.CONTINUE
63-
assert not path.exists(f"{temp_git_dir}/data/000001/42/000001-42.600.2.tif.dvc")
63+
assert not path.exists(f"{temp_git_dir}/data/000001/52/000001-52.600.2.tif.dvc")
6464
assert result.contains_text("successfully deleted")

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ def given_a_diff_structure_with_added_gold_image_it_should_generate_base_image(
5252
)
5353

5454
# Assert Base image was created
55-
assert os.path.isfile(f"{temp_git_dir}/data/000001/42/000001-42.600.2.tif")
55+
assert os.path.isfile(f"{temp_git_dir}/data/000001/52/000001-52.600.2.tif")
5656

5757
# DVC Asserts
5858

5959
# Assert dvc files were created
60-
assert os.path.isfile(f"{temp_git_dir}/data/000001/42/000001-42.600.2.tif.dvc")
61-
assert os.path.isfile(f"{temp_git_dir}/data/000001/42/.gitignore")
60+
assert os.path.isfile(f"{temp_git_dir}/data/000001/52/000001-52.600.2.tif.dvc")
61+
assert os.path.isfile(f"{temp_git_dir}/data/000001/52/.gitignore")
6262

6363
# Assert Base image was pushed to local "remote" storage
6464
dvc_status_output_json = dvc(temp_git_dir).status_remote("localremote")
65-
expected_status_new = {"data/000001/42/000001-42.600.2.tif": "new"}
65+
expected_status_new = {"data/000001/52/000001-52.600.2.tif": "new"}
6666
expected_status_empty = {}
6767
assert (
6868
expected_status_new == dvc_status_output_json

0 commit comments

Comments
 (0)