class TestSpam(TestCase):
    def test_too_short(self):
        self.env = FakeEnv(80, 10, 30)
        self.spam = SpamClassifier(self.env, skip_loading=True)
        self.assertTrue(self.spam.too_long_or_too_short('a' * 5))

    def test_too_long(self):
        self.env = FakeEnv(80, 10, 30)
        self.spam = SpamClassifier(self.env, skip_loading=True)
        self.assertTrue(self.spam.too_long_or_too_short('a' * 35))

    def test_okay_length(self):
        self.env = FakeEnv(80, 10, 30)
        self.spam = SpamClassifier(self.env, skip_loading=True)
        self.assertFalse(self.spam.too_long_or_too_short('a' * 20))

    def test_is_spam(self):
        threshold = 0.8
        self.env = FakeEnv(threshold, 20, 150)
        self.spam = SpamClassifier(self.env)

        is_spam, y_hats = self.spam.is_spam(
            '[̲̅G̲̅][̲̅u̲̅][̲̅t̲̅][̲̅e̲̅][̲̅n̲̅] [̲̅M̲̅][̲̅o̲̅][̲̅r̲̅][̲̅g̲̅]a[̲̅h̲̅][̲̅n̲̅]'
        )

        above = 0
        for y_hat in y_hats:
            if y_hat > threshold:
                above += 1

        self.assertTrue(is_spam)
        self.assertTrue(above >= 2)
    def test_is_spam(self):
        threshold = 0.8
        self.env = FakeEnv(threshold, 20, 150)
        self.spam = SpamClassifier(self.env)

        is_spam, y_hats = self.spam.is_spam(
            '[̲̅G̲̅][̲̅u̲̅][̲̅t̲̅][̲̅e̲̅][̲̅n̲̅] [̲̅M̲̅][̲̅o̲̅][̲̅r̲̅][̲̅g̲̅]a[̲̅h̲̅][̲̅n̲̅]'
        )

        above = 0
        for y_hat in y_hats:
            if y_hat > threshold:
                above += 1

        self.assertTrue(is_spam)
        self.assertTrue(above >= 2)
Exemple #3
0
def init_spam_service(gn_env: GNEnvironment):
    if len(gn_env.config) == 0 or gn_env.config.get(ConfigKeys.TESTING, False):
        # assume we're testing
        return

    if not gn_env.config.get(ConfigKeys.SPAM_CLASSIFIER, default=False):
        return

    from dino.utils.spam import SpamClassifier
    gn_env.spam = SpamClassifier(gn_env)
 def test_okay_length(self):
     self.env = FakeEnv(80, 10, 30)
     self.spam = SpamClassifier(self.env, skip_loading=True)
     self.assertFalse(self.spam.too_long_or_too_short('a' * 20))
 def test_too_long(self):
     self.env = FakeEnv(80, 10, 30)
     self.spam = SpamClassifier(self.env, skip_loading=True)
     self.assertTrue(self.spam.too_long_or_too_short('a' * 35))