-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtest_profanity_noboundries.py
38 lines (28 loc) · 1.11 KB
/
test_profanity_noboundries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from profanityfilter import ProfanityFilter
import unittest
pf = ProfanityFilter(no_word_boundaries=True)
TEST_STATEMENT = "Hey, my efuckingmail is [email protected]"
CENSORED_STATEMENT = "Hey, my e*******mail is ****you****@*****.com"
CLEAN_STATEMENT = "Hey there, I like chocolate too mate."
def update_censored(pf_instance=pf):
global censored
censored = pf_instance.censor(TEST_STATEMENT)
class TestProfanity(unittest.TestCase):
def setUp(self):
global censored
# Only to restore the default censor char
pf.set_censor("*")
pf.restore_words()
def test_checks(self):
self.assertTrue(pf.is_profane(TEST_STATEMENT))
self.assertFalse(pf.is_clean(TEST_STATEMENT))
self.assertTrue(pf.is_clean(CLEAN_STATEMENT))
self.assertFalse(pf.is_profane(CLEAN_STATEMENT))
def test_censor(self):
update_censored()
self.assertEqual(censored, CENSORED_STATEMENT)
pf.set_censor("#")
update_censored()
self.assertEqual(censored, CENSORED_STATEMENT.replace("*", "#"))
if __name__ == "__main__":
unittest.main()