@@ 140-152 (lines=13) @@ | ||
137 | out = repo.byId('2') |
|
138 | self.assertEqual(img2, out) |
|
139 | ||
140 | def test_byLocations(self): |
|
141 | self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['a'] |
|
142 | from niprov.jsonfile import JsonFile |
|
143 | repo = JsonFile(self.dependencies) |
|
144 | img1 = self.imageWithProvenance({'location':'i'}) |
|
145 | img2 = self.imageWithProvenance({'location':'j'}) |
|
146 | img3 = self.imageWithProvenance({'location':'m'}) |
|
147 | img4 = self.imageWithProvenance({'location':'f'}) |
|
148 | img5 = self.imageWithProvenance({'location':'x'}) |
|
149 | repo.all = Mock() |
|
150 | repo.all.return_value = [img1,img2,img3,img4,img5] |
|
151 | out = repo.byLocations(['j','f','k']) |
|
152 | self.assertEqual([img2, img4], out) |
|
153 | ||
154 | def test_byParents(self): |
|
155 | self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
|
@@ 204-215 (lines=12) @@ | ||
201 | out = repo.search('red') |
|
202 | self.assertEqual([img2], out) |
|
203 | ||
204 | def test_Search_sorts_results_by_number_of_matches(self): |
|
205 | self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
|
206 | from niprov.jsonfile import JsonFile |
|
207 | repo = JsonFile(self.dependencies) |
|
208 | img1 = self.imageWithProvenance({'transformation':'red bluered'}) |
|
209 | img2 = self.imageWithProvenance({'transformation':'red and green'}) |
|
210 | img3 = self.imageWithProvenance({'transformation':'red pruple red red'}) |
|
211 | img4 = self.imageWithProvenance({'transformation':'nuthin'}) |
|
212 | repo.all = Mock() |
|
213 | repo.all.return_value = [img1, img2, img3, img4] |
|
214 | out = repo.search('red') |
|
215 | self.assertEqual([img3, img1, img2], out) |
|
216 | ||
217 | def test_Search_looks_through_multiple_fields(self): |
|
218 | self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |