Example #1
0
 def test_no_hooks(self):
     instance = MockLegacyRankProcessor({
         "result_size": 2,
         "batch_size": 3
     })
     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.")
Example #2
0
 def test_invalid_hook_weight(self):
     instance = MockLegacyRankProcessor({
         "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.")
Example #3
0
 def test_floats_as_values(self):
     instance = MockLegacyRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1,
         "$ban_highest": 10
     })
     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.")
Example #4
0
 def test_boolean_ranking(self):
     instance = MockLegacyRankProcessor({
         "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]["_rank"]["rank"], ranking[1]["_rank"]["rank"])
Example #5
0
 def test_negative_weights(self):
     instance = MockLegacyRankProcessor({
         "result_size": 3,
         "batch_size": 4,
         "$rank_by_value": 1,
         "$is_highest": -10
     })
     ranking = instance.hooks(self.test_content)
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['double-1', 'double-2', 'under-double'], "Order of ranked dictionaries is not correct.")
Example #6
0
 def test_floats_as_weights(self):
     instance = MockLegacyRankProcessor({
         "result_size": 3,
         "batch_size": 4,
         "$rank_by_value": 1,
         "$is_highest": 0.8
     })
     ranking = instance.hooks(self.test_content)
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['highest', 'highest-of-triple', 'double-1'], "Order of ranked dictionaries is not correct.")
Example #7
0
 def test_ranking_with_multiple_hooks(self):
     instance = MockLegacyRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1,
         "$is_double": 5
     })
     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.")
Example #8
0
 def test_ranking_with_one_hook(self):
     instance = MockLegacyRankProcessor({
         "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.")
Example #9
0
 def test_order(self, islice_patch):
     instance = MockLegacyRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1
     })
     instance.hooks(self.test_content)
     self.assertEqual(islice_patch.call_count, 1)
     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")