1
|
|
|
import unittest |
2
|
|
|
from namebot import techniques |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class DomainifyTestCase(unittest.TestCase): |
6
|
|
|
|
7
|
|
|
def test_threeletter(self): |
8
|
|
|
self.assertEqual(techniques.domainify(['intercom']), ['inter.com']) |
9
|
|
|
|
10
|
|
|
def test_twoletter(self): |
11
|
|
|
self.assertEqual( |
12
|
|
|
techniques.domainify(['actively'], tld='.ly'), ['active.ly']) |
13
|
|
|
|
14
|
|
|
def test_fourletter(self): |
15
|
|
|
self.assertEqual( |
16
|
|
|
techniques.domainify(['scamp'], tld='.camp'), ['s.camp']) |
17
|
|
|
|
18
|
|
|
def test_empty(self): |
19
|
|
|
self.assertEqual( |
20
|
|
|
techniques.domainify(['intercom'], tld=''), ['intercom']) |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class PalindromeTestCase(unittest.TestCase): |
24
|
|
|
|
25
|
|
|
def test_simple(self): |
26
|
|
|
self.assertEqual(techniques.palindrome('Fool'), 'FoollooF') |
27
|
|
|
|
28
|
|
|
def test_complicated(self): |
29
|
|
|
self.assertEqual(techniques.palindrome( |
30
|
|
|
'Aardvarks'), 'AardvarksskravdraA') |
31
|
|
|
|
32
|
|
|
def test_spaced(self): |
33
|
|
|
self.assertEqual(techniques.palindrome( |
34
|
|
|
'Red Dragon'), 'Red DragonnogarD deR') |
35
|
|
|
|
36
|
|
|
def test_simple_array(self): |
37
|
|
|
self.assertEqual(techniques.palindromes( |
38
|
|
|
['foo', 'bar']), ['foooof', 'barrab']) |
39
|
|
|
|
40
|
|
|
def test_single_letter(self): |
41
|
|
|
self.assertEqual(techniques.palindrome('f'), 'ff') |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
class SpoonerismTestCase(unittest.TestCase): |
45
|
|
|
|
46
|
|
|
def test_simple(self): |
47
|
|
|
self.assertEqual( |
48
|
|
|
techniques.spoonerism(['flim', 'boom', 'dang', 'dune']), |
49
|
|
|
['blim foom', 'doom bang', 'dang dune']) |
50
|
|
|
|
51
|
|
|
def test_single_word(self): |
52
|
|
|
with self.assertRaises(ValueError): |
53
|
|
|
self.assertEqual(techniques.spoonerism(['foo'])) |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
class KniferismTestCase(unittest.TestCase): |
57
|
|
|
|
58
|
|
|
def test_simple(self): |
59
|
|
|
self.assertEqual( |
60
|
|
|
techniques.kniferism(['flim', 'boom', 'dang', 'dune']), |
61
|
|
|
['flom boim', 'bonm daog', 'dang dune']) |
62
|
|
|
|
63
|
|
|
def test_single_word(self): |
64
|
|
|
with self.assertRaises(ValueError): |
65
|
|
|
self.assertEqual(techniques.kniferism(['foo'])) |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
class ForkerismTestCase(unittest.TestCase): |
69
|
|
|
|
70
|
|
|
def test_simple(self): |
71
|
|
|
self.assertEqual( |
72
|
|
|
techniques.forkerism(['flim', 'boom', 'dang', 'dune']), |
73
|
|
|
['flim boom', 'boog danm', 'dane dung']) |
74
|
|
|
|
75
|
|
|
def test_single_word(self): |
76
|
|
|
with self.assertRaises(ValueError): |
77
|
|
|
self.assertEqual(techniques.forkerism(['foo'])) |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
class ReduplicationAblautTestCase(unittest.TestCase): |
81
|
|
|
|
82
|
|
|
def test_vowel_a(self): |
83
|
|
|
self.assertEqual(techniques.reduplication_ablaut( |
84
|
|
|
['cat', 'dog'], random=False, vowel='a'), ['dog dag']) |
85
|
|
|
|
86
|
|
|
def test_vowel_e(self): |
87
|
|
|
self.assertEqual(techniques.reduplication_ablaut( |
88
|
|
|
['cat', 'dog'], random=False, vowel='e'), |
89
|
|
|
['cat cet', 'dog deg']) |
90
|
|
|
|
91
|
|
|
def test_vowel_i(self): |
92
|
|
|
self.assertEqual(techniques.reduplication_ablaut( |
93
|
|
|
['cat', 'dog'], random=False, vowel='i'), |
94
|
|
|
['cat cit', 'dog dig']) |
95
|
|
|
|
96
|
|
|
def test_vowel_o(self): |
97
|
|
|
self.assertEqual(techniques.reduplication_ablaut( |
98
|
|
|
['cat', 'dog'], random=False, vowel='o'), ['cat cot']) |
99
|
|
|
|
100
|
|
|
def test_vowel_u(self): |
101
|
|
|
self.assertEqual(techniques.reduplication_ablaut( |
102
|
|
|
['cat', 'dog'], random=False, vowel='u'), |
103
|
|
|
['cat cut', 'dog dug']) |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
class AffixWordsTestCase(unittest.TestCase): |
107
|
|
|
|
108
|
|
|
def setUp(self): |
109
|
|
|
self.words = ['shop'] |
110
|
|
|
|
111
|
|
|
def test_prefix(self): |
112
|
|
|
res = techniques.prefixify(self.words) |
113
|
|
|
self.assertEqual(res[:3], ['ennishop', 'epishop', 'equishop']) |
114
|
|
|
|
115
|
|
|
def test_suffix(self): |
116
|
|
|
res = techniques.suffixify(self.words) |
117
|
|
|
self.assertEqual(res[:3], ['shopage', 'shopable', 'shopible']) |
118
|
|
|
|
119
|
|
|
def test_duplifix(self): |
120
|
|
|
res = techniques.duplifixify(self.words) |
121
|
|
|
self.assertEqual(res[:3], ['shop ahop', 'shop bhop', 'shop chop']) |
122
|
|
|
|
123
|
|
|
def test_duplifix_duplicates(self): |
124
|
|
|
res = techniques.duplifixify(self.words) |
125
|
|
|
self.assertTrue('shop shop' not in res) |
126
|
|
|
|
127
|
|
|
def test_infix(self): |
128
|
|
|
# TODO |
129
|
|
|
pass |
130
|
|
|
|
131
|
|
|
def test_disfix(self): |
132
|
|
|
# TODO |
133
|
|
|
pass |
134
|
|
|
|
135
|
|
|
def test_simulfix(self): |
136
|
|
|
res = techniques.simulfixify(self.words) |
137
|
|
|
self.assertIsInstance(res, list) |
138
|
|
|
self.assertGreater(len(res), len(self.words)) |
139
|
|
|
# Confirm that the pairs were added to each word |
140
|
|
|
for word in res: |
141
|
|
|
self.assertEqual(len(self.words[0]) + 2, len(word)) |
142
|
|
|
|
143
|
|
|
def test_simulfix_custom_pairs(self): |
144
|
|
|
res = techniques.simulfixify(self.words, pairs=['ab', 'ec', 'oz']) |
145
|
|
|
self.assertEqual(res, ['shabop', 'shecop', 'shozop']) |
146
|
|
|
|
147
|
|
|
def test_simulfix_empty_strings(self): |
148
|
|
|
res = techniques.simulfixify(['', ''], pairs=['ab', 'ec']) |
149
|
|
|
self.assertEqual(res, ['ab', 'ec', 'ab', 'ec']) |
150
|
|
|
|
151
|
|
|
def test_simulfix_short_words(self): |
152
|
|
|
res = techniques.simulfixify(['f', 'b', 'a'], pairs=['ab', 'ec']) |
153
|
|
|
expected = ['abf', 'ecf', 'abb', 'ecb', 'aba', 'eca'] |
154
|
|
|
self.assertEqual(res, expected) |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
class MakeFounderProductNameTestCase(unittest.TestCase): |
158
|
|
|
|
159
|
|
|
def test_simple(self): |
160
|
|
|
self.assertEqual( |
161
|
|
|
techniques.make_founder_product_name( |
162
|
|
|
'Foo', 'Bar', 'Goods'), 'F & B Goods') |
163
|
|
|
|
164
|
|
|
def test_simple_lowercase(self): |
165
|
|
|
self.assertNotEqual( |
166
|
|
|
techniques.make_founder_product_name( |
167
|
|
|
'Foo', 'Bar', 'Goods'), 'foo bar & co goods') |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
class MakeNameAlliterationTestCase(unittest.TestCase): |
171
|
|
|
|
172
|
|
|
def test_simple(self): |
173
|
|
|
original = ['jamba', 'juice', 'dancing', 'tornado', |
174
|
|
|
'disco', 'wicked', 'tomato'] |
175
|
|
|
updated = ['dancing disco', 'disco dancing', 'jamba juice', |
176
|
|
|
'juice jamba', 'tomato tornado', 'tornado tomato'] |
177
|
|
|
self.assertEqual( |
178
|
|
|
techniques.make_name_alliteration(original), updated) |
179
|
|
|
|
180
|
|
|
def test_divider(self): |
181
|
|
|
original = ['content', 'applesauce', 'candor', 'character'] |
182
|
|
|
updated = ['candor & character', 'candor & content', |
183
|
|
|
'character & candor', 'character & content', |
184
|
|
|
'content & candor', 'content & character'] |
185
|
|
|
self.assertEqual( |
186
|
|
|
techniques.make_name_alliteration( |
187
|
|
|
original, divider=' & '), updated) |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
class MakeNameAbbreviationTestCase(unittest.TestCase): |
191
|
|
|
|
192
|
|
|
def test_simple(self): |
193
|
|
|
self.assertEqual( |
194
|
|
|
techniques.make_name_abbreviation( |
195
|
|
|
['Badische', 'Anilin', 'Soda', 'Fabrik']), 'BASF') |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
class MakeVowelTestCase(unittest.TestCase): |
199
|
|
|
|
200
|
|
|
def test_a(self): |
201
|
|
|
self.assertEqual(techniques.make_vowel( |
202
|
|
|
['brad', 'angelina'], r'a{1}', 'a'), ['brangelina']) |
203
|
|
|
|
204
|
|
|
def test_e(self): |
205
|
|
|
self.assertEqual(techniques.make_vowel( |
206
|
|
|
['street', 'credence'], r'e{1}', 'e'), ['stredence']) |
207
|
|
|
|
208
|
|
|
def test_i(self): |
209
|
|
|
self.assertEqual(techniques.make_vowel( |
210
|
|
|
['stripe', 'wild'], r'i{1}', 'i'), ['strild']) |
211
|
|
|
|
212
|
|
|
def test_o(self): |
213
|
|
|
self.assertEqual(techniques.make_vowel( |
214
|
|
|
['strode', 'pork'], r'o{1}', 'o'), ['strork']) |
215
|
|
|
|
216
|
|
|
def test_u(self): |
217
|
|
|
self.assertEqual(techniques.make_vowel( |
218
|
|
|
['true', 'crude'], r'u{1}', 'u'), ['trude']) |
219
|
|
|
|
220
|
|
|
def test_no_substring(self): |
221
|
|
|
"""Check for values that aren't found in the regex list.""" |
222
|
|
|
self.assertEqual(techniques.make_vowel( |
223
|
|
|
['matching', 'not'], r'a{1}', 'a'), []) |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
class MakePortmanteauDefaultVowelTestCase(unittest.TestCase): |
227
|
|
|
|
228
|
|
|
def test_simple(self): |
229
|
|
|
self.assertEqual( |
230
|
|
|
techniques.make_portmanteau_default_vowel( |
231
|
|
|
['sweet', 'potato', 'nifty', 'gadget', 'widgets']), |
232
|
|
|
['potadget', 'gadgeet', 'widgeet']) |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
class MakemakePortmanteauSplitTestCase(unittest.TestCase): |
236
|
|
|
|
237
|
|
|
def test_2words(self): |
238
|
|
|
self.assertEqual( |
239
|
|
|
techniques.make_portmanteau_split(['dad', 'cool']), |
240
|
|
|
['dadool', 'dadool', 'datool', 'dasool', 'dazool', |
241
|
|
|
'daxool', 'cocad', 'coad', 'colad', 'cotad', |
242
|
|
|
'cosad', 'cozad', 'coxad']) |
243
|
|
|
|
244
|
|
|
def test_results_count(self): |
245
|
|
|
self.assertEqual( |
246
|
|
|
len(techniques.make_portmanteau_split( |
247
|
|
|
['dad', 'neat', 'cool'])), 40) |
248
|
|
|
self.assertEqual( |
249
|
|
|
len(techniques.make_portmanteau_split( |
250
|
|
|
['dad', 'neat', 'cool', 'nifty'])), 58) |
251
|
|
|
self.assertEqual( |
252
|
|
|
len(techniques.make_portmanteau_split( |
253
|
|
|
['dad', 'neat', 'cool', 'nifty', 'super', 'duper'])), 166) |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
class MakePunctuatorTestCase(unittest.TestCase): |
257
|
|
|
|
258
|
|
|
def test_simple(self): |
259
|
|
|
self.assertEqual( |
260
|
|
|
techniques.make_punctuator(['delicious'], 'i'), |
261
|
|
|
['deli-ci-ous', 'deli.ci.ous']) |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
class MakeVowelifyTestCase(unittest.TestCase): |
265
|
|
|
|
266
|
|
|
def test_simple(self): |
267
|
|
|
self.assertEqual( |
268
|
|
|
techniques.make_vowelify( |
269
|
|
|
['nautical', 'monster']), ['nautica', 'monste']) |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
class MakemisspellingTestCase(unittest.TestCase): |
273
|
|
|
|
274
|
|
|
def setUp(self): |
275
|
|
|
self.words = ['effects', 'phonics', 'glee', 'cron', 'chrono'] |
276
|
|
|
self.expected = ['phonix', 'ephphects', 'gly', 'crawn', 'krono'] |
277
|
|
|
|
278
|
|
|
def test_simple(self): |
279
|
|
|
res = techniques.make_misspelling(self.words) |
280
|
|
|
for word in self.expected: |
281
|
|
|
assert word in res |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
class PigLatinTestCase(unittest.TestCase): |
285
|
|
|
|
286
|
|
|
def test_simple(self): |
287
|
|
|
"""Basic test.""" |
288
|
|
|
self.assertEqual( |
289
|
|
|
techniques.pig_latinize(['rad']), ['adray']) |
290
|
|
|
|
291
|
|
|
def test_custom_postfix_value(self): |
292
|
|
|
"""Basic test.""" |
293
|
|
|
self.assertEqual( |
294
|
|
|
techniques.pig_latinize(['rad'], postfix='ey'), ['adrey']) |
295
|
|
|
|
296
|
|
|
def test_bad_postfix_value(self): |
297
|
|
|
"""Basic test.""" |
298
|
|
|
with self.assertRaises(TypeError): |
299
|
|
|
techniques.pig_latinize(['rad'], postfix=1223) |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
class AcronymLastnameTestCase(unittest.TestCase): |
303
|
|
|
|
304
|
|
|
def test_simple(self): |
305
|
|
|
desc = 'Amazingly cool product' |
306
|
|
|
self.assertEqual( |
307
|
|
|
'ACP McDonald', techniques.acronym_lastname(desc, 'McDonald')) |
308
|
|
|
|
309
|
|
|
def test_simple_nostopwords(self): |
310
|
|
|
desc = 'A cool product' |
311
|
|
|
self.assertEqual( |
312
|
|
|
'CP McDonald', techniques.acronym_lastname(desc, 'McDonald')) |
313
|
|
|
|
314
|
|
|
|
315
|
|
|
class GetDescriptorsTestCase(unittest.TestCase): |
316
|
|
|
|
317
|
|
|
def test_complex(self): |
318
|
|
|
self.assertEqual(techniques.get_descriptors( |
319
|
|
|
['Jumping', 'Fly', 'Monkey', 'Dog', 'Action']), |
320
|
|
|
{'VBG': ['Jumping'], |
321
|
|
|
'NNP': ['Fly', 'Monkey', 'Dog', 'Action']}) |
322
|
|
|
|
323
|
|
|
|
324
|
|
|
class MakeDescriptorsTestCase(unittest.TestCase): |
325
|
|
|
|
326
|
|
|
def test_simple(self): |
327
|
|
|
self.assertEqual(techniques.make_descriptors( |
328
|
|
|
{'VBG': ['Jumping'], 'RB': ['Fly'], |
329
|
|
|
'NNP': ['Monkey', 'Dog', 'Action']}), |
330
|
|
|
['Monkey Fly', 'Fly Monkey', 'Action Fly', 'Dog Fly', |
331
|
|
|
'Fly Dog', 'Fly Action']) |
332
|
|
|
|
333
|
|
|
|
334
|
|
|
class AllPrefixesToFirstVowelTestCase(unittest.TestCase): |
335
|
|
|
|
336
|
|
|
def test_simple(self): |
337
|
|
|
word = 'umbrellas' |
338
|
|
|
expected = [ |
339
|
|
|
'Bumbrellas', 'Cumbrellas', 'Dumbrellas', 'Fumbrellas', |
340
|
|
|
'Gumbrellas', 'Humbrellas', 'Jumbrellas', 'Kumbrellas', |
341
|
|
|
'Lumbrellas', 'Mumbrellas', 'Numbrellas', 'Pumbrellas', |
342
|
|
|
'Qumbrellas', 'Rumbrellas', 'Sumbrellas', 'Tumbrellas', |
343
|
|
|
'Vumbrellas', 'Wumbrellas', 'Xumbrellas', 'Yumbrellas', |
344
|
|
|
'Zumbrellas'] |
345
|
|
|
self.assertEqual(techniques.all_prefix_first_vowel(word), expected) |
346
|
|
|
|
347
|
|
|
|
348
|
|
|
class RecycleTestCase(unittest.TestCase): |
349
|
|
|
|
350
|
|
|
def test_pig_latinize(self): |
351
|
|
|
words = techniques.pig_latinize(['purring', 'cats']) |
352
|
|
|
self.assertEqual(techniques.recycle( |
353
|
|
|
words, techniques.pig_latinize), |
354
|
|
|
['urringpaywayway', 'atscaywayway']) |
355
|
|
|
|
356
|
|
|
def test_portmanteau(self): |
357
|
|
|
words = ['ratchet', 'broccoli', 'potato', 'gadget', 'celery', 'hammer'] |
358
|
|
|
res = techniques.recycle( |
359
|
|
|
words, techniques.make_portmanteau_default_vowel) |
360
|
|
|
expected = ['potatchelery', 'potatchelery', 'potadgelery', |
361
|
|
|
'potadgelery', 'potammelery', 'potammelery', |
362
|
|
|
'ratchelery', 'ratchelery'] |
363
|
|
|
self.assertEqual(res, expected) |
364
|
|
|
|
365
|
|
|
|
366
|
|
|
class SuperScrubTestCase(unittest.TestCase): |
367
|
|
|
|
368
|
|
|
def test_uniq(self): |
369
|
|
|
data = {'words': {'technique': ['words', 'words']}} |
370
|
|
|
self.assertEqual( |
371
|
|
|
techniques.super_scrub(data)['words']['technique'], ['words']) |
372
|
|
|
|
373
|
|
|
def test_remove_odd(self): |
374
|
|
|
data = {'words': {'technique': ['asdsaasdokokk', 'words']}} |
375
|
|
|
self.assertEqual( |
376
|
|
|
techniques.super_scrub(data)['words']['technique'], ['words']) |
377
|
|
|
|
378
|
|
|
def test_cleansort(self): |
379
|
|
|
data = {'words': {'technique': ['!!@words', 'radio0']}} |
380
|
|
|
self.assertEqual( |
381
|
|
|
techniques.super_scrub(data)['words']['technique'], |
382
|
|
|
['radio', 'words']) |
383
|
|
|
|