@@ -22,6 +22,60 @@ def test_convert_nimads_to_dataset(example_nimads_studyset, example_nimads_annot
22
22
assert isinstance (dset2 , nimare .dataset .Dataset )
23
23
24
24
25
+ def test_convert_nimads_to_dataset_sample_sizes (
26
+ example_nimads_studyset , example_nimads_annotation
27
+ ):
28
+ """Conversion of nimads JSON to nimare dataset."""
29
+ studyset = Studyset (example_nimads_studyset )
30
+ for study in studyset .studies :
31
+ for analysis in study .analyses :
32
+ analysis .metadata ["sample_sizes" ] = [2 , 20 ]
33
+
34
+ dset = io .convert_nimads_to_dataset (studyset )
35
+
36
+ assert isinstance (dset , nimare .dataset .Dataset )
37
+ assert "sample_sizes" in dset .metadata .columns
38
+
39
+
40
+ def test_convert_nimads_to_dataset_single_sample_size (
41
+ example_nimads_studyset , example_nimads_annotation
42
+ ):
43
+ """Test conversion of nimads JSON to nimare dataset with a single sample size value."""
44
+ studyset = Studyset (example_nimads_studyset )
45
+ for study in studyset .studies :
46
+ for analysis in study .analyses :
47
+ analysis .metadata ["sample_size" ] = 20
48
+
49
+ dset = io .convert_nimads_to_dataset (studyset )
50
+
51
+ assert isinstance (dset , nimare .dataset .Dataset )
52
+ assert "sample_sizes" in dset .metadata .columns
53
+
54
+
55
+ def test_analysis_to_dict_invalid_sample_sizes_type (example_nimads_studyset ):
56
+ """Test _analysis_to_dict raises ValueError when sample_sizes is not a list/tuple."""
57
+ studyset = Studyset (example_nimads_studyset )
58
+ # Set sample_sizes to an int rather than list/tuple
59
+ for study in studyset .studies :
60
+ for analysis in study .analyses :
61
+ analysis .metadata ["sample_sizes" ] = 5
62
+ with pytest .raises (TypeError ):
63
+ # Trigger conversion which internally calls _analysis_to_dict
64
+ io .convert_nimads_to_dataset (studyset )
65
+
66
+
67
+ def test_analysis_to_dict_invalid_annotations_format (example_nimads_studyset ):
68
+ """Test _analysis_to_dict raises ValueError when annotations are in an invalid format."""
69
+ studyset = Studyset (example_nimads_studyset )
70
+ # Here we assume that the annotation is expected to be a dict
71
+ # Set annotation to an invalid format (e.g., a string)
72
+ for study in studyset .studies :
73
+ for analysis in study .analyses :
74
+ analysis .metadata ["annotations" ] = "invalid_format"
75
+ with pytest .raises (TypeError ):
76
+ io .convert_nimads_to_dataset (studyset )
77
+
78
+
25
79
def test_convert_sleuth_to_dataset_smoke ():
26
80
"""Smoke test for Sleuth text file conversion."""
27
81
sleuth_file = os .path .join (get_test_data_path (), "test_sleuth_file.txt" )
0 commit comments