forked from ppannuto/python-titlecase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
350 lines (327 loc) · 9.35 KB
/
Copy pathtests.py
File metadata and controls
350 lines (327 loc) · 9.35 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for titlecase"""
from __future__ import print_function, unicode_literals
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))
from titlecase import titlecase, set_small_word_list
TEST_DATA = (
(
"",
""
),
(
"word/word",
"Word/Word"
),
(
"a title and/or string",
"A Title and/or String"
),
(
"dance with me/let’s face the music and dance",
"Dance With Me/Let’s Face the Music and Dance"
),
(
"34th 3rd 2nd",
"34th 3rd 2nd"
),
(
"Q&A with steve jobs: 'that's what happens in technology'",
"Q&A With Steve Jobs: 'That's What Happens in Technology'"
),
(
"What is AT&T's problem?",
"What Is AT&T's Problem?"
),
(
"Apple deal with AT&T falls through",
"Apple Deal With AT&T Falls Through"
),
(
"this v that",
"This v That"
),
(
"this v. that",
"This v. That"
),
(
"this vs that",
"This vs That"
),
(
"this vs. that",
"This vs. That"
),
(
"The SEC's Apple probe: what you need to know",
"The SEC's Apple Probe: What You Need to Know"
),
(
"'by the Way, small word at the start but within quotes.'",
"'By the Way, Small Word at the Start but Within Quotes.'"
),
(
"Small word at end is nothing to be afraid of",
"Small Word at End Is Nothing to Be Afraid Of"
),
(
"Starting Sub-Phrase With a Small Word: a Trick, Perhaps?",
"Starting Sub-Phrase With a Small Word: A Trick, Perhaps?"
),
(
"Sub-Phrase With a Small Word in Quotes: 'a Trick, Perhaps?'",
"Sub-Phrase With a Small Word in Quotes: 'A Trick, Perhaps?'"
),
(
'sub-phrase with a small word in quotes: "a trick, perhaps?"',
'Sub-Phrase With a Small Word in Quotes: "A Trick, Perhaps?"'
),
(
"Starting a Hyphen Delimited Sub-Phrase With a Small Word - a Trick, Perhaps?",
"Starting a Hyphen Delimited Sub-Phrase With a Small Word - A Trick, Perhaps?"
),
(
"Hyphen Delimited Sub-Phrase With a Small Word in Quotes - 'a Trick, Perhaps?'",
"Hyphen Delimited Sub-Phrase With a Small Word in Quotes - 'A Trick, Perhaps?'"
),
(
'Hyphen Delimited sub-phrase with a small word in quotes - "a trick, perhaps?"',
'Hyphen Delimited Sub-Phrase With a Small Word in Quotes - "A Trick, Perhaps?"'
),
(
"Snakes on a Plane - The TV Edit - The Famous Line",
"Snakes on a Plane - The TV Edit - The Famous Line"
),
(
"Starting an Em Dash Delimited Sub-Phrase With a Small Word — a Trick, Perhaps?",
"Starting an Em Dash Delimited Sub-Phrase With a Small Word — A Trick, Perhaps?"
),
(
"Em Dash Delimited Sub-Phrase With a Small Word in Quotes — 'a Trick, Perhaps?'",
"Em Dash Delimited Sub-Phrase With a Small Word in Quotes — 'A Trick, Perhaps?'"
),
(
'Em Dash Delimited sub-phrase with a small word in quotes — "a trick, perhaps?"',
'Em Dash Delimited Sub-Phrase With a Small Word in Quotes — "A Trick, Perhaps?"'
),
(
"Snakes on a Plane — The TV Edit — The Famous Line",
"Snakes on a Plane — The TV Edit — The Famous Line"
),
(
"EPISODE 7 — THE FORCE AWAKENS",
"Episode 7 — The Force Awakens"
),
(
"episode 7 – The force awakens",
"Episode 7 – The Force Awakens"
),
(
"THE CASE OF X ≤ 7",
"The Case of X ≤ 7"
),
(
"the case of X ≤ 7",
"The Case of X ≤ 7"
),
(
'"Nothing to Be Afraid of?"',
'"Nothing to Be Afraid Of?"'
),
(
'"Nothing to be Afraid Of?"',
'"Nothing to Be Afraid Of?"'
),
(
'a thing',
'A Thing'
),
(
"2lmc Spool: 'gruber on OmniFocus and vapo(u)rware'",
"2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'"
),
(
'this is just an example.com',
'This Is Just an example.com'
),
(
'this is something listed on del.icio.us',
'This Is Something Listed on del.icio.us'
),
(
'iTunes should be unmolested',
'iTunes Should Be Unmolested'
),
(
'reading between the lines of steve jobs’s ‘thoughts on music’',
'Reading Between the Lines of Steve Jobs’s ‘Thoughts on Music’'
),
(
'seriously, ‘repair permissions’ is voodoo',
'Seriously, ‘Repair Permissions’ Is Voodoo'
),
(
'generalissimo francisco franco: still dead; kieren McCarthy: still a jackass',
'Generalissimo Francisco Franco: Still Dead; Kieren McCarthy: Still a Jackass'
),
(
"O'Reilly should be untouched",
"O'Reilly Should Be Untouched"
),
(
"my name is o'reilly",
"My Name Is O'Reilly"
),
(
"WASHINGTON, D.C. SHOULD BE FIXED BUT MIGHT BE A PROBLEM",
"Washington, D.C. Should Be Fixed but Might Be a Problem"
),
(
"THIS IS ALL CAPS AND SHOULD BE ADDRESSED",
"This Is All Caps and Should Be Addressed"
),
(
"Mr McTavish went to MacDonalds",
"Mr McTavish Went to MacDonalds"
),
(
"this shouldn't\nget mangled",
"This Shouldn't\nGet Mangled"
),
(
"this is http://foo.com",
"This Is http://foo.com"
),
(
"mac mc MAC MC machine",
"Mac Mc MAC MC Machine",
),
(
"FOO BAR 5TH ST",
"Foo Bar 5th St",
),
(
"foo bar 5th st",
"Foo Bar 5th St",
),
(
"l'grange l'grange l'Grange l'Grange",
"l'Grange l'Grange l'Grange l'Grange",
),
(
"L'grange L'grange L'Grange L'Grange",
"l'Grange l'Grange l'Grange l'Grange",
),
(
"l'GranGe",
"l'GranGe",
),
(
"o'grange O'grange o'Grange O'Grange",
"O'Grange O'Grange O'Grange O'Grange",
),
(
"o'grange's O'grange's o'Grange's O'Grange's",
"O'Grange's O'Grange's O'Grange's O'Grange's",
),
(
"O'GranGe",
"O'GranGe",
),
(
"o'melveny/o'doyle o'Melveny/o'doyle O'melveny/o'doyle o'melveny/o'Doyle o'melveny/O'doyle",
"O'Melveny/O'Doyle O'Melveny/O'Doyle O'Melveny/O'Doyle O'Melveny/O'Doyle O'Melveny/O'Doyle",
),
(
"oblon, spivak, mcclelland, maier & neustadt",
"Oblon, Spivak, McClelland, Maier & Neustadt",
),
(
"Mcoblon, spivak, mcclelland, mcmaier, & mcneustadt",
"McOblon, Spivak, McClelland, McMaier, & McNeustadt",
),
(
"mcfoo-bar, MCFOO-BAR, McFoo-bar, McFoo-Bar, mcfoo-mcbar, foo-mcbar",
"McFoo-Bar, McFoo-Bar, McFoo-Bar, McFoo-Bar, McFoo-McBar, Foo-McBar",
),
(
"'QUOTE' A GREAT",
"'Quote' a Great",
),
(
"‘QUOTE’ A GREAT",
"‘Quote’ a Great",
),
(
"“YOUNG AND RESTLESS”",
"“Young and Restless”",
),
(
"EL NIÑO A ARRIVÉ HIER",
"El Niño a Arrivé Hier",
),
(
"YEA NO",
"Yea No",
),
(
"ÝÆ ÑØ",
"Ýæ Ñø",
),
(
"yea no",
"Yea No",
),
(
"ýæ ñø",
"Ýæ Ñø",
),
)
def test_initials_regex():
"""Test - uppercase initials regex with A.B"""
from titlecase import UC_INITIALS
assert bool(UC_INITIALS.match('A.B')) is True
def test_initials_regex_2():
"""Test - uppercase initials regex with A.B."""
from titlecase import UC_INITIALS
assert bool(UC_INITIALS.match('A.B.')) is True
def test_initials_regex_3():
"""Test - uppercase initials regex with ABCD"""
from titlecase import UC_INITIALS
assert bool(UC_INITIALS.match('ABCD')) is False
def check_input_matches_expected_output(in_, out):
"""Function yielded by test generator"""
try:
assert titlecase(in_) == out
except AssertionError:
print("{0} != {1}".format(titlecase(in_), out))
raise
def test_at_and_t():
def at_n_t(word, **kwargs):
if word.upper() == "AT&T":
return word.upper()
print(titlecase("at&t", callback=at_n_t))
assert titlecase("at&t", callback=at_n_t) == "AT&T"
def test_input_output():
"""Generated tests"""
for data in TEST_DATA:
yield check_input_matches_expected_output, data[0], data[1]
def test_callback():
def abbreviation(word, **kwargs):
if word.upper() in ('TCP', 'UDP'):
return word.upper()
s = 'a simple tcp and udp wrapper'
assert titlecase(s) == 'A Simple Tcp and Udp Wrapper'
assert titlecase(s, callback=abbreviation) == 'A Simple TCP and UDP Wrapper'
assert titlecase(s.upper(), callback=abbreviation) == 'A Simple TCP and UDP Wrapper'
assert titlecase(u'crème brûlée', callback=lambda x, **kw: x.upper()) == u'CRÈME BRÛLÉE'
def test_set_small_word_list():
assert titlecase('playing the game "words with friends"') == 'Playing the Game "Words With Friends"'
set_small_word_list('a|an|the|with')
assert titlecase('playing the game "words with friends"') == 'Playing the Game "Words with Friends"'
if __name__ == "__main__":
import nose
nose.main()