Skip to content

Commit

Permalink
Introduce --nose option in openfisca-run-test
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagnoux committed May 24, 2017
1 parent e10b68c commit dbfe0d9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 12.2.0

* Improve the `openfisca-run-test` script
- Add a `--nose` option to run the tests with nose.
- This avoids boilerplate code on country packages, and makes parallelism easier to set on Circle CI.

## 12.1.4

* Fix package naming conflict between the preview API and the official one.
Expand Down
4 changes: 3 additions & 1 deletion openfisca_core/scripts/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def build_parser():
parser = add_tax_benefit_system_arguments(parser)
parser.add_argument('-n', '--name_filter', default = None, help = "partial name of tests to execute. Only tests with the given name_filter in their name, file name, or keywords will be run.")
parser.add_argument('-v', '--verbose', action = 'store_true', default = False, help = "increase output verbosity")
parser.add_argument('--nose', action = 'store_true', default = False, help = "use nosetests to run the tests")

return parser

Expand All @@ -29,6 +30,7 @@ def main():
options = {
'verbose': args.verbose,
'name_filter': args.name_filter,
'nose': args.nose,
}

tests_found = False
Expand All @@ -38,7 +40,7 @@ def main():
nb_tests = run_tests(tax_benefit_system, path, options)
tests_found = tests_found or nb_tests > 0

if not tests_found:
if not tests_found and not args.nose:
print("No tests found!")
sys.exit(1)

Expand Down
29 changes: 22 additions & 7 deletions openfisca_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import os
import yaml
import numpy as np
import sys
import unittest

from openfisca_core import conv, periods, scenarios
from openfisca_core.tools import assert_near
Expand Down Expand Up @@ -94,16 +96,26 @@ def run_tests(tax_benefit_system, path, options = {}):
| verbose | ``bool`` | |
+-------------------------------+-----------+ +
| name_filter | ``str`` | See :any:`openfisca-run-test` options doc |
+-------------------------------+-----------+ +
| nose | ``bool`` | |
+-------------------------------+-----------+-------------------------------------------+
"""
if options.get('nose'):
import nose
nose.run(
# The suite argument must be a lambda for nose to run the tests lazily
suite = lambda: generate_tests(tax_benefit_system, path, options),
# Nose crashes if it gets any unexpected argument.
argv = sys.argv[:1]
)
else:
nb_tests = 0
for test in generate_tests(tax_benefit_system, path, options):
test()
nb_tests += 1

nb_tests = 0
for test in generate_tests(tax_benefit_system, path, options):
test()
nb_tests += 1

return nb_tests # Nb of sucessful tests
return nb_tests # Nb of sucessful tests


# Internal methods
Expand Down Expand Up @@ -137,7 +149,10 @@ def check():
print("=" * len(title))
_run_test(period_str, test, verbose, options)

yield check
if options.get('nose'):
yield unittest.FunctionTestCase(check)
else:
yield check


def _generate_tests_from_directory(tax_benefit_system, path_to_dir, options):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name = 'OpenFisca-Core',
version = '12.1.4',
version = '12.2.0',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.fr',
classifiers = [
Expand Down

0 comments on commit dbfe0d9

Please sign in to comment.