Refactor testing setup (#220)

* Refactor tox and travis config files

Separates flake8 and isort into separate tox tasks
Tie flake8 and isort to specific python version so they only run once on Travis
Add python3.7 to tested python versions
* Requires newer Xenial base
* Running Xenial on Travis requires sudo
Move coveralls submission to travis config to avoid triggering during local runs.

* Require all tests to be run

Clean up test generation code form test_fi.py
Perform coverage measurement of tests
Fail tox if coverage of tests directory isn't at 100%

* Further Tox refactoring

Measure project coverage explicitly instead of omitting non-project files from reporting
Add branch measurement to coverage
Only report to coveralls if a .coverage result file exists
Make dependencies for each testenv explict and only include requried deps

* Small readme update to trigger travis

Add overly brief message about installing and running tox

* Fix unescaped flake8 violations

Unescaped \w -> \\w and \e to \\e in regex patterns found with updated flake8
This commit is contained in:
btharper
2018-10-26 09:31:41 -04:00
committed by Ernesto Rodriguez Ortiz
parent c606fd54e8
commit 5c9bce19e4
8 changed files with 44 additions and 64 deletions

View File

@@ -1,4 +1,5 @@
[report]
omit =
*/.tox/*
*/tests/*
[run]
branch = true
source =
num2words
tests

View File

@@ -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

View File

@@ -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::

View File

@@ -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

View File

@@ -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
)

View File

@@ -3,5 +3,4 @@ flake8-copyright
isort
pep8<1.6
coverage
coveralls
delegator.py

View File

@@ -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]))

25
tox.ini
View File

@@ -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