Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run test options #610

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 21.3.0

Add `--only-variables` and `--ignore-variables` options to `openfisca-run-test` to filter out tested output variables if needed.

### 21.2.2 [#612](https://github.com/openfisca/openfisca-core/pull/612)

- When a variable file is loaded twice in the same python interpreter, make sure the second loading doesn't corrupt the first one.
Expand Down
4 changes: 4 additions & 0 deletions openfisca_core/scripts/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ 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('-o', '--only-variables', nargs = '*', default = None, help = "variables to test. If specified, only test the given variables.")
parser.add_argument('-i', '--ignore-variables', nargs = '*', default = None, help = "variables to ignore. If specified, do not test the given variables.")

return parser

Expand All @@ -29,6 +31,8 @@ def main():
options = {
'verbose': args.verbose,
'name_filter': args.name_filter,
'only_variables': args.only_variables,
'ignore_variables': args.ignore_variables,
}

paths = map(os.path.abspath, args.path)
Expand Down
10 changes: 8 additions & 2 deletions openfisca_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def _generate_tests_from_file(tax_benefit_system, path_to_file, options):
if isinstance(name_filter, str):
name_filter = name_filter.decode('utf-8')
verbose = options.get('verbose')
only_variables = options.get('only_variables')
ignore_variables = options.get('ignore_variables')

tests = _parse_test_file(tax_benefit_system, path_to_file)

Expand All @@ -147,7 +149,7 @@ def _generate_tests_from_file(tax_benefit_system, path_to_file, options):

def check():
try:
_run_test(period_str, test, verbose, options)
_run_test(period_str, test, verbose, only_variables, ignore_variables, options)
except:
log.error(title)
raise
Expand Down Expand Up @@ -218,7 +220,7 @@ def _parse_test_file(tax_benefit_system, yaml_path):
yield yaml_path, test.get('name') or filename, unicode(test['scenario'].period), test


def _run_test(period_str, test, verbose = False, options = {}):
def _run_test(period_str, test, verbose = False, only_variables = None, ignore_variables = None, options = {}):
absolute_error_margin = None
relative_error_margin = None
if test.get('absolute_error_margin') is not None:
Expand All @@ -233,6 +235,10 @@ def _run_test(period_str, test, verbose = False, options = {}):
if output_variables is not None:
try:
for variable_name, expected_value in output_variables.iteritems():
variable_ignored = ignore_variables is not None and variable_name in ignore_variables
variable_not_tested = only_variables is not None and variable_name not in only_variables
if variable_ignored or variable_not_tested:
continue # Skip this variable
if isinstance(expected_value, dict):
for requested_period, expected_value_at_period in expected_value.iteritems():
assert_near(
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 = '21.2.2',
version = '21.3.0',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.fr',
classifiers = [
Expand Down