Coverage for nilearn/plotting/displays/tests/test_figures.py: 0%

24 statements  

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

1"""Test nilearn.plotting.displays._figures.SurfaceFigure.""" 

2 

3import pytest 

4 

5from nilearn._utils.helpers import is_plotly_installed 

6from nilearn.plotting.displays import PlotlySurfaceFigure, SurfaceFigure 

7 

8 

9def test_surface_figure(): 

10 """Tests SurfaceFigure class.""" 

11 s = SurfaceFigure() 

12 assert s.output_file is None 

13 assert s.figure is None 

14 assert s.hemi == "left" 

15 s._check_output_file("foo.png") 

16 assert s.output_file == "foo.png" 

17 s = SurfaceFigure(output_file="bar.png") 

18 assert s.output_file == "bar.png" 

19 

20 

21def test_surface_figure_errors(): 

22 """Test SurfaceFigure class for errors.""" 

23 figure = SurfaceFigure() 

24 with pytest.raises(NotImplementedError): 

25 figure.add_contours() 

26 with pytest.raises(NotImplementedError): 

27 figure.show() 

28 with pytest.raises(ValueError, match="You must provide an output file"): 

29 figure._check_output_file() 

30 

31 

32@pytest.mark.skipif( 

33 is_plotly_installed(), 

34 reason="This test only runs if Plotly is not installed.", 

35) 

36def test_plotly_surface_figure_import_error(): 

37 """Test that an ImportError is raised when instantiating \ 

38 a PlotlySurfaceFigure without having Plotly installed. 

39 """ 

40 with pytest.raises(ImportError, match="Plotly is required"): 

41 PlotlySurfaceFigure()