-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_word_tools.py
executable file
·258 lines (211 loc) · 8.38 KB
/
test_word_tools.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env python
"""
Unit tests for word_tools.py
"""
import unittest
import word_tools
class TestFindWords(unittest.TestCase):
def setUp(self): # noqa
self.setup_i_hate_the_word()
self.csv_file = "test_word_tools.csv"
def setup_i_hate_the_word(self):
self.search_term = "I hate the word"
self.target_word_follows_search_term = True
self.pattern = word_tools.get_pattern(
self.search_term, self.target_word_follows_search_term
)
def setup_aint_a_word(self):
self.search_term = "ain't a word"
self.target_word_follows_search_term = False
self.pattern = word_tools.get_pattern(
self.search_term, self.target_word_follows_search_term
)
def test_word1(self):
text = "I hate the word 'moist.'"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "moist")
def test_word2(self):
text = "I hate the word hun tf"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "hun")
def test_word3(self):
text = "“@BoobsNBamboos_: I hate the word hun tf” Sorry Hun."
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, None)
def test_word4(self):
text = "!!!! RT @BoobsNBamboos_: I hate the word hun tf"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, None)
def test_word5(self):
text = 'RT @MegannoConnor: I hate the word "swills"'
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, None)
def test_word6(self):
text = 'I hate the word "Bae". It makes you sound uneducated.'
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "bae")
def test_word7(self):
text = "Wow..I hate the word thot but that was funny."
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "thot")
def test_word8(self):
text = "Why I hate the word 'couture'?! #weird"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "couture")
def test_word9(self):
text = (
'I hate the word "spooky", bro the fuck you mean '
'" dis nigga movin spooky" sounds like some shaggy '
"n scooby doo type shit son"
)
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "spooky")
def test_word10(self):
text = 'I swear I hate the word “ flee " . . . .'
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "flee")
def test_word11(self):
text = "I HATE the word bae...." "it seems like you just too lazy to say babe"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "bae")
def test_word12(self):
text = "I hate the word YALL like im a conjoined twin"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "yall")
def test_word13(self):
text = "I hate the word 'Banter' it annoys me so much🙈"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "banter")
def test_word14(self):
text = "I hate the word madting"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "madting")
def test_word15(self):
text = (
"I hate the word ❌NO❌ like y'all nigga hate a bitch dat "
"uses her teeth on da dick."
)
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "no")
def test_word16(self):
text = (
"@QuayNastyy Lmao So What Would Call Me ? " "Cause I HATE The Word Boo ."
)
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "boo")
def test_word17(self):
text = "i hate the word expand"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertEqual(word, "expand")
def test_word18(self):
text = "i hate the word glove(s)"
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertNotEqual(word, "glove(s")
def test_word19(self):
# Arrange
self.setup_aint_a_word()
text = '"People(s)" ain\'t a word😒'
# Act
word = word_tools.word_from_text(text, self.pattern, self.search_term)
# Assert
self.assertNotEqual(word, "people(s")
def test_word20(self):
# Arrange
self.setup_aint_a_word()
text = '"You(s)"\nAin\'t a word either 😒"'
# Act
word = word_tools.word_from_text(text, self.pattern, self.search_term)
self.assertNotEqual(word, "you(s")
def test_load_words_from_csv_24_hours(self):
words = word_tools.load_words_from_csv(
self.csv_file, self.search_term, 24 * 60 * 60
)
self.assertIsInstance(words, list)
def test_load_words_from_csv_7_days(self):
words = word_tools.load_words_from_csv(
self.csv_file, self.search_term, 7 * 24 * 60 * 60
)
self.assertIsInstance(words, list)
def test_load_words_from_csv_30_days(self):
words = word_tools.load_words_from_csv(
self.csv_file, self.search_term, 30 * 24 * 60 * 60
)
self.assertIsInstance(words, list)
def test_load_words_from_csv_all_time(self):
# Arrange
search_term = "I love the word"
# Act
words = word_tools.load_words_from_csv(self.csv_file, search_term, None)
# Assert
self.assertIsInstance(words, list)
self.assertGreater(len(words), 0)
def test_tweet_from_csv(self):
# Arrange
# Don't actually tweet:
word_tools.TEST_MODE = True
search_term = "I love the word"
tweet_prefix = "Test: "
words = []
# Act
word_tools.tweet_those(
words, tweet_prefix, self.csv_file, search_term, "alltime"
)
# Assert
# No exceptions
def OFF_test_add_string_to_wordnik(self):
words = ["string"]
wordlist_permalink = "test--47"
word_tools.add_to_wordnik(words, wordlist_permalink)
def OFF_test_add_strings_to_wordnik(self):
words = ["string2", "string3"]
wordlist_permalink = "test--47"
word_tools.add_to_wordnik(words, wordlist_permalink)
def test_add_unicode_to_wordnik(self):
words = ["unicode"]
wordlist_permalink = "test--47"
word_tools.add_to_wordnik(words, wordlist_permalink)
def test_add_unicodes_to_wordnik(self):
words = ["unicode2", "unicode3"]
wordlist_permalink = "test--47"
word_tools.add_to_wordnik(words, wordlist_permalink)
def OFF_test_add_mix_to_wordnik(self):
words = ["string4", "unicode4"]
wordlist_permalink = "test--47"
word_tools.add_to_wordnik(words, wordlist_permalink)
def test_add_nothing_to_wordnik(self):
# Arrange
words = []
wordlist_permalink = "test--47"
# Act
word_tools.add_to_wordnik(words, wordlist_permalink)
# Assert
# No exceptions
def test_add_to_wordnik_test_mode(self):
# Arrange
words = ["one", "two"]
wordlist_permalink = "test--47"
# Enable test mode
word_tools.TEST_MODE = True
# Act
word_tools.add_to_wordnik(words, wordlist_permalink)
# Assert
# No exceptions
def test_pick_a_random_tweet(self):
# Arrange
search_term = "I love the word"
# Act
id = word_tools.pick_a_random_tweet(self.csv_file, search_term)
# Assert
self.assertIn(
id,
[
"462097300840796160",
"462096811738398720",
"462851899889164288",
"462854220165574656",
"462851899889164288",
],
)
if __name__ == "__main__":
unittest.main()
# End of file