Skip to content

Commit 73ac260

Browse files
hugovkagronholm
authored andcommittedOct 17, 2016
Added Travis CI and Coveralls (#19)
Code reformatted to fit PEP 8 line width limitations.
1 parent 34d5c61 commit 73ac260

12 files changed

+283
-100
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ dist/*
44
cover/*
55
htmlcov/*
66
.tox/*
7-
*.egg-info
7+
*.egg-info
8+
.coverage

‎.travis.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
language: python
2+
3+
python:
4+
- pypy
5+
- pypy3
6+
- 2.7
7+
- 3.5
8+
- 3.4
9+
- 3.3
10+
11+
sudo: false # Use container-based infrastructure
12+
13+
install:
14+
- pip install coverage tox-travis
15+
16+
script: tox
17+
18+
after_success:
19+
- pip install coveralls
20+
- coveralls
21+
22+
after_script:
23+
- coverage report
24+
25+
matrix:
26+
fast_finish: true

‎README.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
inflect.py
33
==========
44

5+
.. image:: https://travis-ci.org/pwdyson/inflect.py.svg?branch=travis
6+
:target: https://travis-ci.org/pwdyson/inflect.py
7+
.. image:: https://coveralls.io/repos/pwdyson/inflect.py/badge.png?branch=travis
8+
:target: https://coveralls.io/r/pwdyson/inflect.py?branch=travis
9+
510
NAME
611
====
712

‎inflect.py

+35-17
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ def make_pl_si_lists(lst, plending, siendingsize, dojoinstem=True):
275275
"itis",
276276
]
277277

278-
pl_sb_C_is_ides = joinstem(-2, pl_sb_C_is_ides_complete + ['.*%s' % w for w in pl_sb_C_is_ides_endings])
278+
pl_sb_C_is_ides = joinstem(-2, pl_sb_C_is_ides_complete + [
279+
'.*%s' % w for w in pl_sb_C_is_ides_endings])
279280

280281
pl_sb_C_is_ides_list = pl_sb_C_is_ides_complete + pl_sb_C_is_ides_endings
281282

@@ -579,7 +580,8 @@ def make_pl_si_lists(lst, plending, siendingsize, dojoinstem=True):
579580
(si_sb_U_man_mans_list, si_sb_U_man_mans_bysize,
580581
pl_sb_U_man_mans_bysize) = make_pl_si_lists(pl_sb_U_man_mans_list, 's', None, dojoinstem=False)
581582
(si_sb_U_man_mans_caps_list, si_sb_U_man_mans_caps_bysize,
582-
pl_sb_U_man_mans_caps_bysize) = make_pl_si_lists(pl_sb_U_man_mans_caps_list, 's', None, dojoinstem=False)
583+
pl_sb_U_man_mans_caps_bysize) = make_pl_si_lists(
584+
pl_sb_U_man_mans_caps_list, 's', None, dojoinstem=False)
583585

584586

585587
pl_sb_uninflected_s_complete = [
@@ -612,7 +614,8 @@ def make_pl_si_lists(lst, plending, siendingsize, dojoinstem=True):
612614
"measles",
613615
]
614616

615-
pl_sb_uninflected_s = pl_sb_uninflected_s_complete + ['.*%s' % w for w in pl_sb_uninflected_s_endings]
617+
pl_sb_uninflected_s = pl_sb_uninflected_s_complete + [
618+
'.*%s' % w for w in pl_sb_uninflected_s_endings]
616619

617620
pl_sb_uninflected_herd = (
618621
# DON'T INFLECT IN CLASSICAL MODE, OTHERWISE NORMAL INFLECTION
@@ -1796,7 +1799,7 @@ def _pl_check_plurals_N(self, word1, word2):
17961799
return False
17971800

17981801
def _pl_check_plurals_adj(self, word1, word2):
1799-
# VERSION: tuple in endswith requires python 2.5
1802+
# VERSION: tuple in endswith requires python 2.5
18001803
word1a = word1[:word1.rfind("'")] if word1.endswith(("'s", "'")) else ''
18011804
word2a = word2[:word2.rfind("'")] if word2.endswith(("'s", "'")) else ''
18021805
# TODO: BUG? report upstream. I don't think you should chop off the s'
@@ -1807,8 +1810,8 @@ def _pl_check_plurals_adj(self, word1, word2):
18071810
# then they return False because they are the same. Need to fix this.
18081811

18091812
if word1a:
1810-
if word2a and (self._pl_check_plurals_N(word1a, word2a)
1811-
or self._pl_check_plurals_N(word2a, word1a)):
1813+
if word2a and (self._pl_check_plurals_N(word1a, word2a) or
1814+
self._pl_check_plurals_N(word2a, word1a)):
18121815
return True
18131816
# if word2b and ( self._pl_check_plurals_N(word1a, word2b)
18141817
# or self._pl_check_plurals_N(word2b, word1a) ):
@@ -1830,7 +1833,8 @@ def get_count(self, count=None):
18301833

18311834
if count is not None:
18321835
count = 1 if ((str(count) in pl_count_one) or
1833-
(self.classical_dict['zero'] and str(count).lower() in pl_count_zero)) else 2
1836+
(self.classical_dict['zero'] and
1837+
str(count).lower() in pl_count_zero)) else 2
18341838
else:
18351839
count = ''
18361840
return count
@@ -1898,15 +1902,17 @@ def _plnoun(self, word, count=None):
18981902
return ' '.join(
18991903
lowersplit[:numword - 1] +
19001904
[self._plnoun(lowersplit[numword - 1], 2) +
1901-
'-' + lowersplit[numword] + '-']) + ' '.join(lowersplit[(numword + 1):])
1905+
'-' + lowersplit[numword] + '-']
1906+
) + ' '.join(lowersplit[(numword + 1):])
19021907

19031908
# HANDLE PRONOUNS
19041909

19051910
for k, v in pl_pron_acc_keys_bysize.items():
19061911
if lowerword[-k:] in v: # ends with accusivate pronoun
19071912
for pk, pv in pl_prep_bysize.items():
19081913
if lowerword[:pk] in pv: # starts with a prep
1909-
if lowerword.split() == [lowerword[:pk], lowerword[-k:]]: # only whitespace in between
1914+
if lowerword.split() == [lowerword[:pk], lowerword[-k:]]:
1915+
# only whitespace in between
19101916
return lowerword[:-k] + pl_pron_acc[lowerword[-k:]]
19111917

19121918
try:
@@ -2336,16 +2342,21 @@ def _sinoun(self, word, count=None, gender=None):
23362342
if lowersplit[numword] in pl_prep_list_da:
23372343
return ' '.join(
23382344
lowersplit[:numword - 1] +
2339-
[(self._sinoun(lowersplit[numword - 1], 1, gender=gender) or lowersplit[numword - 1]) +
2340-
'-' + lowersplit[numword] + '-']) + ' '.join(lowersplit[(numword + 1):])
2345+
[(self._sinoun(lowersplit[numword - 1],
2346+
1,
2347+
gender=gender) or
2348+
lowersplit[numword - 1]) +
2349+
'-' + lowersplit[numword] + '-']
2350+
) + ' '.join(lowersplit[(numword + 1):])
23412351

23422352
# HANDLE PRONOUNS
23432353

23442354
for k, v in si_pron_acc_keys_bysize.items():
23452355
if lowerword[-k:] in v: # ends with accusivate pronoun
23462356
for pk, pv in pl_prep_bysize.items():
23472357
if lowerword[:pk] in pv: # starts with a prep
2348-
if lowerword.split() == [lowerword[:pk], lowerword[-k:]]: # only whitespace in between
2358+
if lowerword.split() == [lowerword[:pk], lowerword[-k:]]:
2359+
# only whitespace in between
23492360
return lowerword[:-k] + get_si_pron('acc', lowerword[-k:], gender)
23502361

23512362
try:
@@ -2793,7 +2804,10 @@ def ordinal(self, num):
27932804
except TypeError:
27942805
if '.' in str(num):
27952806
try:
2796-
n = int(num[-1]) # numbers after decimal, so only need last one for ordinal
2807+
# numbers after decimal,
2808+
# so only need last one for ordinal
2809+
n = int(num[-1])
2810+
27972811
except ValueError: # ends with '.', so need to use whole string
27982812
n = int(num[:-1])
27992813
else:
@@ -2830,8 +2844,9 @@ def tenfn(self, tens, units, mindex=0):
28302844

28312845
def hundfn(self, hundreds, tens, units, mindex):
28322846
if hundreds:
2847+
andword = " %s " % self.number_args['andword'] if tens or units else ''
28332848
return "%s hundred%s%s%s, " % (unit[hundreds], # use unit not unitfn as simpler
2834-
" %s " % self.number_args['andword'] if tens or units else '',
2849+
andword,
28352850
self.tenfn(tens, units),
28362851
self.millfn(mindex))
28372852
if tens or units:
@@ -2843,15 +2858,17 @@ def group1sub(self, mo):
28432858
if units == 1:
28442859
return " %s, " % self.number_args['one']
28452860
elif units:
2846-
# TODO: bug one and zero are padded with a space but other numbers aren't. check this in perl
2861+
# TODO: bug one and zero are padded with a space but other numbers
2862+
# aren't. check this in perl
28472863
return "%s, " % unit[units]
28482864
else:
28492865
return " %s, " % self.number_args['zero']
28502866

28512867
def group1bsub(self, mo):
28522868
units = int(mo.group(1))
28532869
if units:
2854-
# TODO: bug one and zero are padded with a space but other numbers aren't. check this in perl
2870+
# TODO: bug one and zero are padded with a space but other numbers
2871+
# aren't. check this in perl
28552872
return "%s, " % unit[units]
28562873
else:
28572874
return " %s, " % self.number_args['zero']
@@ -2873,7 +2890,8 @@ def group3sub(self, mo):
28732890
hunword = " %s" % self.number_args['one']
28742891
elif hundreds:
28752892
hunword = "%s" % unit[hundreds]
2876-
# TODO: bug one and zero are padded with a space but other numbers aren't. check this in perl
2893+
# TODO: bug one and zero are padded with a space but other numbers
2894+
# aren't. check this in perl
28772895
else:
28782896
hunword = " %s" % self.number_args['zero']
28792897
if tens:

‎setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[bdist_wheel]
22
universal = 1
3+
4+
[flake8]
5+
max-line-length = 99

‎setup.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
setup(
1616
name='inflect',
1717
version=inflect.__version__,
18-
description='Correctly generate plurals, singular nouns, ordinals, indefinite articles; convert numbers to words',
18+
description='Correctly generate plurals, singular nouns, ordinals, '
19+
'indefinite articles; convert numbers to words',
1920
long_description=readme,
2021
author='Paul Dyson',
2122
author_email='pwdyson@yahoo.com',
@@ -28,10 +29,8 @@
2829
classifiers=[
2930
'Development Status :: 3 - Alpha',
3031
'Programming Language :: Python',
31-
'Programming Language :: Python :: 2.6',
3232
'Programming Language :: Python :: 2.7',
3333
'Programming Language :: Python :: 3',
34-
'Programming Language :: Python :: 3.2',
3534
'Programming Language :: Python :: 3.3',
3635
'Programming Language :: Python :: 3.4',
3736
'Programming Language :: Python :: 3.5',

‎tests/test_classical_all.py

+48-24
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,66 @@ def test_classical(self):
99

1010
# DEFAULT...
1111

12-
self.assertEqual(p.plural_noun('error', 0), 'errors', msg="classical 'zero' not active")
13-
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests', msg="classical 'herd' not active")
14-
self.assertEqual(p.plural_noun('Sally'), 'Sallys', msg="classical 'names' active")
15-
self.assertEqual(p.plural_noun('brother'), 'brothers', msg="classical others not active")
16-
self.assertEqual(p.plural_noun('person'), 'people', msg="classical 'persons' not active")
17-
self.assertEqual(p.plural_noun('formula'), 'formulas', msg="classical 'ancient' not active")
12+
self.assertEqual(p.plural_noun('error', 0), 'errors',
13+
msg="classical 'zero' not active")
14+
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests',
15+
msg="classical 'herd' not active")
16+
self.assertEqual(p.plural_noun('Sally'), 'Sallys',
17+
msg="classical 'names' active")
18+
self.assertEqual(p.plural_noun('brother'), 'brothers',
19+
msg="classical others not active")
20+
self.assertEqual(p.plural_noun('person'), 'people',
21+
msg="classical 'persons' not active")
22+
self.assertEqual(p.plural_noun('formula'), 'formulas',
23+
msg="classical 'ancient' not active")
1824

1925
# CLASSICAL PLURALS ACTIVATED...
2026

2127
p.classical(all=True)
22-
self.assertEqual(p.plural_noun('error', 0), 'error', msg="classical 'zero' active")
23-
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest', msg="classical 'herd' active")
24-
self.assertEqual(p.plural_noun('Sally'), 'Sallys', msg="classical 'names' active")
25-
self.assertEqual(p.plural_noun('brother'), 'brethren', msg="classical others active")
26-
self.assertEqual(p.plural_noun('person'), 'persons', msg="classical 'persons' active")
27-
self.assertEqual(p.plural_noun('formula'), 'formulae', msg="classical 'ancient' active")
28+
self.assertEqual(p.plural_noun('error', 0), 'error',
29+
msg="classical 'zero' active")
30+
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest',
31+
msg="classical 'herd' active")
32+
self.assertEqual(p.plural_noun('Sally'), 'Sallys',
33+
msg="classical 'names' active")
34+
self.assertEqual(p.plural_noun('brother'), 'brethren',
35+
msg="classical others active")
36+
self.assertEqual(p.plural_noun('person'), 'persons',
37+
msg="classical 'persons' active")
38+
self.assertEqual(p.plural_noun('formula'), 'formulae',
39+
msg="classical 'ancient' active")
2840

2941
# CLASSICAL PLURALS DEACTIVATED...
3042

3143
p.classical(all=False)
32-
self.assertEqual(p.plural_noun('error', 0), 'errors', msg="classical 'zero' not active")
33-
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests', msg="classical 'herd' not active")
34-
self.assertEqual(p.plural_noun('Sally'), 'Sallies', msg="classical 'names' not active")
35-
self.assertEqual(p.plural_noun('brother'), 'brothers', msg="classical others not active")
36-
self.assertEqual(p.plural_noun('person'), 'people', msg="classical 'persons' not active")
37-
self.assertEqual(p.plural_noun('formula'), 'formulas', msg="classical 'ancient' not active")
44+
self.assertEqual(p.plural_noun('error', 0), 'errors',
45+
msg="classical 'zero' not active")
46+
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests',
47+
msg="classical 'herd' not active")
48+
self.assertEqual(p.plural_noun('Sally'), 'Sallies',
49+
msg="classical 'names' not active")
50+
self.assertEqual(p.plural_noun('brother'), 'brothers',
51+
msg="classical others not active")
52+
self.assertEqual(p.plural_noun('person'), 'people',
53+
msg="classical 'persons' not active")
54+
self.assertEqual(p.plural_noun('formula'), 'formulas',
55+
msg="classical 'ancient' not active")
3856

3957
# CLASSICAL PLURALS REREREACTIVATED...
4058

4159
p.classical()
42-
self.assertEqual(p.plural_noun('error', 0), 'error', msg="classical 'zero' active")
43-
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest', msg="classical 'herd' active")
44-
self.assertEqual(p.plural_noun('Sally'), 'Sallys', msg="classical 'names' active")
45-
self.assertEqual(p.plural_noun('brother'), 'brethren', msg="classical others active")
46-
self.assertEqual(p.plural_noun('person'), 'persons', msg="classical 'persons' active")
47-
self.assertEqual(p.plural_noun('formula'), 'formulae', msg="classical 'ancient' active")
60+
self.assertEqual(p.plural_noun('error', 0), 'error',
61+
msg="classical 'zero' active")
62+
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest',
63+
msg="classical 'herd' active")
64+
self.assertEqual(p.plural_noun('Sally'), 'Sallys',
65+
msg="classical 'names' active")
66+
self.assertEqual(p.plural_noun('brother'), 'brethren',
67+
msg="classical others active")
68+
self.assertEqual(p.plural_noun('person'), 'persons',
69+
msg="classical 'persons' active")
70+
self.assertEqual(p.plural_noun('formula'), 'formulae',
71+
msg="classical 'ancient' active")
4872

4973
if __name__ == '__main__':
5074
try:

‎tests/test_inflections.py

+32-13
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,30 @@ def check_all(p, is_nv, singular, mod_PL_val, class_PL_val, mod_plural, class_pl
7272
eq_(mod_plural, mod_PL_val)
7373
eq_(class_plural, class_PL_val)
7474
eq_(is_eq(p, singular, mod_plural) in ('s:p', 'p:s', 'eq'), True,
75-
msg='is_eq(%s,%s) == %s != %s' % (singular, mod_plural, is_eq(p, singular, mod_plural), 's:p, p:s or eq'))
75+
msg='is_eq(%s,%s) == %s != %s' % (
76+
singular,
77+
mod_plural,
78+
is_eq(p, singular, mod_plural),
79+
's:p, p:s or eq'))
7680
eq_(is_eq(p, mod_plural, singular) in ('p:s', 's:p', 'eq'), True,
77-
msg='is_eq(%s,%s) == %s != %s' % (mod_plural, singular, is_eq(p, mod_plural, singular), 's:p, p:s or eq'))
81+
msg='is_eq(%s,%s) == %s != %s' % (
82+
mod_plural,
83+
singular,
84+
is_eq(p, mod_plural, singular),
85+
's:p, p:s or eq'))
7886
eq_(is_eq(p, singular, class_plural) in ('s:p', 'p:s', 'eq'), True)
7987
eq_(is_eq(p, class_plural, singular) in ('p:s', 's:p', 'eq'), True)
8088
assert_not_equal(singular, '')
8189
eq_(mod_PL_val, mod_PL_val if class_PL_val else '%s|%s' (mod_PL_val, class_PL_val))
8290

8391
if is_nv != '_V':
8492
eq_(p.singular_noun(mod_plural, 1), singular,
85-
msg="p.singular_noun(%s) == %s != %s" % (mod_plural, p.singular_noun(mod_plural, 1), singular))
93+
msg="p.singular_noun(%s) == %s != %s" % (
94+
mod_plural, p.singular_noun(mod_plural, 1), singular))
8695

8796
eq_(p.singular_noun(class_plural, 1), singular,
88-
msg="p.singular_noun(%s) == %s != %s" % (class_plural, p.singular_noun(class_plural, 1), singular))
97+
msg="p.singular_noun(%s) == %s != %s" % (
98+
class_plural, p.singular_noun(class_plural, 1), singular))
8999

90100
'''
91101
don't see any test data for this ???
@@ -552,10 +562,12 @@ class -> classes
552562
helix -> helices
553563
hepatitis -> hepatitises|hepatitides
554564
TODO:singular_noun 2 values her -> them # PRONOUN
555-
TODO:singular_noun 2 values her -> their # POSSESSIVE ADJ
565+
TODO:singular_noun 2 values her -> their
566+
# POSSESSIVE ADJ
556567
hero -> heroes
557568
herpes -> herpes
558-
TODO:singular_noun 2 values hers -> theirs # POSSESSIVE NOUN
569+
TODO:singular_noun 2 values hers -> theirs
570+
# POSSESSIVE NOUN
559571
TODO:singular_noun 2 values herself -> themselves
560572
hetman -> hetmans
561573
hiatus -> hiatuses|hiatus
@@ -565,8 +577,10 @@ class -> classes
565577
TODO:singular_noun 2 values himself -> themselves
566578
hippopotamus -> hippopotamuses|hippopotami
567579
Hiroshiman -> Hiroshimans
568-
TODO:singular_noun 2 values his -> their # POSSESSIVE ADJ
569-
TODO:singular_noun 2 values his -> theirs # POSSESSIVE NOUN
580+
TODO:singular_noun 2 values his -> their
581+
# POSSESSIVE ADJ
582+
TODO:singular_noun 2 values his -> theirs
583+
# POSSESSIVE NOUN
570584
TODO:siverb hoes -> hoe
571585
honorarium -> honorariums|honoraria
572586
hoof -> hoofs|hooves
@@ -930,9 +944,12 @@ class -> classes
930944
testes -> testes
931945
TODO:singular_noun multiple return testis -> testes
932946
TODO:siadj that -> those
933-
TODO:siadj their -> their # POSSESSIVE FORM (GENDER-INCLUSIVE)
934-
TODO:singular_noun multiple return themself -> themselves # ugly but gaining currency
935-
TODO:singular_noun multiple return they -> they # for indeterminate gender
947+
TODO:siadj their -> their
948+
# POSSESSIVE FORM (GENDER-INCLUSIVE)
949+
TODO:singular_noun multiple return themself -> themselves
950+
# ugly but gaining currency
951+
TODO:singular_noun multiple return they -> they
952+
# for indeterminate gender
936953
thief -> thiefs|thieves
937954
TODO:siadj this -> these
938955
thought -> thoughts # NOUN FORM
@@ -953,8 +970,10 @@ class -> classes
953970
to itself -> to themselves
954971
to me -> to us
955972
to myself -> to ourselves
956-
TODO:singular_noun multivalue to them -> to them # for indeterminate gender
957-
TODO:singular_noun multivalue to themself -> to themselves # ugly but gaining currency
973+
TODO:singular_noun multivalue to them -> to them
974+
# for indeterminate gender
975+
TODO:singular_noun multivalue to themself -> to themselves
976+
# ugly but gaining currency
958977
to you -> to you
959978
to yourself -> to yourselves
960979
Tocharese -> Tocharese

‎tests/test_join.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,37 @@ def test_join():
2020
"apple, banana... and carrot", msg='3 words, different final sep')
2121

2222
eq_(p.join(words, final_sep='...', conj=''),
23-
"apple, banana... carrot", msg='-->%s != %s<-- 3 words, different final sep, no conjunction' %
24-
(p.join(words, final_sep='...', conj=''), "apple, banana... carrot"))
23+
"apple, banana... carrot",
24+
msg='-->%s != %s<-- 3 words, different final sep, no conjunction' % (
25+
p.join(words, final_sep='...', conj=''), "apple, banana... carrot"))
2526

2627
eq_(p.join(words, conj='or'),
27-
"apple, banana, or carrot", msg='%s != %s 3 words, different conjunction' % (p.join(words, conj='or'),
28-
"apple, banana, or carrot"))
28+
"apple, banana, or carrot",
29+
msg='%s != %s 3 words, different conjunction' % (
30+
p.join(words, conj='or'),
31+
"apple, banana, or carrot"))
2932

3033
# Three words with semicolons...
3134
words = ('apple,fuji', 'banana', 'carrot')
3235

3336
eq_(p.join(words),
3437
"apple,fuji; banana; and carrot",
35-
msg='%s != %s<-- comma-inclusive 3 words' % (p.join(words), "apple,fuji, banana; and carrot"))
38+
msg='%s != %s<-- comma-inclusive 3 words' % (
39+
p.join(words), "apple,fuji, banana; and carrot"))
3640

3741
eq_(p.join(words, final_sep=''),
38-
"apple,fuji; banana and carrot", msg='join(%s) == "%s" != "%s"' % (words, p.join(words, final_sep=''),
39-
"apple,fuji) banana and carrot"))
42+
"apple,fuji; banana and carrot",
43+
msg='join(%s) == "%s" != "%s"' % (
44+
words,
45+
p.join(words, final_sep=''),
46+
"apple,fuji) banana and carrot"))
4047

4148
eq_(p.join(words, final_sep='...'),
4249
"apple,fuji; banana... and carrot", msg='comma-inclusive 3 words, different final sep')
4350

4451
eq_(p.join(words, final_sep='...', conj=''),
45-
"apple,fuji; banana... carrot", msg='comma-inclusive 3 words, different final sep, no conjunction')
52+
"apple,fuji; banana... carrot",
53+
msg='comma-inclusive 3 words, different final sep, no conjunction')
4654

4755
eq_(p.join(words, conj='or'),
4856
"apple,fuji; banana; or carrot", msg='comma-inclusive 3 words, different conjunction')

‎tests/test_numwords.py

+56-25
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def test_lines():
4444
eq_(p.number_to_words(999.3, threshold=500, comma=0), '999.3', msg=' 999.3 -> 999.3')
4545
eq_(p.number_to_words(1000.3, threshold=500, comma=0), '1000.3', msg='1000.3 -> 1000.3')
4646
eq_(p.number_to_words(10000.3, threshold=500, comma=0), '10000.3', msg='10000.3 -> 10000.3')
47-
eq_(p.number_to_words(100000.3, threshold=500, comma=0), '100000.3', msg='100000.3 -> 100000.3')
48-
eq_(p.number_to_words(1000000.3, threshold=500, comma=0), '1000000.3', msg='1000000.3 -> 1000000.3')
47+
eq_(p.number_to_words(100000.3, threshold=500, comma=0), '100000.3',
48+
msg='100000.3 -> 100000.3')
49+
eq_(p.number_to_words(1000000.3, threshold=500, comma=0), '1000000.3',
50+
msg='1000000.3 -> 1000000.3')
4951

5052

5153
def test_array():
@@ -318,65 +320,93 @@ def test_array():
318320
"one hundred thousand and first",
319321
], [
320322
"123456",
321-
"one hundred and twenty-three thousand, four hundred and fifty-six",
323+
"one hundred and twenty-three thousand, "
324+
"four hundred and fifty-six",
322325
"one, two, three, four, five, six",
323326
"twelve, thirty-four, fifty-six",
324327
"one twenty-three, four fifty-six",
325-
"one hundred and twenty-three thousand, four hundred and fifty-sixth",
328+
"one hundred and twenty-three thousand, "
329+
"four hundred and fifty-sixth",
326330
], [
327331
"0123456",
328-
"one hundred and twenty-three thousand, four hundred and fifty-six",
332+
"one hundred and twenty-three thousand, "
333+
"four hundred and fifty-six",
329334
"zero, one, two, three, four, five, six",
330335
"zero one, twenty-three, forty-five, six",
331336
"zero twelve, three forty-five, six",
332-
"one hundred and twenty-three thousand, four hundred and fifty-sixth",
337+
"one hundred and twenty-three thousand, "
338+
"four hundred and fifty-sixth",
333339
], [
334340
"1234567",
335-
"one million, two hundred and thirty-four thousand, five hundred and sixty-seven",
341+
"one million, two hundred and thirty-four thousand, "
342+
"five hundred and sixty-seven",
336343
"one, two, three, four, five, six, seven",
337344
"twelve, thirty-four, fifty-six, seven",
338345
"one twenty-three, four fifty-six, seven",
339-
"one million, two hundred and thirty-four thousand, five hundred and sixty-seventh",
346+
"one million, two hundred and thirty-four thousand, "
347+
"five hundred and sixty-seventh",
340348
], [
341349
"12345678",
342-
"twelve million, three hundred and forty-five thousand, six hundred and seventy-eight",
350+
"twelve million, three hundred and forty-five thousand, "
351+
"six hundred and seventy-eight",
343352
"one, two, three, four, five, six, seven, eight",
344353
"twelve, thirty-four, fifty-six, seventy-eight",
345354
"one twenty-three, four fifty-six, seventy-eight",
346-
"twelve million, three hundred and forty-five thousand, six hundred and seventy-eighth",
355+
"twelve million, three hundred and forty-five thousand, "
356+
"six hundred and seventy-eighth",
347357
], [
348358
"12_345_678",
349-
"twelve million, three hundred and forty-five thousand, six hundred and seventy-eight",
359+
"twelve million, three hundred and forty-five thousand, "
360+
"six hundred and seventy-eight",
350361
"one, two, three, four, five, six, seven, eight",
351362
"twelve, thirty-four, fifty-six, seventy-eight",
352363
"one twenty-three, four fifty-six, seventy-eight",
353364
], [
354365
"1234,5678",
355-
"twelve million, three hundred and forty-five thousand, six hundred and seventy-eight",
366+
"twelve million, three hundred and forty-five thousand, "
367+
"six hundred and seventy-eight",
356368
"one, two, three, four, five, six, seven, eight",
357369
"twelve, thirty-four, fifty-six, seventy-eight",
358370
"one twenty-three, four fifty-six, seventy-eight",
359371
], [
360372
"1234567890",
361-
"one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety",
373+
"one billion, two hundred and thirty-four million, five hundred "
374+
"and sixty-seven thousand, eight hundred and ninety",
362375
"one, two, three, four, five, six, seven, eight, nine, zero",
363376
"twelve, thirty-four, fifty-six, seventy-eight, ninety",
364377
"one twenty-three, four fifty-six, seven eighty-nine, zero",
365-
"one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninetieth",
378+
"one billion, two hundred and thirty-four million, five hundred "
379+
"and sixty-seven thousand, eight hundred and ninetieth",
366380
], [
367381
"123456789012345",
368-
"one hundred and twenty-three trillion, four hundred and fifty-six billion, seven hundred and eighty-nine million, twelve thousand, three hundred and forty-five",
369-
"one, two, three, four, five, six, seven, eight, nine, zero, one, two, three, four, five",
370-
"twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, thirty-four, five",
371-
"one twenty-three, four fifty-six, seven eighty-nine, zero twelve, three forty-five",
372-
"one hundred and twenty-three trillion, four hundred and fifty-six billion, seven hundred and eighty-nine million, twelve thousand, three hundred and forty-fifth",
382+
"one hundred and twenty-three trillion, four hundred and "
383+
"fifty-six billion, seven hundred and eighty-nine million, twelve "
384+
"thousand, three hundred and forty-five",
385+
"one, two, three, four, five, six, seven, eight, nine, zero, one, "
386+
"two, three, four, five",
387+
"twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, "
388+
"thirty-four, five",
389+
"one twenty-three, four fifty-six, seven eighty-nine, "
390+
"zero twelve, three forty-five",
391+
"one hundred and twenty-three trillion, four hundred and "
392+
"fifty-six billion, seven hundred and eighty-nine million, "
393+
"twelve thousand, three hundred and forty-fifth",
373394
], [
374395
"12345678901234567890",
375-
"twelve quintillion, three hundred and forty-five quadrillion, six hundred and seventy-eight trillion, nine hundred and one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety",
376-
"one, two, three, four, five, six, seven, eight, nine, zero, one, two, three, four, five, six, seven, eight, nine, zero",
377-
"twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, thirty-four, fifty-six, seventy-eight, ninety",
378-
"one twenty-three, four fifty-six, seven eighty-nine, zero twelve, three forty-five, six seventy-eight, ninety",
379-
"twelve quintillion, three hundred and forty-five quadrillion, six hundred and seventy-eight trillion, nine hundred and one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninetieth",
396+
"twelve quintillion, three hundred and forty-five quadrillion, "
397+
"six hundred and seventy-eight trillion, nine hundred and one "
398+
"billion, two hundred and thirty-four million, five hundred and "
399+
"sixty-seven thousand, eight hundred and ninety",
400+
"one, two, three, four, five, six, seven, eight, nine, zero, one, "
401+
"two, three, four, five, six, seven, eight, nine, zero",
402+
"twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, "
403+
"thirty-four, fifty-six, seventy-eight, ninety",
404+
"one twenty-three, four fifty-six, seven eighty-nine, "
405+
"zero twelve, three forty-five, six seventy-eight, ninety",
406+
"twelve quintillion, three hundred and forty-five quadrillion, "
407+
"six hundred and seventy-eight trillion, nine hundred and one "
408+
"billion, two hundred and thirty-four million, five hundred and "
409+
"sixty-seven thousand, eight hundred and ninetieth",
380410
], [
381411
"0.987654",
382412
"zero point nine eight seven six five four",
@@ -463,7 +493,8 @@ def go(p, i):
463493
eq_(p.number_to_words(i[0], group=2), i[3])
464494
eq_(p.number_to_words(i[0], group=3), i[4])
465495
if len(i) > 5:
466-
eq_(p.number_to_words(p.ordinal(i[0])), i[5], msg="number_to_words(ordinal(%s)) == %s != %s" % (
496+
eq_(p.number_to_words(p.ordinal(i[0])), i[5],
497+
msg="number_to_words(ordinal(%s)) == %s != %s" % (
467498
i[0], p.number_to_words(p.ordinal(i[0])),
468499
i[5]))
469500
if len(i) > 6:

‎tests/test_pwd.py

+39-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99

1010
class test(unittest.TestCase):
1111
def TODO(self, ans, answer_wanted,
12-
answer_gives_now="default_that_will_never_occur__can't_use_None_as_that_is_a_possible_valid_value"):
12+
answer_gives_now="default_that_will_never_occur__can't_use_None"
13+
"_as_that_is_a_possible_valid_value"):
1314
'''
1415
make this test for future testing
1516
1617
so can easily rename these to assertEqual when code ready
1718
'''
1819
if ans == answer_wanted:
1920
print('test unexpectedly passed!: %s == %s' % (ans, answer_wanted))
20-
if answer_gives_now != "default_that_will_never_occur__can't_use_None_as_that_is_a_possible_valid_value":
21+
if answer_gives_now != ("default_that_will_never_occur__can't_use_None"
22+
"_as_that_is_a_possible_valid_value"):
2123
self.assertEqual(ans, answer_gives_now)
2224

2325
def test_enclose(self):
@@ -253,6 +255,7 @@ def test_pl(self):
253255
(p.plural_noun, '', ''),
254256
(p.plural_noun, 'cow', 'cows'),
255257
(p.plural_noun, 'thought', 'thoughts'),
258+
(p.plural_noun, 'snooze', 'snoozes'),
256259
(p.plural_verb, '', ''),
257260
(p.plural_verb, 'runs', 'run'),
258261
(p.plural_verb, 'thought', 'thought'),
@@ -305,6 +308,23 @@ def test_sinoun(self):
305308
self.assertEqual(p.singular_noun(plur), sing)
306309
self.assertEqual(p.inflect('singular_noun(%s)' % plur), sing)
307310

311+
self.assertEqual(p.singular_noun('cats', count=2), 'cats')
312+
313+
self.assertEqual(p.singular_noun('zombies'), 'zombie')
314+
315+
self.assertEqual(p.singular_noun('shoes'), 'shoe')
316+
317+
self.assertEqual(p.singular_noun('Matisses'), 'Matisse')
318+
self.assertEqual(p.singular_noun('bouillabaisses'), 'bouillabaisse')
319+
320+
self.assertEqual(p.singular_noun('quartzes'), 'quartz')
321+
322+
self.assertEqual(p.singular_noun('Nietzsches'), 'Nietzsche')
323+
self.assertEqual(p.singular_noun('aches'), 'ache')
324+
325+
self.assertEqual(p.singular_noun('Clives'), 'Clive')
326+
self.assertEqual(p.singular_noun('weaves'), 'weave')
327+
308328
def test_gender(self):
309329
p = inflect.engine()
310330
p.gender('feminine')
@@ -367,6 +387,9 @@ def test_gender(self):
367387
):
368388
self.assertEqual(p.singular_noun(plur, gender=gen), sing)
369389

390+
with self.assertRaises(BadGenderError):
391+
p.singular_noun('cats', gender='unknown gender')
392+
370393
def test_plequal(self):
371394
p = inflect.engine()
372395
for fn, sing, plur, res in (
@@ -649,7 +672,8 @@ def test__pl_special_verb(self):
649672
self.assertEqual(p._pl_special_verb('canoes'), 'canoe')
650673
self.assertEqual(p._pl_special_verb('horseshoes'), 'horseshoe')
651674
self.assertEqual(p._pl_special_verb('does'), 'do')
652-
self.assertEqual(p._pl_special_verb('zzzoes'), 'zzzo') # TODO: what's a real word to test this case?
675+
# TODO: what's a real word to test this case?
676+
self.assertEqual(p._pl_special_verb('zzzoes'), 'zzzo')
653677
self.assertEqual(p._pl_special_verb('runs'), 'run')
654678

655679
def test__pl_general_verb(self):
@@ -724,6 +748,7 @@ def test_a(self):
724748
self.assertEqual(p.a('cat', 2), '2 cat')
725749

726750
self.assertEqual(p.a, p.an)
751+
self.assertEqual(p.a(''), '')
727752

728753
def test_no(self):
729754
p = inflect.engine()
@@ -876,7 +901,8 @@ def test_enword(self):
876901
self.assertEqual(enword('123456', -1),
877902
'one hundred and twenty-three thousand, four hundred and fifty-six , ')
878903
self.assertEqual(enword('1234567', -1),
879-
'one million, two hundred and thirty-four thousand, five hundred and sixty-seven , ')
904+
'one million, two hundred and thirty-four thousand, '
905+
'five hundred and sixty-seven , ')
880906

881907
def test_numwords(self):
882908
p = inflect.engine()
@@ -950,7 +976,8 @@ def test_numwords(self):
950976
self.assertEqual(numwords('1', decimal=None),
951977
'one')
952978
self.assertEqual(numwords('1234.5678', decimal=None),
953-
'twelve million, three hundred and forty-five thousand, six hundred and seventy-eight')
979+
'twelve million, three hundred and forty-five '
980+
'thousand, six hundred and seventy-eight')
954981

955982
def test_numwords_group(self):
956983
p = inflect.engine()
@@ -1056,7 +1083,8 @@ def test_doc_examples(self):
10561083
self.assertEqual("There %s%s" % (p.plural_verb('was', errors), p.no(" error", errors)),
10571084
txt)
10581085

1059-
self.assertEqual(p.inflect("There plural_verb(was,%d) no(error,%d)" % (errors, errors)),
1086+
self.assertEqual(p.inflect(
1087+
"There plural_verb(was,%d) no(error,%d)" % (errors, errors)),
10601088
txt)
10611089

10621090
for num1, num2, txt in (
@@ -1105,6 +1133,11 @@ def test_deprecation(self):
11051133
):
11061134
self.assertRaises(DeprecationWarning, getattr, p, meth)
11071135

1136+
def test_unknown_method(self):
1137+
p = inflect.engine()
1138+
with self.assertRaises(AttributeError):
1139+
p.unknown_method
1140+
11081141

11091142
# TODO: test .inflectrc file code
11101143

‎tox.ini

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
[tox]
2-
envlist = py26,py27,py32,py33,py34,py35
2+
envlist = py27, py33, py34, py35
3+
4+
[tox:travis]
5+
pypy = pypy
6+
pypy3 = pypy3
7+
2.7 = py27
8+
3.3 = py33
9+
3.4 = py34
10+
3.5 = py35, flake8
311

412
[testenv]
5-
deps=nose
6-
commands=nosetests []
13+
deps =
14+
coverage
15+
nose
16+
commands = coverage run --source=inflect -m nose -x
17+
18+
[testenv:flake8]
19+
deps = flake8
20+
commands =
21+
flake8 .
22+
skip_install = true

0 commit comments

Comments
 (0)
Please sign in to comment.