From 63595c20695d2b59c7e61dba3b3bafaddae13c6f Mon Sep 17 00:00:00 2001 From: martinholmer Date: Sun, 23 Apr 2017 21:52:21 -0400 Subject: [PATCH] Make 'tc --test' exit code indicate PASS or FAIL --- taxcalc/cli/tc.py | 14 ++++++++++---- taxcalc/tests/test_parameters.py | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/taxcalc/cli/tc.py b/taxcalc/cli/tc.py index ed8840a0d..28c1593f7 100644 --- a/taxcalc/cli/tc.py +++ b/taxcalc/cli/tc.py @@ -133,9 +133,11 @@ def main(): output_sqldb=args.sqldb) # compare test output with expected test output if --test option specified if args.test: - compare_test_output_files() - # return no-error exit code - return 0 + retcode = compare_test_output_files() + else: + retcode = 0 + # return exit code + return retcode # end of main function code @@ -165,18 +167,22 @@ def write_test_input_output_files(): def compare_test_output_files(): """ - Compare expected and actual test output files. + Compare expected and actual test output files; + returns 0 if pass test, otherwise returns 1. """ explines = open(EXPECTED_TEST_OUTPUT_FILENAME, 'U').readlines() actlines = open(ACTUAL_TEST_OUTPUT_FILENAME, 'U').readlines() if ''.join(explines) == ''.join(actlines): sys.stdout.write('PASSED TEST\n') + retcode = 0 else: + retcode = 1 sys.stdout.write('FAILED TEST\n') diff = difflib.unified_diff(explines, actlines, fromfile=EXPECTED_TEST_OUTPUT_FILENAME, tofile=ACTUAL_TEST_OUTPUT_FILENAME, n=0) sys.stdout.writelines(diff) + return retcode if __name__ == '__main__': diff --git a/taxcalc/tests/test_parameters.py b/taxcalc/tests/test_parameters.py index aa0375de6..20f710674 100644 --- a/taxcalc/tests/test_parameters.py +++ b/taxcalc/tests/test_parameters.py @@ -10,8 +10,8 @@ import six import numpy as np import pytest -from taxcalc import ParametersBase # pylint: disable=import-error -from taxcalc import Policy, Consumption # pylint: disable=import-error +# pylint: disable=import-error +from taxcalc import ParametersBase, Policy, Consumption def test_instantiation_and_usage():