Skip to content

Commit

Permalink
Refactor testing setup (#220)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
btharper authored and erozqba committed Oct 26, 2018
1 parent c606fd5 commit 5c9bce1
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 64 deletions.
9 changes: 5 additions & 4 deletions .coveragerc
@@ -1,4 +1,5 @@
[report]
omit =
*/.tox/*
*/tests/*
[run]
branch = true
source =
num2words
tests
13 changes: 12 additions & 1 deletion .travis.yml
Expand Up @@ -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
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -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::
Expand Down
4 changes: 2 additions & 2 deletions num2words/lang_PT.py
Expand Up @@ -157,7 +157,7 @@ def to_cardinal(self, value):
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)
)
Expand Down Expand Up @@ -195,7 +195,7 @@ def to_ordinal(self, value):

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
Expand Down
2 changes: 1 addition & 1 deletion num2words/lang_PT_BR.py
Expand Up @@ -79,7 +79,7 @@ def to_cardinal(self, value):
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
)
Expand Down
1 change: 0 additions & 1 deletion requirements-test.txt
Expand Up @@ -3,5 +3,4 @@ flake8-copyright
isort
pep8<1.6
coverage
coveralls
delegator.py
49 changes: 0 additions & 49 deletions tests/test_fi.py
Expand Up @@ -16,7 +16,6 @@

from __future__ import division, print_function, unicode_literals

import sys
from unittest import TestCase

from num2words import num2words
Expand All @@ -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):
Expand Down Expand Up @@ -2804,7 +2759,3 @@ def test_currency(self):
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 changes: 19 additions & 6 deletions 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

0 comments on commit 5c9bce1

Please sign in to comment.