@@ -69,7 +69,7 @@ def test_FieldmapEstimation(testdata_dir, inputfiles, method, nsources, raises):
69
69
fm .FieldmapEstimation (sources )
70
70
71
71
# Clean up so this parameter set can be tested.
72
- fm ._estimators . clear ()
72
+ fm .clear_registry ()
73
73
74
74
fe = fm .FieldmapEstimation (sources )
75
75
assert fe .method == method
@@ -109,17 +109,17 @@ def test_FieldmapEstimationError(testdata_dir, inputfiles, errortype):
109
109
"""Test errors."""
110
110
sub_dir = testdata_dir / "sub-01"
111
111
112
- fm ._estimators . clear ()
112
+ fm .clear_registry ()
113
113
114
114
with pytest .raises (errortype ):
115
115
fm .FieldmapEstimation ([sub_dir / f for f in inputfiles ])
116
116
117
- fm ._estimators . clear ()
117
+ fm .clear_registry ()
118
118
119
119
120
- def test_FieldmapEstimationIdentifier (testdata_dir ):
120
+ def test_FieldmapEstimationIdentifier (monkeypatch , testdata_dir ):
121
121
"""Check some use cases of B0FieldIdentifier."""
122
- fm ._estimators . clear ()
122
+ fm .clear_registry ()
123
123
124
124
with pytest .raises (ValueError ):
125
125
fm .FieldmapEstimation (
@@ -139,7 +139,11 @@ def test_FieldmapEstimationIdentifier(testdata_dir):
139
139
[
140
140
fm .FieldmapFile (
141
141
testdata_dir / "sub-01" / "fmap/sub-01_fieldmap.nii.gz" ,
142
- metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_0" },
142
+ metadata = {
143
+ "Units" : "Hz" ,
144
+ "B0FieldIdentifier" : "fmap_0" ,
145
+ "IntendedFor" : "file1.nii.gz" ,
146
+ },
143
147
),
144
148
fm .FieldmapFile (
145
149
testdata_dir / "sub-01" / "fmap/sub-01_magnitude.nii.gz" ,
@@ -148,6 +152,8 @@ def test_FieldmapEstimationIdentifier(testdata_dir):
148
152
]
149
153
)
150
154
assert fe .bids_id == "fmap_0"
155
+ assert fm .get_identifier ("file1.nii.gz" ) == ("fmap_0" ,)
156
+ assert not fm .get_identifier ("file2.nii.gz" )
151
157
152
158
with pytest .raises (KeyError ):
153
159
fm .FieldmapEstimation (
@@ -163,13 +169,17 @@ def test_FieldmapEstimationIdentifier(testdata_dir):
163
169
]
164
170
) # Consistent, but already exists
165
171
166
- fm ._estimators . clear ()
172
+ fm .clear_registry ()
167
173
168
174
fe = fm .FieldmapEstimation (
169
175
[
170
176
fm .FieldmapFile (
171
177
testdata_dir / "sub-01" / "fmap/sub-01_fieldmap.nii.gz" ,
172
- metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_1" },
178
+ metadata = {
179
+ "Units" : "Hz" ,
180
+ "B0FieldIdentifier" : "fmap_1" ,
181
+ "IntendedFor" : ["file1.nii.gz" , "file2.nii.gz" ],
182
+ },
173
183
),
174
184
fm .FieldmapFile (
175
185
testdata_dir / "sub-01" / "fmap/sub-01_magnitude.nii.gz" ,
@@ -178,5 +188,15 @@ def test_FieldmapEstimationIdentifier(testdata_dir):
178
188
]
179
189
)
180
190
assert fe .bids_id == "fmap_1"
181
-
182
- fm ._estimators .clear ()
191
+ assert fm .get_identifier ("file1.nii.gz" ) == ("fmap_1" ,)
192
+ assert fm .get_identifier ("file2.nii.gz" ) == ("fmap_1" ,)
193
+ assert not fm .get_identifier ("file3.nii.gz" )
194
+ assert fm .get_identifier (
195
+ str (testdata_dir / "sub-01" / "fmap/sub-01_magnitude.nii.gz" ), by = "sources"
196
+ ) == ("fmap_1" ,)
197
+
198
+ with monkeypatch .context () as m :
199
+ m .setattr (fm , "_intents" , {"file1.nii.gz" : {"fmap_0" , "fmap_1" }})
200
+ assert fm .get_identifier ("file1.nii.gz" ) == ("fmap_0" , "fmap_1" ,)
201
+
202
+ fm .clear_registry ()
0 commit comments