Esempio n. 1
0
 def test_by_feature(self):
     instance = MockRankProcessor({
         "identifier_key": self.identifier_key,
         "feature_frame_path": self.frame_path,
         "ranking_feature": "rank_by_value",
         "result_size": 2
     })
     content_iterator = Mock(
         return_value=(
             Mock(
                 spec_set=Individual,
                 properties=content,
                 content=content,
                 identity=content[self.identifier_key],
                 __getitem__=Individual.__getitem__
             )
             for content in self.test_content
         )
     )
     query_set = Mock(
         spec_set=QuerySet,
         count=Mock(return_value=len(self.test_content)),
         iterator=content_iterator,
         filter=content_iterator
     )
     ranking = instance.by_feature(query_set)
     self.assertTrue(issubclass(ranking.__class__, Iterator))
     ranking = self.assert_ranking(ranking, 2, ['rank_by_value'])
     # Check order of results
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['highest', 'highest-of-triple'], "Order of ranked dictionaries is not correct.")
     self.skipTest("Rewrite with real query set instead of a mock")
Esempio n. 2
0
 def test_hook_none_value(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$i_think_none_of_it": 1
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['lowest', 'lowest-2'],
                      "Order of ranked dictionaries is not correct.")
Esempio n. 3
0
 def test_invalid_hook_weight(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": "makes no sense"
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['lowest', 'lowest-2'],
                      "Order of ranked dictionaries is not correct.")
Esempio n. 4
0
 def test_floats_as_values(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1,
         "$ban_highest": 1
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['double-1', 'double-2'],
                      "Order of ranked dictionaries is not correct.")
Esempio n. 5
0
 def test_boolean_ranking(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$is_highest": 1
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['highest', 'highest-of-triple'],
                      "Order of ranked dictionaries is not correct.")
     self.assertEqual(ranking[0]["ds_rank"]["rank"],
                      ranking[1]["ds_rank"]["rank"])
Esempio n. 6
0
 def test_ranking_with_one_hook(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1
     })
     ranking = instance.hooks(self.test_content)
     self.assertTrue(issubclass(ranking.__class__, Iterator))
     ranking = self.assert_ranking(ranking, 2, ['rank_by_value'])
     # Check order of results
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['highest', 'highest-of-triple'],
                      "Order of ranked dictionaries is not correct.")
Esempio n. 7
0
 def test_ranking_with_multiple_hooks(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1,
         "$is_double": 2
     })
     ranking = instance.hooks(self.test_content)
     self.assertTrue(issubclass(ranking.__class__, Iterator))
     ranking = self.assert_ranking(ranking, 2,
                                   ['rank_by_value', 'is_double'])
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['double-1', 'double-2'],
                      "Order of ranked dictionaries is not correct.")
Esempio n. 8
0
 def setUpClass(cls):
     for forbidden_feature in cls.blacklist_features:
         setattr(cls, forbidden_feature, getattr(MockRankProcessor, forbidden_feature))
         setattr(MockRankProcessor, forbidden_feature, None)
     frame = NumericFeaturesFrame(
         lambda content: content[cls.identifier_key],
         MockRankProcessor.get_features(),
         lambda: cls.test_content
     )
     frame.to_disk(cls.frame_path)
Esempio n. 9
0
 def test_order(self, islice_patch):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1
     })
     instance.hooks(self.test_content)
     islice_patch.assert_called_once()
     args, kwargs = islice_patch.call_args
     order = list(args[0])
     order_keys = list(map(itemgetter('name'), order))
     self.assertEqual(
         order_keys, [
             'highest', 'highest-of-triple', 'double-1', 'double-2',
             'lowest-included', 'lowest'
         ],
         "Order of ranked dictionaries is not correct or splitting it batches did not work."
     )
     self.assertEqual(args[1], 2, "Slice should be the size of the result")