diff --git a/.coveragerc b/.coveragerc index 9d3f399..6d88b72 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,5 @@ -[report] -omit = - */.tox/* - */tests/* +[run] +branch = true +source = + num2words + tests diff --git a/.travis.yml b/.travis.yml index 6df6b36..aa600d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,16 @@ python: - "3.4" - "3.5" - "3.6" -install: pip install tox-travis +matrix: + include: + - { python: 3.6, env: TOXENV=flake8 } + - { python: 3.6, env: TOXENV=isort } + # Py37 requires xenial distrubution and sudo + # See travis-ci/travis-ci#9069 + - { python: 3.7, dist: xenial, sudo: true } + +install: + - pip install tox-travis + - pip install coveralls script: tox +after_success: if [ -e .coverage ]; then coveralls; fi diff --git a/README.rst b/README.rst index 5b76fcf..f50823f 100644 --- a/README.rst +++ b/README.rst @@ -35,6 +35,11 @@ The test suite in this library is new, so it's rather thin, but it can be run wi python setup.py test +To run the full CI test suite which includes linting and multiple python environments:: + + pip install tox + tox + Usage ----- Command line:: diff --git a/num2words/lang_PT.py b/num2words/lang_PT.py index ef523b5..44bd4d0 100644 --- a/num2words/lang_PT.py +++ b/num2words/lang_PT.py @@ -157,7 +157,7 @@ class Num2Word_PT(Num2Word_EU): for ext in ( 'mil', 'milhão', 'milhões', 'mil milhões', 'bilião', 'biliões', 'mil biliões'): - if re.match('.*{} e \w*entos? (?=.*e)'.format(ext), result): + if re.match('.*{} e \\w*entos? (?=.*e)'.format(ext), result): result = result.replace( '{} e'.format(ext), '{}'.format(ext) ) @@ -195,7 +195,7 @@ class Num2Word_PT(Num2Word_EU): result = ' '.join(result[::-1]) result = result.strip() - result = re.sub('\s+', ' ', result) + result = re.sub('\\s+', ' ', result) if result.startswith('primeiro') and value != '1': # avoiding "primeiro milésimo", "primeiro milionésimo" and so on diff --git a/num2words/lang_PT_BR.py b/num2words/lang_PT_BR.py index 7515e28..cc8c45c 100644 --- a/num2words/lang_PT_BR.py +++ b/num2words/lang_PT_BR.py @@ -79,7 +79,7 @@ class Num2Word_PT_BR(lang_PT.Num2Word_PT): for ext in ( 'mil', 'milhão', 'milhões', 'bilhão', 'bilhões', 'trilhão', 'trilhões', 'quatrilhão', 'quatrilhões'): - if re.match('.*{} e \w*ento'.format(ext), result): + if re.match('.*{} e \\w*ento'.format(ext), result): result = result.replace( '{} e'.format(ext), '{},'.format(ext), 1 ) diff --git a/requirements-test.txt b/requirements-test.txt index 7c337d4..7165ac7 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -3,5 +3,4 @@ flake8-copyright isort pep8<1.6 coverage -coveralls delegator.py diff --git a/tests/test_fi.py b/tests/test_fi.py index bf0d56f..1698a96 100644 --- a/tests/test_fi.py +++ b/tests/test_fi.py @@ -16,7 +16,6 @@ from __future__ import division, print_function, unicode_literals -import sys from unittest import TestCase from num2words import num2words @@ -32,50 +31,6 @@ def n2f(*args, **kwargs): return num2words(lang='fi', *args, **kwargs) -def create_test(number, to): - return ( - "# %s\n" % num2words(number, lang='en') + - "self.assertEqual(\n" + - ' tuple(n2f(%s, to="%s", case=c) for c in CASES),\n' % - (number, to) + - # grammatical - ' ("%s", "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c) for c in CASES[0:3]) + - # internal locative - ' "%s", "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c) for c in CASES[3:6]) + - # external locative - ' "%s", "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c) for c in CASES[6:9]) + - # essive - ' "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c) for c in CASES[9:11]) + - # rare - ' "%s", "%s", "%s")\n' % - tuple(n2f(number, to=to, case=c) for c in CASES[11:14]) + - ")\n" + - "self.assertEqual(\n" + - ' tuple(n2f(%s, to="%s", case=c, plural=True) for c in CASES),\n' % - (number, to) + - # grammatical - ' ("%s", "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c, plural=True) for c in CASES[0:3]) + - # internal locative - ' "%s", "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c, plural=True) for c in CASES[3:6]) + - # external locative - ' "%s", "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c, plural=True) for c in CASES[6:9]) + - # essive - ' "%s", "%s",\n' % - tuple(n2f(number, to=to, case=c, plural=True) for c in CASES[9:11]) + - # rare - ' "%s", "%s", "%s")\n' % - tuple(n2f(number, to=to, case=c, plural=True) for c in CASES[11:14]) + - ")\n" - ) - - class Num2WordsFITest(TestCase): def test_low(self): @@ -2804,7 +2759,3 @@ class Num2WordsFITest(TestCase): self.assertEqual( n2f(150, to="currency", currency="FIM", adjective=True), "yksi Suomen markka ja viisikymmentä penniä") - - -if __name__ == '__main__': - print(create_test(int(sys.argv[1]), sys.argv[2])) diff --git a/tox.ini b/tox.ini index 6bdc5f4..34ff065 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,28 @@ [tox] -envlist = flake8,isort,py27,py34,py35,py36 +envlist = flake8,isort,py27,py34,py35,py36,py37 [testenv] passenv = TRAVIS TRAVIS_* deps = - -r{toxinidir}/requirements-test.txt + coverage + delegator.py commands = - flake8 - isort --check-only --recursive --diff num2words tests - coverage erase coverage run -m unittest discover coverage report --fail-under=75 --omit=.tox/*,tests/*,/usr/* - coveralls + coverage report --fail-under=100 --include=tests/* --skip-covered +[testenv:flake8] +changedir = {toxinidir} +deps = + flake8 + flake8-copyright +commands = + flake8 + +[testenv:isort] +changedir = {toxinidir} +deps = + isort + delegator.py +commands = + isort --check-only --recursive --diff num2words tests