Coverage for nilearn/interfaces/fmriprep/tests/test_load_confounds_utils.py: 0%

16 statements  

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

1import pytest 

2 

3from nilearn.interfaces.fmriprep.load_confounds_utils import ( 

4 _get_file_name, 

5 sanitize_confounds, 

6) 

7from nilearn.interfaces.fmriprep.tests._testing import create_tmp_filepath 

8 

9 

10@pytest.mark.parametrize( 

11 "inputs,flag", 

12 [ 

13 (["image.nii.gz"], True), 

14 ("image.nii.gz", True), 

15 (["image1.nii.gz", "image2.nii.gz"], False), 

16 (["image_L.func.gii", "image_R.func.gii"], True), 

17 ([["image_L.func.gii", "image_R.func.gii"]], True), 

18 ( 

19 [ 

20 ["image1_L.func.gii", "image1_R.func.gii"], 

21 ["image2_L.func.gii", "image2_R.func.gii"], 

22 ], 

23 False, 

24 ), 

25 ], 

26) 

27def test_sanitize_confounds(inputs, flag): 

28 """Should correctly catch inputs that are a single image.""" 

29 _, singleflag = sanitize_confounds(inputs) 

30 assert singleflag is flag 

31 

32 

33@pytest.mark.parametrize( 

34 "flag,keyword", 

35 [ 

36 ("1.2.x", "_desc-confounds_regressors"), 

37 ("1.4.x", "_desc-confounds_timeseries"), 

38 ("21.x.x", "21xx"), 

39 ], 

40) 

41@pytest.mark.parametrize( 

42 "image_type", ["regular", "native", "res", "cifti", "den", "part", "gifti"] 

43) 

44def test_get_file_name(tmp_path, flag, keyword, image_type): 

45 """Test _get_file_name.""" 

46 if image_type == "part": 

47 kwargs = { 

48 "bids_fields": { 

49 "entities": { 

50 "sub": flag.replace(".", ""), 

51 "task": "test", 

52 "part": "mag", 

53 "run": "01", 

54 } 

55 } 

56 } 

57 else: 

58 kwargs = {} 

59 

60 img, _ = create_tmp_filepath( 

61 tmp_path, 

62 image_type=image_type, 

63 fmriprep_version=flag, 

64 **kwargs, 

65 ) 

66 

67 conf = _get_file_name(img) 

68 

69 assert keyword in conf