From 5ad5f8e99bdc7aba0d03e811e81dbc4a46e59ae5 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Thu, 25 Jul 2024 07:21:42 +0100 Subject: [PATCH] Add non-brainreg tests --- .../test_brainmapper/test_transform_widget.py | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/tests/tests/test_brainmapper/test_transform_widget.py b/tests/tests/test_brainmapper/test_transform_widget.py index ed1e0af..06809fc 100644 --- a/tests/tests/test_brainmapper/test_transform_widget.py +++ b/tests/tests/test_brainmapper/test_transform_widget.py @@ -166,17 +166,17 @@ def transformation_widget(make_napari_viewer): return widget -# @pytest.fixture(scope="function") -# def transformation_widget_with_napari_layers( -# transformation_widget, brainreg_directory -# ): -# points_layer = transformation_widget.viewer.add_points(points) -# transformation_widget.points_layer = points_layer -# -# raw_data = brainreg_directory / "downsampled.tiff" -# raw_data_layer = transformation_widget.viewer.open(raw_data) -# transformation_widget.raw_data = raw_data_layer[0] -# return transformation_widget +@pytest.fixture(scope="function") +def transformation_widget_with_napari_layers( + transformation_widget, brainreg_directory +): + points_layer = transformation_widget.viewer.add_points(points) + transformation_widget.points_layer = points_layer + + raw_data = brainreg_directory / "downsampled.tiff" + raw_data_layer = transformation_widget.viewer.open(raw_data) + transformation_widget.raw_data = raw_data_layer[0] + return transformation_widget @pytest.fixture @@ -361,20 +361,21 @@ def test_check_layers_no_raw_data(transformation_widget, mock_display_info): # ) # # -# def test_load_brainreg_directory_no_input( -# transformation_widget_with_napari_layers, 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 = "" -# -# transformation_widget_with_napari_layers.load_brainreg_directory() -# assert not hasattr( -# transformation_widget_with_napari_layers.atlas, "atlas_name" -# ) +def test_load_brainreg_directory_no_input( + transformation_widget_with_napari_layers, 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 = "" + + transformation_widget_with_napari_layers.load_brainreg_directory() + assert not hasattr( + transformation_widget_with_napari_layers.atlas, "atlas_name" + ) + + # # # def test_check_brainreg_directory_correct_metadata( @@ -414,19 +415,20 @@ def test_check_layers_no_raw_data(transformation_widget, mock_display_info): # mock_method.assert_called_once() # # -# def test_display_brainreg_directory_warning_calls_display_info( -# transformation_widget_with_napari_layers, mock_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_display_brainreg_directory_warning_calls_display_info( + transformation_widget_with_napari_layers, mock_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):