From 260673573c381710be86cfeb3227a78646e6c10f Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Thu, 25 Jul 2024 11:02:37 +0100 Subject: [PATCH] Enable more tests --- .../test_brainmapper/test_transform_widget.py | 132 ++++++++---------- 1 file changed, 62 insertions(+), 70 deletions(-) diff --git a/tests/tests/test_brainmapper/test_transform_widget.py b/tests/tests/test_brainmapper/test_transform_widget.py index 85b25af..4acd059 100644 --- a/tests/tests/test_brainmapper/test_transform_widget.py +++ b/tests/tests/test_brainmapper/test_transform_widget.py @@ -285,26 +285,24 @@ def test_call_transform_points_to_atlas_space( # ) # # -# def test_transformation_raises_info_points_out_of_bounds( -# transformation_widget_with_data, mock_display_info -# ): -# points_layer = transformation_widget_with_data.viewer.add_points( -# points_outside_brain -# ) -# transformation_widget_with_data.points_layer = points_layer -# transformation_widget_with_data. -# run_transform_points_to_downsampled_space() -# transformation_widget_with_data. -# run_transform_downsampled_points_to_atlas_space() -# mock_display_info.assert_called_once_with( -# transformation_widget_with_data, -# "Points outside atlas", -# "2 points fell outside the atlas space", -# ) +def test_transformation_raises_info_points_out_of_bounds( + transformation_widget_with_data, mock_display_info +): + points_layer = transformation_widget_with_data.viewer.add_points( + points_outside_brain + ) + transformation_widget_with_data.points_layer = points_layer + transformation_widget_with_data.run_transform_points_to_downsampled_space() + transformation_widget_with_data.run_transform_downsampled_points_to_atlas_space() + mock_display_info.assert_called_once_with( + transformation_widget_with_data, + "Points outside atlas", + "2 points fell outside the atlas space", + ) -# def test_check_layers(transformation_widget_with_data): -# assert transformation_widget_with_data.check_layers() +def test_check_layers(transformation_widget_with_data): + assert transformation_widget_with_data.check_layers() def test_check_layers_no_layers(transformation_widget, mock_display_info): @@ -349,21 +347,20 @@ def test_check_layers_no_points_data( ) -# def test_load_brainreg_directory( -# transformation_widget_with_napari_layers, brainreg_directory, mocker -# ): -# # Mock dialog to avoid need for UI -# mock_get_save_file_name = mocker.patch( -# "brainglobe_utils.brainmapper.transform_widget. -# QFileDialog.getExistingDirectory" -# ) -# mock_get_save_file_name.return_value = brainreg_directory -# -# transformation_widget_with_napari_layers.load_brainreg_directory() -# assert ( -# transformation_widget_with_napari_layers.atlas.atlas_name -# == "allen_mouse_50um" -# ) +def test_load_brainreg_directory( + transformation_widget_with_napari_layers, brainreg_directory, mocker +): + # Mock dialog to avoid need for UI + mock_get_save_file_name = mocker.patch( + "brainglobe_utils.brainmapper.transform_widget.QFileDialog.getExistingDirectory" + ) + mock_get_save_file_name.return_value = brainreg_directory + + transformation_widget_with_napari_layers.load_brainreg_directory() + assert ( + transformation_widget_with_napari_layers.atlas.atlas_name + == "allen_mouse_50um" + ) def test_load_brainreg_directory_no_input( @@ -381,45 +378,40 @@ def test_load_brainreg_directory_no_input( ) -# 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_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_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(