@@ 193-202 (lines=10) @@ | ||
190 | repo = JsonFile(self.dependencies) |
|
191 | img1 = self.imageWithProvenance({'transformation':'red bluered'}) |
|
192 | img2 = self.imageWithProvenance({'transformation':'red and green'}) |
|
193 | img3 = self.imageWithProvenance({'transformation':'red pruple red red'}) |
|
194 | img4 = self.imageWithProvenance({'transformation':'nuthin'}) |
|
195 | repo.all = Mock() |
|
196 | repo.all.return_value = [img1, img2, img3, img4] |
|
197 | out = repo.search('red') |
|
198 | self.assertEqual([img3, img1, img2], out) |
|
199 | ||
200 | def test_Search_looks_through_multiple_fields(self): |
|
201 | self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
|
202 | from niprov.jsonfile import JsonFile |
|
203 | repo = JsonFile(self.dependencies) |
|
204 | i1 = self.imageWithProvenance({'color':'red'}) |
|
205 | i2 = self.imageWithProvenance({'location':'redis'}) |
|
@@ 129-138 (lines=10) @@ | ||
126 | img1 = self.imageWithProvenance({'location':'i'}) |
|
127 | img2 = self.imageWithProvenance({'location':'j'}) |
|
128 | img3 = self.imageWithProvenance({'location':'m'}) |
|
129 | img4 = self.imageWithProvenance({'location':'f'}) |
|
130 | img5 = self.imageWithProvenance({'location':'x'}) |
|
131 | repo.all = Mock() |
|
132 | repo.all.return_value = [img1,img2,img3,img4,img5] |
|
133 | out = repo.byLocations(['j','f','k']) |
|
134 | self.assertEqual([img2, img4], out) |
|
135 | ||
136 | def test_byParents(self): |
|
137 | self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
|
138 | from niprov.jsonfile import JsonFile |
|
139 | repo = JsonFile(self.dependencies) |
|
140 | img1 = self.imageWithProvenance({'parents':[],'l':'a'}) |
|
141 | img2 = self.imageWithProvenance({'parents':['x','a'],'l':'b'}) |
|
@@ 241-251 (lines=11) @@ | ||
238 | from niprov.jsonfile import JsonFile |
|
239 | repo = JsonFile(self.dependencies) |
|
240 | recs = [] |
|
241 | for i in range(35): |
|
242 | recs.append(self.imageWithProvenance({'transformation':'red'})) |
|
243 | repo.all = Mock() |
|
244 | repo.all.return_value = recs |
|
245 | out = repo.search('red') |
|
246 | self.assertEqual(20, len(out)) |
|
247 | ||
248 | def test_Query_with_ALL_field(self): |
|
249 | self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
|
250 | from niprov.jsonfile import JsonFile |
|
251 | repo = JsonFile(self.dependencies) |
|
252 | img1 = self.imageWithProvenance({'a':'b'}) |
|
253 | img2 = self.imageWithProvenance({'color':'red','a':'d'}) |
|
254 | img3 = self.imageWithProvenance({'color':'blue','a':'f'}) |
|
@@ 253-263 (lines=11) @@ | ||
250 | from niprov.jsonfile import JsonFile |
|
251 | repo = JsonFile(self.dependencies) |
|
252 | img1 = self.imageWithProvenance({'a':'b'}) |
|
253 | img2 = self.imageWithProvenance({'color':'red','a':'d'}) |
|
254 | img3 = self.imageWithProvenance({'color':'blue','a':'f'}) |
|
255 | img4 = self.imageWithProvenance({'color':'green','a':'d'}) |
|
256 | img5 = self.imageWithProvenance({'color':'blue','a':'g'}) |
|
257 | repo.all = Mock() |
|
258 | repo.all.return_value = [img1, img2, img3, img4, img5] |
|
259 | q = Mock() |
|
260 | field1 = Mock() |
|
261 | field1.name = 'color' |
|
262 | field1.all = True |
|
263 | q.getFields.return_value = [field1] |
|
264 | out = repo.inquire(q) |
|
265 | self.assertIn('red', out) |
|
266 | self.assertIn('green', out) |
|
@@ 288-298 (lines=11) @@ | ||
285 | img = Mock() |
|
286 | img.getSeriesId.return_value = None |
|
287 | repo.all = Mock() |
|
288 | out = repo.getSeries(img) |
|
289 | assert not repo.all.called, "Should not be called if no series id" |
|
290 | self.assertEqual(None, out) |
|
291 | ||
292 |