Skip to content

Commit

Permalink
renable all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Jul 25, 2024
1 parent 2606735 commit 41f0f3d
Showing 1 changed file with 103 additions and 109 deletions.
212 changes: 103 additions & 109 deletions tests/tests/test_brainmapper/test_transform_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 41f0f3d

Please sign in to comment.