Coverage for nilearn/surface/tests/test_utils.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-16 12:32 +0200

1import numpy as np 

2import pytest 

3 

4from nilearn.surface import PolyData 

5from nilearn.surface.utils import ( 

6 assert_polydata_equal, 

7 assert_surface_mesh_equal, 

8) 

9 

10 

11def test_assert_polydata_equal(): 

12 """Check that PolyData with different keys are detected.""" 

13 data_1 = PolyData(left=np.ones((3, 2)), right=np.ones((3, 2))) 

14 data_2 = PolyData(left=np.ones((3, 2)), right=np.ones((3, 2))) 

15 

16 assert_polydata_equal(data_1, data_2) 

17 

18 data_2.parts["new_key"] = np.ones((3, 2)) 

19 

20 with pytest.raises( 

21 ValueError, match="PolyData do not have the same keys." 

22 ): 

23 assert_polydata_equal(data_1, data_2) 

24 

25 

26def test_assert_surface_mesh_equal(surf_mesh): 

27 """Check that Meshes with different faces/coords are detected.""" 

28 assert_surface_mesh_equal(surf_mesh.parts["left"], surf_mesh.parts["left"]) 

29 

30 with pytest.raises( 

31 ValueError, match="Meshes do not have the same coordinates." 

32 ): 

33 assert_surface_mesh_equal( 

34 surf_mesh.parts["left"], surf_mesh.parts["right"] 

35 ) 

36 

37 surf_mesh.parts["right"].coordinates = surf_mesh.parts["left"].coordinates 

38 

39 with pytest.raises(ValueError, match="Meshes do not have the same faces."): 

40 assert_surface_mesh_equal( 

41 surf_mesh.parts["left"], surf_mesh.parts["right"] 

42 )