-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
executable file
·99 lines (85 loc) · 3.44 KB
/
test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python3
import unittest
import owo
str = "123456789"
affix = ("abcdefg",)
subs = {
"l": "w",
"lllll": "wwwww",
"r": "w",
"rrrrr": "wwwww",
"rlrlrl": "wwwwww",
"notification": "nutification",
"MPs reject Theresa May's revised EU withdrawal deal, throwing UK's Brexit plans into confusion":
"MPs weject Thewesa May's wevised EU withdwawaw deaw, thwowing UK's Bwexit pwans into confusion"
}
class TestOwO(unittest.TestCase):
def test_constants(self):
self.assertIsInstance(owo.SUBSTITUTIONS, dict)
self.assertIsInstance(owo.PREFIXES, tuple)
self.assertIsInstance(owo.SUFFIXES, tuple)
def test_substitution(self):
for x in subs:
self.assertEqual(owo.substitute(x), subs[x])
with self.assertRaises(TypeError):
owo.substitute(30)
with self.assertRaises(TypeError):
owo.substitute(str, substitutions=30)
with self.assertRaises(TypeError):
owo.substitute(str, substitutions="string")
self.assertEqual(owo.substitute(
str, substitutions={"123": "xyz"}), "xyz456789")
def test_affixes(self):
self.assertTrue(len(owo.add_affixes(str)) >= len(str))
self.assertEqual(owo.add_affixes(str, prefixes=affix,
suffixes=affix), "abcdefg123456789abcdefg")
with self.assertRaises(TypeError):
owo.add_affixes(30)
with self.assertRaises(TypeError):
owo.add_affixes(str, prefixes=30)
with self.assertRaises(TypeError):
owo.add_affixes(str, prefixes="string")
with self.assertRaises(TypeError):
owo.add_affixes(str, suffixes=30)
with self.assertRaises(TypeError):
owo.add_affixes(str, suffixes="string")
def test_prefixes(self):
self.assertTrue(len(owo.add_prefix(str)) >= len(str))
self.assertEqual(owo.add_prefix(
str, prefixes=affix), "abcdefg123456789")
with self.assertRaises(TypeError):
owo.add_prefix(30)
with self.assertRaises(TypeError):
owo.add_prefix(str, prefixes=30)
with self.assertRaises(TypeError):
owo.add_prefix(str, prefixes="string")
def test_suffixes(self):
self.assertTrue(len(owo.add_suffix(str)) >= len(str))
self.assertEqual(owo.add_suffix(
str, suffixes=affix), "123456789abcdefg")
with self.assertRaises(TypeError):
owo.add_suffix(30)
with self.assertRaises(TypeError):
owo.add_suffix(str, suffixes=30)
with self.assertRaises(TypeError):
owo.add_suffix(str, suffixes="string")
def test_owo(self):
with self.assertRaises(TypeError):
owo.owo(30)
with self.assertRaises(TypeError):
owo.owo(str, substitutions=30)
with self.assertRaises(TypeError):
owo.owo(str, substitutions="string")
with self.assertRaises(TypeError):
owo.owo(str, prefixes=30)
with self.assertRaises(TypeError):
owo.owo(str, prefixes="string")
with self.assertRaises(TypeError):
owo.owo(str, suffixes=30)
with self.assertRaises(TypeError):
owo.owo(str, suffixes="string")
self.assertEqual(owo.owo(str, prefixes=affix, suffixes=affix, substitutions={
"123": "xyz"}), "abcdefgxyz456789abcdefg")
if __name__ == '__main__':
# Main module
unittest.main()