Code Duplication    Length = 10-11 lines in 4 locations

tests/test_jsonfile.py 4 locations

@@ 193-202 (lines=10) @@
190
        out = repo.inquire(q)
191
        self.assertEqual([img2, img4], out)
192
193
    def test_Search_only_returns_objects_which_have_needle(self):
194
        self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l']
195
        from niprov.jsonfile import JsonFile
196
        repo = JsonFile(self.dependencies)
197
        img1 = self.imageWithProvenance({'transformation':'green blue'})
198
        img2 = self.imageWithProvenance({'transformation':'yellow red'})
199
        repo.all = Mock()
200
        repo.all.return_value = [img1, img2]
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']
@@ 129-138 (lines=10) @@
126
        out = repo.statistics()
127
        self.assertEqual(totalsize, out['totalsize'])
128
        
129
    def test_byId(self):
130
        from niprov.jsonfile import JsonFile
131
        repo = JsonFile(self.dependencies)
132
        img1 = self.imageWithProvenance({'id':'1'})
133
        img2 = self.imageWithProvenance({'id':'2'})
134
        img3 = self.imageWithProvenance({'id':'3'})
135
        repo.all = Mock()
136
        repo.all.return_value = [img1, img2, img3]
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']
@@ 241-251 (lines=11) @@
238
        self.assertIn(i7, out)
239
        self.assertIn(i8, out)
240
241
    def test_Search_distinguishes_words_as_OR_search(self):
242
        self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l']
243
        from niprov.jsonfile import JsonFile
244
        repo = JsonFile(self.dependencies)
245
        i1 = self.imageWithProvenance({'transformation':'blue red red'})       #2
246
        i2 = self.imageWithProvenance({'transformation':'red blue green red'}) #3
247
        i3 = self.imageWithProvenance({'transformation':'green blue'})         #1
248
        repo.all = Mock()
249
        repo.all.return_value = [i1,i2,i3]
250
        out = repo.search('red green')
251
        self.assertEqual([i2, i1, i3], out)
252
253
    def test_Search_returns_max_20_results(self):
254
        self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l']
@@ 253-263 (lines=11) @@
250
        out = repo.search('red green')
251
        self.assertEqual([i2, i1, i3], out)
252
253
    def test_Search_returns_max_20_results(self):
254
        self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l']
255
        from niprov.jsonfile import JsonFile
256
        repo = JsonFile(self.dependencies)
257
        recs = []
258
        for i in range(35):
259
            recs.append(self.imageWithProvenance({'transformation':'red'}))
260
        repo.all = Mock()
261
        repo.all.return_value = recs
262
        out = repo.search('red')
263
        self.assertEqual(20, len(out))
264
265