Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Jul 22, 2024
1 parent fe59388 commit 108a562
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion brainglobe_utils/brainmapper/transform_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def check_brainreg_directory(self):
with open(self.paths.brainreg_metadata_file) as json_file:
self.brainreg_metadata = json.load(json_file)

if not self.brainreg_metadata["atlas"]:
if "atlas" not in self.brainreg_metadata:
self.display_brainreg_directory_warning()

except FileNotFoundError:
Expand Down
68 changes: 68 additions & 0 deletions tests/tests/test_brainmapper/test_transform_widget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from pathlib import Path
from typing import Any, Dict

Expand Down Expand Up @@ -210,6 +211,73 @@ def test_transform_points_to_atlas_space(
)


@pytest.fixture
def random_json_path(tmp_path):
json_path = tmp_path / "random_json.json"
content = {
"name": "Pooh Bear",
"location": "100 acre wood",
"food": "Honey",
}
with open(json_path, "w") as f:
json.dump(content, f)

return json_path


def test_check_brainreg_directory_correct_metadata(
mocker, transformation_widget_with_data
):
mock_method = mocker.patch.object(
transformation_widget_with_data, "display_brainreg_directory_warning"
)

transformation_widget_with_data.check_brainreg_directory()
mock_method.assert_not_called()


def test_check_brainreg_directory_random_data(
mocker, transformation_widget_with_data, random_json_path
):
mock_method = mocker.patch.object(
transformation_widget_with_data, "display_brainreg_directory_warning"
)
transformation_widget_with_data.paths.brainreg_metadata_file = (
random_json_path
)
transformation_widget_with_data.check_brainreg_directory()
mock_method.assert_called_once()


def test_check_brainreg_directory_false_path(
mocker, transformation_widget_with_data
):
mock_method = mocker.patch.object(
transformation_widget_with_data, "display_brainreg_directory_warning"
)

transformation_widget_with_data.paths.brainreg_metadata_file = "/some/file"
transformation_widget_with_data.check_brainreg_directory()
mock_method.assert_called_once()


def test_display_brainreg_directory_warning_calls_display_info(
mocker, transformation_widget_with_napari_layers
):
mock_display_info = mocker.patch(
"brainglobe_utils.brainmapper.transform_widget.display_info"
)
transformation_widget_with_napari_layers.display_brainreg_directory_warning()

# Assert display_info was called once with the expected arguments
mock_display_info.assert_called_once_with(
transformation_widget_with_napari_layers,
"Not a brainreg directory",
"This directory does not appear to be a valid brainreg directory. "
"Please try loading another brainreg output directory.",
)


def test_analysis(transformation_widget_with_transformed_points):
transformation_widget_with_transformed_points.analyse_points()

Expand Down

0 comments on commit 108a562

Please sign in to comment.