Skip to content

Commit

Permalink
Added Travis CI and Coveralls (#19)
Browse files Browse the repository at this point in the history
Code reformatted to fit PEP 8 line width limitations.
  • Loading branch information
hugovk authored and agronholm committed Oct 17, 2016
1 parent 34d5c61 commit 73ac260
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@ dist/*
cover/*
htmlcov/*
.tox/*
*.egg-info
*.egg-info
.coverage
26 changes: 26 additions & 0 deletions .travis.yml
@@ -0,0 +1,26 @@
language: python

python:
- pypy
- pypy3
- 2.7
- 3.5
- 3.4
- 3.3

sudo: false # Use container-based infrastructure

install:
- pip install coverage tox-travis

script: tox

after_success:
- pip install coveralls
- coveralls

after_script:
- coverage report

matrix:
fast_finish: true
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -2,6 +2,11 @@
inflect.py
==========

.. image:: https://travis-ci.org/pwdyson/inflect.py.svg?branch=travis
:target: https://travis-ci.org/pwdyson/inflect.py
.. image:: https://coveralls.io/repos/pwdyson/inflect.py/badge.png?branch=travis
:target: https://coveralls.io/r/pwdyson/inflect.py?branch=travis

NAME
====

Expand Down
52 changes: 35 additions & 17 deletions inflect.py
Expand Up @@ -275,7 +275,8 @@ def make_pl_si_lists(lst, plending, siendingsize, dojoinstem=True):
"itis",
]

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

pl_sb_C_is_ides_list = pl_sb_C_is_ides_complete + pl_sb_C_is_ides_endings

Expand Down Expand Up @@ -579,7 +580,8 @@ def make_pl_si_lists(lst, plending, siendingsize, dojoinstem=True):
(si_sb_U_man_mans_list, si_sb_U_man_mans_bysize,
pl_sb_U_man_mans_bysize) = make_pl_si_lists(pl_sb_U_man_mans_list, 's', None, dojoinstem=False)
(si_sb_U_man_mans_caps_list, si_sb_U_man_mans_caps_bysize,
pl_sb_U_man_mans_caps_bysize) = make_pl_si_lists(pl_sb_U_man_mans_caps_list, 's', None, dojoinstem=False)
pl_sb_U_man_mans_caps_bysize) = make_pl_si_lists(
pl_sb_U_man_mans_caps_list, 's', None, dojoinstem=False)


pl_sb_uninflected_s_complete = [
Expand Down Expand Up @@ -612,7 +614,8 @@ def make_pl_si_lists(lst, plending, siendingsize, dojoinstem=True):
"measles",
]

pl_sb_uninflected_s = pl_sb_uninflected_s_complete + ['.*%s' % w for w in pl_sb_uninflected_s_endings]
pl_sb_uninflected_s = pl_sb_uninflected_s_complete + [
'.*%s' % w for w in pl_sb_uninflected_s_endings]

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

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

if word1a:
if word2a and (self._pl_check_plurals_N(word1a, word2a)
or self._pl_check_plurals_N(word2a, word1a)):
if word2a and (self._pl_check_plurals_N(word1a, word2a) or
self._pl_check_plurals_N(word2a, word1a)):
return True
# if word2b and ( self._pl_check_plurals_N(word1a, word2b)
# or self._pl_check_plurals_N(word2b, word1a) ):
Expand All @@ -1830,7 +1833,8 @@ def get_count(self, count=None):

if count is not None:
count = 1 if ((str(count) in pl_count_one) or
(self.classical_dict['zero'] and str(count).lower() in pl_count_zero)) else 2
(self.classical_dict['zero'] and
str(count).lower() in pl_count_zero)) else 2
else:
count = ''
return count
Expand Down Expand Up @@ -1898,15 +1902,17 @@ def _plnoun(self, word, count=None):
return ' '.join(
lowersplit[:numword - 1] +
[self._plnoun(lowersplit[numword - 1], 2) +
'-' + lowersplit[numword] + '-']) + ' '.join(lowersplit[(numword + 1):])
'-' + lowersplit[numword] + '-']
) + ' '.join(lowersplit[(numword + 1):])

# HANDLE PRONOUNS

for k, v in pl_pron_acc_keys_bysize.items():
if lowerword[-k:] in v: # ends with accusivate pronoun
for pk, pv in pl_prep_bysize.items():
if lowerword[:pk] in pv: # starts with a prep
if lowerword.split() == [lowerword[:pk], lowerword[-k:]]: # only whitespace in between
if lowerword.split() == [lowerword[:pk], lowerword[-k:]]:
# only whitespace in between
return lowerword[:-k] + pl_pron_acc[lowerword[-k:]]

try:
Expand Down Expand Up @@ -2336,16 +2342,21 @@ def _sinoun(self, word, count=None, gender=None):
if lowersplit[numword] in pl_prep_list_da:
return ' '.join(
lowersplit[:numword - 1] +
[(self._sinoun(lowersplit[numword - 1], 1, gender=gender) or lowersplit[numword - 1]) +
'-' + lowersplit[numword] + '-']) + ' '.join(lowersplit[(numword + 1):])
[(self._sinoun(lowersplit[numword - 1],
1,
gender=gender) or
lowersplit[numword - 1]) +
'-' + lowersplit[numword] + '-']
) + ' '.join(lowersplit[(numword + 1):])

# HANDLE PRONOUNS

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

try:
Expand Down Expand Up @@ -2793,7 +2804,10 @@ def ordinal(self, num):
except TypeError:
if '.' in str(num):
try:
n = int(num[-1]) # numbers after decimal, so only need last one for ordinal
# numbers after decimal,
# so only need last one for ordinal
n = int(num[-1])

except ValueError: # ends with '.', so need to use whole string
n = int(num[:-1])
else:
Expand Down Expand Up @@ -2830,8 +2844,9 @@ def tenfn(self, tens, units, mindex=0):

def hundfn(self, hundreds, tens, units, mindex):
if hundreds:
andword = " %s " % self.number_args['andword'] if tens or units else ''
return "%s hundred%s%s%s, " % (unit[hundreds], # use unit not unitfn as simpler
" %s " % self.number_args['andword'] if tens or units else '',
andword,
self.tenfn(tens, units),
self.millfn(mindex))
if tens or units:
Expand All @@ -2843,15 +2858,17 @@ def group1sub(self, mo):
if units == 1:
return " %s, " % self.number_args['one']
elif units:
# TODO: bug one and zero are padded with a space but other numbers aren't. check this in perl
# TODO: bug one and zero are padded with a space but other numbers
# aren't. check this in perl
return "%s, " % unit[units]
else:
return " %s, " % self.number_args['zero']

def group1bsub(self, mo):
units = int(mo.group(1))
if units:
# TODO: bug one and zero are padded with a space but other numbers aren't. check this in perl
# TODO: bug one and zero are padded with a space but other numbers
# aren't. check this in perl
return "%s, " % unit[units]
else:
return " %s, " % self.number_args['zero']
Expand All @@ -2873,7 +2890,8 @@ def group3sub(self, mo):
hunword = " %s" % self.number_args['one']
elif hundreds:
hunword = "%s" % unit[hundreds]
# TODO: bug one and zero are padded with a space but other numbers aren't. check this in perl
# TODO: bug one and zero are padded with a space but other numbers
# aren't. check this in perl
else:
hunword = " %s" % self.number_args['zero']
if tens:
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
@@ -1,2 +1,5 @@
[bdist_wheel]
universal = 1

[flake8]
max-line-length = 99
5 changes: 2 additions & 3 deletions setup.py
Expand Up @@ -15,7 +15,8 @@
setup(
name='inflect',
version=inflect.__version__,
description='Correctly generate plurals, singular nouns, ordinals, indefinite articles; convert numbers to words',
description='Correctly generate plurals, singular nouns, ordinals, '
'indefinite articles; convert numbers to words',
long_description=readme,
author='Paul Dyson',
author_email='pwdyson@yahoo.com',
Expand All @@ -28,10 +29,8 @@
classifiers=[
'Development Status :: 3 - Alpha',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
Expand Down
72 changes: 48 additions & 24 deletions tests/test_classical_all.py
Expand Up @@ -9,42 +9,66 @@ def test_classical(self):

# DEFAULT...

self.assertEqual(p.plural_noun('error', 0), 'errors', msg="classical 'zero' not active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests', msg="classical 'herd' not active")
self.assertEqual(p.plural_noun('Sally'), 'Sallys', msg="classical 'names' active")
self.assertEqual(p.plural_noun('brother'), 'brothers', msg="classical others not active")
self.assertEqual(p.plural_noun('person'), 'people', msg="classical 'persons' not active")
self.assertEqual(p.plural_noun('formula'), 'formulas', msg="classical 'ancient' not active")
self.assertEqual(p.plural_noun('error', 0), 'errors',
msg="classical 'zero' not active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests',
msg="classical 'herd' not active")
self.assertEqual(p.plural_noun('Sally'), 'Sallys',
msg="classical 'names' active")
self.assertEqual(p.plural_noun('brother'), 'brothers',
msg="classical others not active")
self.assertEqual(p.plural_noun('person'), 'people',
msg="classical 'persons' not active")
self.assertEqual(p.plural_noun('formula'), 'formulas',
msg="classical 'ancient' not active")

# CLASSICAL PLURALS ACTIVATED...

p.classical(all=True)
self.assertEqual(p.plural_noun('error', 0), 'error', msg="classical 'zero' active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest', msg="classical 'herd' active")
self.assertEqual(p.plural_noun('Sally'), 'Sallys', msg="classical 'names' active")
self.assertEqual(p.plural_noun('brother'), 'brethren', msg="classical others active")
self.assertEqual(p.plural_noun('person'), 'persons', msg="classical 'persons' active")
self.assertEqual(p.plural_noun('formula'), 'formulae', msg="classical 'ancient' active")
self.assertEqual(p.plural_noun('error', 0), 'error',
msg="classical 'zero' active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest',
msg="classical 'herd' active")
self.assertEqual(p.plural_noun('Sally'), 'Sallys',
msg="classical 'names' active")
self.assertEqual(p.plural_noun('brother'), 'brethren',
msg="classical others active")
self.assertEqual(p.plural_noun('person'), 'persons',
msg="classical 'persons' active")
self.assertEqual(p.plural_noun('formula'), 'formulae',
msg="classical 'ancient' active")

# CLASSICAL PLURALS DEACTIVATED...

p.classical(all=False)
self.assertEqual(p.plural_noun('error', 0), 'errors', msg="classical 'zero' not active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests', msg="classical 'herd' not active")
self.assertEqual(p.plural_noun('Sally'), 'Sallies', msg="classical 'names' not active")
self.assertEqual(p.plural_noun('brother'), 'brothers', msg="classical others not active")
self.assertEqual(p.plural_noun('person'), 'people', msg="classical 'persons' not active")
self.assertEqual(p.plural_noun('formula'), 'formulas', msg="classical 'ancient' not active")
self.assertEqual(p.plural_noun('error', 0), 'errors',
msg="classical 'zero' not active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeests',
msg="classical 'herd' not active")
self.assertEqual(p.plural_noun('Sally'), 'Sallies',
msg="classical 'names' not active")
self.assertEqual(p.plural_noun('brother'), 'brothers',
msg="classical others not active")
self.assertEqual(p.plural_noun('person'), 'people',
msg="classical 'persons' not active")
self.assertEqual(p.plural_noun('formula'), 'formulas',
msg="classical 'ancient' not active")

# CLASSICAL PLURALS REREREACTIVATED...

p.classical()
self.assertEqual(p.plural_noun('error', 0), 'error', msg="classical 'zero' active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest', msg="classical 'herd' active")
self.assertEqual(p.plural_noun('Sally'), 'Sallys', msg="classical 'names' active")
self.assertEqual(p.plural_noun('brother'), 'brethren', msg="classical others active")
self.assertEqual(p.plural_noun('person'), 'persons', msg="classical 'persons' active")
self.assertEqual(p.plural_noun('formula'), 'formulae', msg="classical 'ancient' active")
self.assertEqual(p.plural_noun('error', 0), 'error',
msg="classical 'zero' active")
self.assertEqual(p.plural_noun('wildebeest'), 'wildebeest',
msg="classical 'herd' active")
self.assertEqual(p.plural_noun('Sally'), 'Sallys',
msg="classical 'names' active")
self.assertEqual(p.plural_noun('brother'), 'brethren',
msg="classical others active")
self.assertEqual(p.plural_noun('person'), 'persons',
msg="classical 'persons' active")
self.assertEqual(p.plural_noun('formula'), 'formulae',
msg="classical 'ancient' active")

if __name__ == '__main__':
try:
Expand Down

0 comments on commit 73ac260

Please sign in to comment.