diff --git a/tests/tests/test_brainmapper/test_transform_widget.py b/tests/tests/test_brainmapper/test_transform_widget.py index 4acd059..d3050d5 100644 --- a/tests/tests/test_brainmapper/test_transform_widget.py +++ b/tests/tests/test_brainmapper/test_transform_widget.py @@ -137,15 +137,13 @@ def mock_display_info(mocker): ) -# @pytest.fixture(scope="function") -# def transformation_widget_with_transformed_points( -# transformation_widget_with_data, -# ): -# transformation_widget_with_data. -# run_transform_points_to_downsampled_space() -# transformation_widget_with_data. -# run_transform_downsampled_points_to_atlas_space() -# return transformation_widget_with_data +@pytest.fixture(scope="function") +def transformation_widget_with_transformed_points( + transformation_widget_with_data, +): + transformation_widget_with_data.run_transform_points_to_downsampled_space() + transformation_widget_with_data.run_transform_downsampled_points_to_atlas_space() + return transformation_widget_with_data @pytest.fixture(scope="function") @@ -268,23 +266,23 @@ def test_call_transform_points_to_atlas_space( mock_analyse_points.assert_called_once() -# def test_transform_points_to_atlas_space( -# transformation_widget_with_transformed_points, -# ): -# np.testing.assert_array_equal( -# transformation_widget_with_transformed_points.viewer.layers[ -# "Points in downsampled space" -# ].data, -# points_in_downsampled_space, -# ) -# np.testing.assert_array_equal( -# transformation_widget_with_transformed_points.viewer.layers[ -# "Points in atlas space" -# ].data, -# points_in_atlas_space, -# ) -# -# +def test_transform_points_to_atlas_space( + transformation_widget_with_transformed_points, +): + np.testing.assert_array_equal( + transformation_widget_with_transformed_points.viewer.layers[ + "Points in downsampled space" + ].data, + points_in_downsampled_space, + ) + np.testing.assert_array_equal( + transformation_widget_with_transformed_points.viewer.layers[ + "Points in atlas space" + ].data, + points_in_atlas_space, + ) + + def test_transformation_raises_info_points_out_of_bounds( transformation_widget_with_data, mock_display_info ): @@ -428,89 +426,85 @@ def test_display_brainreg_directory_warning_calls_display_info( ) -# -# -# def test_analysis(transformation_widget_with_transformed_points): -# transformation_widget_with_transformed_points.analyse_points() -# -# assert ( -# transformation_widget_with_transformed_points.all_points_df.shape[0] -# == 21 -# ) -# -# df = transformation_widget_with_transformed_points.points_per_region_df -# assert ( -# df.loc[ -# df["structure_name"] == "Caudoputamen", "left_cell_count" -# ].values[0] -# == 9 -# ) -# assert ( -# df.loc[df["structure_name"] == "Pons", "left_cell_count"].values[0] -# == 1 -# ) -# assert ( -# df.loc[ -# df["structure_name"] -# == "Primary somatosensory area, upper limb, layer 5", -# "left_cells_per_mm3", -# ].values[0] -# == 0 -# ) - - -# def test_save_df_to_csv( -# mocker, -# transformation_widget_with_transformed_points, -# sample_dataframe, -# tmp_path, -# ): -# # Mock dialog to avoid need for UI -# mock_get_save_file_name = mocker.patch( -# "brainglobe_utils.brainmapper.transform_widget. -# QFileDialog.getSaveFileName" -# ) -# -# save_path = tmp_path / "test.csv" -# mock_get_save_file_name.return_value = (save_path, "CSV Files (*.csv)") -# -# transformation_widget_with_transformed_points.save_df_to_csv( -# sample_dataframe -# ) -# -# # Ensure the file dialog was called -# mock_get_save_file_name.assert_called_once_with( -# transformation_widget_with_transformed_points, -# "Choose filename", -# "", -# "CSV Files (*.csv)", -# ) -# -# assert save_path.exists() - - -# def test_save_all_points_and_summary_csv( -# mocker, -# transformation_widget_with_transformed_points, -# tmp_path, -# ): -# transformation_widget_with_transformed_points.analyse_points() -# -# # Mock dialog to avoid need for UI -# mock_get_save_file_name = mocker.patch( -# "brainglobe_utils.brainmapper. -# transform_widget.QFileDialog.getSaveFileName" -# ) -# -# save_path = tmp_path / "all_points.csv" -# mock_get_save_file_name.return_value = (save_path, "CSV Files (*.csv)") -# transformation_widget_with_transformed_points.save_all_points_csv() -# assert save_path.exists() -# -# save_path = tmp_path / "points_per_region.csv" -# mock_get_save_file_name.return_value = (save_path, "CSV Files (*.csv)") -# transformation_widget_with_transformed_points.save_points_summary_csv() -# assert save_path.exists() +def test_analysis(transformation_widget_with_transformed_points): + transformation_widget_with_transformed_points.analyse_points() + + assert ( + transformation_widget_with_transformed_points.all_points_df.shape[0] + == 21 + ) + + df = transformation_widget_with_transformed_points.points_per_region_df + assert ( + df.loc[ + df["structure_name"] == "Caudoputamen", "left_cell_count" + ].values[0] + == 9 + ) + assert ( + df.loc[df["structure_name"] == "Pons", "left_cell_count"].values[0] + == 1 + ) + assert ( + df.loc[ + df["structure_name"] + == "Primary somatosensory area, upper limb, layer 5", + "left_cells_per_mm3", + ].values[0] + == 0 + ) + + +def test_save_df_to_csv( + mocker, + transformation_widget_with_transformed_points, + sample_dataframe, + tmp_path, +): + # Mock dialog to avoid need for UI + mock_get_save_file_name = mocker.patch( + "brainglobe_utils.brainmapper.transform_widget.QFileDialog.getSaveFileName" + ) + + save_path = tmp_path / "test.csv" + mock_get_save_file_name.return_value = (save_path, "CSV Files (*.csv)") + + transformation_widget_with_transformed_points.save_df_to_csv( + sample_dataframe + ) + + # Ensure the file dialog was called + mock_get_save_file_name.assert_called_once_with( + transformation_widget_with_transformed_points, + "Choose filename", + "", + "CSV Files (*.csv)", + ) + + assert save_path.exists() + + +def test_save_all_points_and_summary_csv( + mocker, + transformation_widget_with_transformed_points, + tmp_path, +): + transformation_widget_with_transformed_points.analyse_points() + + # Mock dialog to avoid need for UI + mock_get_save_file_name = mocker.patch( + "brainglobe_utils.brainmapper.transform_widget.QFileDialog.getSaveFileName" + ) + + save_path = tmp_path / "all_points.csv" + mock_get_save_file_name.return_value = (save_path, "CSV Files (*.csv)") + transformation_widget_with_transformed_points.save_all_points_csv() + assert save_path.exists() + + save_path = tmp_path / "points_per_region.csv" + mock_get_save_file_name.return_value = (save_path, "CSV Files (*.csv)") + transformation_widget_with_transformed_points.save_points_summary_csv() + assert save_path.exists() def test_is_atlas_installed(mocker, transformation_widget):