Skip to content

Commit 1801451

Browse files
test: fix recovery test by mocking local_full_name
1 parent 00fe75c commit 1801451

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

tests/atlasapi/test_recovery.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,38 @@ def test_recovers_missing_metadata(mocker):
44
"""
55
Test that BrainGlobeAtlas recovers from missing metadata by re-downloading.
66
"""
7-
8-
# Simulate failure on first init, success on second
9-
# We mock 'brainglobe_atlasapi.core.Atlas.__init__' specifically.
7+
8+
# Mock Atlas.__init__: fail once, succeed second time
109
mock_atlas_init = mocker.patch(
1110
"brainglobe_atlasapi.core.Atlas.__init__",
1211
side_effect=[FileNotFoundError("Missing metadata"), None],
1312
autospec=True,
1413
)
1514

16-
# Prevent real IO - patch only relevant methods
15+
# Mock local_full_name to simulate a valid atlas folder
16+
mocker.patch(
17+
"brainglobe_atlasapi.bg_atlas.BrainGlobeAtlas.local_full_name",
18+
new_callable=mocker.PropertyMock,
19+
return_value="example_mouse_100um_v1.0",
20+
)
21+
22+
# Prevent real IO
1723
mock_download = mocker.patch(
1824
"brainglobe_atlasapi.bg_atlas.BrainGlobeAtlas.download_extract_file"
1925
)
2026
mocker.patch(
2127
"brainglobe_atlasapi.bg_atlas.BrainGlobeAtlas.check_latest_version"
2228
)
23-
# Patch shutil.rmtree to verify clean up without touching filesystem
29+
2430
mock_rmtree = mocker.patch(
2531
"brainglobe_atlasapi.bg_atlas.shutil.rmtree"
2632
)
2733

28-
2934
# Act
3035
BrainGlobeAtlas("example_mouse_100um", check_latest=False)
31-
32-
# Assert recovery behavior
33-
mock_download.assert_called_once()
36+
37+
# Assert
3438
assert mock_atlas_init.call_count == 2
35-
mock_rmtree.assert_called_once()
39+
mock_download.assert_called_once()
40+
41+

0 commit comments

Comments
 (0)