예제 #1
0
 def test_wrong_query(self):
     index = defaultdict(list, {'data': [1, 3], 'some':[1, 2], 'hello': [1], 'world': [3]})
     files = ['doc1', 'doc2', 'doc3', 'doc4']
     query = 'data. some hello this is wrong query !'
     with mock.patch('model.index.Config', autospec=True, spec_set=True) as mock_config:
         mock_config.return_value.remove_stopwords.return_value = False
         mock_config.return_value.language.return_value = 'english'
         mock_config.return_value.use_stemming.return_value = False
         idx = Index()
         idx._index = index
         idx._files = files
         with self.assertRaises(ValueError):
             result = idx.get_result_for_query(query)
예제 #2
0
 def test_query_with_stemming_enabled(self):
     index = defaultdict(list, {'continuo': [1, 3], 'cycl':[1, 2], 'hello': [1], 'world': [3]})
     files = ['doc1', 'doc2', 'doc3', 'doc4']
     query = 'continuos && cycling'
     expected = ['doc1']
     with mock.patch('model.index.Config', autospec=True, spec_set=True) as mock_config:
         mock_config.return_value.remove_stopwords.return_value = False
         mock_config.return_value.language.return_value = 'english'
         mock_config.return_value.use_stemming.return_value = True
         idx = Index()
         idx._index = index
         idx._files = files
         assert idx.get_result_for_query(query) == expected
예제 #3
0
 def test_empty_query(self):
     index = defaultdict(list, {'data': [1, 3], 'some':[1, 2], 'hello': [1], 'world': [3]})
     files = ['doc1', 'doc2', 'doc3', 'doc4']
     query = ''
     expected = None
     with mock.patch('model.index.Config', autospec=True, spec_set=True) as mock_config:
         mock_config.return_value.remove_stopwords.return_value = False
         mock_config.return_value.language.return_value = 'english'
         mock_config.return_value.use_stemming.return_value = False
         idx = Index()
         idx._index = index
         idx._files = files
         assert idx.get_result_for_query(query) == expected