Ejemplo n.º 1
0
 def test_check_rules_simple(self):
     comment = None  # Comment features aren't used by this test.
     scores = {'TOXICITY': 0.9}
     rules = [
         Rule('hi_tox', {'TOXICITY': '> 0.5'}, {}, 'report'),
     ]
     actions = check_rules(comment, rules, scores)
     self.assertEqual(['report'], actions.keys())
     self.assertEqual(['hi_tox'], [r.name for r in actions['report']])
Ejemplo n.º 2
0
 def test_check_rules_multiple_actions(self):
     comment = None  # Comment features aren't used by this test.
     scores = {'TOXICITY': 0.9, 'THREAT': 0.2}
     rules = [
         Rule('hi_tox', {'TOXICITY': '> 0.5'}, {}, 'report'),
         Rule('hi_threat', {'THREAT': '> 0.9'}, {}, 'report'),
         Rule('med_threat', {'THREAT': '> 0.1'}, {}, 'noop'),
     ]
     actions = check_rules(comment, rules, scores)
     self.assertEqual(['noop', 'report'], sorted(actions.keys()))
     self.assertEqual(['hi_tox'], [r.name for r in actions['report']])
     self.assertEqual(['med_threat'], [r.name for r in actions['noop']])
Ejemplo n.º 3
0
 def test_create_mod_comment_output_record_more_rules(self):
     comment = MockComment('hello')
     scores = {'TOXICITY': 0.8}
     hi_tox_rule = Rule('hi_tox', {'TOXICITY': '> 0.9'}, {}, 'report')
     med_tox_rule = Rule('med_tox', {'TOXICITY': '> 0.5'}, {}, 'report')
     lo_tox_rule = Rule('lo_tox', {'TOXICITY': '> 0.1'}, {}, 'noop')
     rules = [hi_tox_rule, med_tox_rule, lo_tox_rule]
     action_dict = check_rules(comment, rules, scores)
     record = create_mod_comment_output_record(comment, 'hello', scores,
                                               action_dict, rules)
     self.assertEqual('rule-not-triggered', record['rule:hi_tox'])
     self.assertEqual('report', record['rule:med_tox'])
     self.assertEqual('noop', record['rule:lo_tox'])
Ejemplo n.º 4
0
 def test_create_mod_comment_output_record_basic(self):
     comment = MockComment('hello')
     scores = {'TOXICITY': 0.8}
     hi_tox_rule = Rule('hi_tox', {'TOXICITY': '> 0.5'}, {}, 'report')
     rules = [hi_tox_rule]
     action_dict = check_rules(comment, rules, scores)
     record = create_mod_comment_output_record(comment, 'hello', scores,
                                               action_dict, rules)
     self.assertEqual('hello', record['orig_comment_text'])
     # This field is only present when different from the comment body.
     self.assertFalse('scored_comment_text' in record)
     self.assertEqual(0.8, record['score:TOXICITY'])
     self.assertEqual('report', record['rule:hi_tox'])
Ejemplo n.º 5
0
 def test_check_rules_multiple_triggered_rules(self):
     comment = None  # Comment features aren't used by this test.
     # hi_tox and hi_spam are triggered, but not hi_threat.
     scores = {'TOXICITY': 0.9, 'SPAM': 0.9, 'THREAT': 0.2}
     rules = [
         Rule('hi_tox', {'TOXICITY': '> 0.5'}, {}, 'report'),
         Rule('hi_spam', {'SPAM': '> 0.5'}, {}, 'report'),
         Rule('hi_threat', {'THREAT': '> 0.5'}, {}, 'report'),
     ]
     actions = check_rules(comment, rules, scores)
     self.assertEqual(['report'], actions.keys())
     self.assertEqual(['hi_tox', 'hi_spam'],
                      [r.name for r in actions['report']])