Skip to content

Commit

Permalink
Make 'tc --test' exit code indicate PASS or FAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Apr 24, 2017
1 parent 4c2dae4 commit 63595c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions taxcalc/cli/tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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__':
Expand Down
4 changes: 2 additions & 2 deletions taxcalc/tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 63595c2

Please sign in to comment.