From 229864b8b3a902f1054ad3694ecfd2cfcb8b281f Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Sun, 1 Dec 2024 13:32:13 -0500 Subject: [PATCH] update tests --- hippunfold_plot/tests/test_plotting.py | 39 --------------- tests/test_plotting.py | 69 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 39 deletions(-) delete mode 100644 hippunfold_plot/tests/test_plotting.py create mode 100644 tests/test_plotting.py diff --git a/hippunfold_plot/tests/test_plotting.py b/hippunfold_plot/tests/test_plotting.py deleted file mode 100644 index 1f609a0..0000000 --- a/hippunfold_plot/tests/test_plotting.py +++ /dev/null @@ -1,39 +0,0 @@ -import unittest -import matplotlib.pyplot as plt -from plotting import plot_hipp_surf - -class TestPlotHippSurf(unittest.TestCase): - - def test_invalid_density(self): - with self.assertRaises(ValueError): - plot_hipp_surf(surf_map='dummy_path', density='invalid_density') - - def test_invalid_hemi(self): - with self.assertRaises(ValueError): - plot_hipp_surf(surf_map='dummy_path', hemi='invalid_hemi') - - def test_invalid_space(self): - with self.assertRaises(ValueError): - plot_hipp_surf(surf_map='dummy_path', space='invalid_space') - - def test_plot_creation(self): - fig = plot_hipp_surf(surf_map='dummy_path') - self.assertIsInstance(fig, plt.Figure) - - def test_colorbar(self): - fig = plot_hipp_surf(surf_map='dummy_path', colorbar=True) - self.assertIsInstance(fig, plt.Figure) - self.assertEqual(len(fig.axes), 6) # 5 plots + 1 colorbar - - def test_default_parameters(self): - fig = plot_hipp_surf(surf_map='dummy_path') - self.assertIsInstance(fig, plt.Figure) - self.assertEqual(len(fig.axes), 5) # 5 plots - - def test_custom_parameters(self): - fig = plot_hipp_surf(surf_map='dummy_path', density='1mm', hemi='right', space='canonical', figsize=(10, 6), dpi=200, vmin=0, vmax=1, colorbar=True, colorbar_shrink=0.5, cmap='viridis', view='ventral', avg_method='mean', bg_on_data=False, alpha=0.5, darkness=1) - self.assertIsInstance(fig, plt.Figure) - self.assertEqual(len(fig.axes), 6) # 5 plots + 1 colorbar - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/tests/test_plotting.py b/tests/test_plotting.py new file mode 100644 index 0000000..c4f8354 --- /dev/null +++ b/tests/test_plotting.py @@ -0,0 +1,69 @@ +import unittest +import numpy as np +import nibabel as nib +import matplotlib.pyplot as plt +from hippunfold_plot.plotting import plot_hipp_surf +from hippunfold_plot.utils import get_resource_path + +class TestPlotHippSurf(unittest.TestCase): + + def setUp(self): + # Get a valid file path from resources + self.label_gii = get_resource_path('tpl-avg_label-hippdentate_density-1mm_subfields.label.gii') + self.density = '1mm' + + # Load the GIFTI file to get the number of vertices + gii = nib.load(self.label_gii) + num_vertices = gii.darrays[0].data.shape[0] + + # Create a random numpy array with the same number of vertices + self.random_surf_map = np.random.rand(num_vertices, 1) + + + def test_invalid_density(self): + with self.assertRaises(ValueError): + plot_hipp_surf(surf_map=self.label_gii, density='invalid_density') + + def test_invalid_hemi(self): + with self.assertRaises(ValueError): + plot_hipp_surf(surf_map=self.label_gii, hemi='invalid_hemi') + + def test_invalid_space(self): + with self.assertRaises(ValueError): + plot_hipp_surf(surf_map=self.label_gii, space='invalid_space') + + def test_plot_creation_with_file(self): + fig = plot_hipp_surf(surf_map=self.label_gii, density=self.density) + self.assertIsInstance(fig, plt.Figure) + + def test_plot_creation_with_numpy_array(self): + fig = plot_hipp_surf(surf_map=self.random_surf_map, density=self.density) + self.assertIsInstance(fig, plt.Figure) + + def test_colorbar_with_file(self): + fig = plot_hipp_surf(surf_map=self.label_gii, density=self.density, colorbar=True) + self.assertIsInstance(fig, plt.Figure) + + def test_colorbar_with_numpy_array(self): + fig = plot_hipp_surf(surf_map=self.random_surf_map, density=self.density, colorbar=True) + self.assertIsInstance(fig, plt.Figure) + + def test_default_parameters_with_file(self): + fig = plot_hipp_surf(surf_map=self.label_gii, density=self.density) + self.assertIsInstance(fig, plt.Figure) + + def test_default_parameters_with_numpy_array(self): + fig = plot_hipp_surf(surf_map=self.random_surf_map, density=self.density) + self.assertIsInstance(fig, plt.Figure) + + def test_custom_parameters_with_file(self): + fig = plot_hipp_surf(surf_map=self.label_gii, density='1mm', hemi='right', space='canonical', figsize=(10, 6), dpi=200, vmin=0, vmax=1, colorbar=True, colorbar_shrink=0.5, cmap='viridis', view='ventral', avg_method='mean', bg_on_data=False, alpha=0.5, darkness=1) + self.assertIsInstance(fig, plt.Figure) + + def test_custom_parameters_with_numpy_array(self): + fig = plot_hipp_surf(surf_map=self.random_surf_map, density='1mm', hemi='right', space='canonical', figsize=(10, 6), dpi=200, vmin=0, vmax=1, colorbar=True, colorbar_shrink=0.5, cmap='viridis', view='ventral', avg_method='mean', bg_on_data=False, alpha=0.5, darkness=1) + self.assertIsInstance(fig, plt.Figure) + +if __name__ == '__main__': + unittest.main() +