Skip to content

Commit

Permalink
Eliminate 2.7 vs 3.6 small difference definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Sep 6, 2018
1 parent 1ae7766 commit d926b31
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
6 changes: 1 addition & 5 deletions taxcalc/tests/test_cpscsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ def test_agg(tests_path, cps_fullsample):
txt = expected_file.read()
expected_results = txt.rstrip('\n\t ') + '\n' # cleanup end of file txt
# ensure actual and expected results have no nonsmall differences
if sys.version_info.major == 2:
small = 0.0 # tighter test for Python 2.7
else:
small = 0.1 # looser test for Python 3.6
diffs = nonsmall_diffs(actual_results.splitlines(True),
expected_results.splitlines(True), small)
expected_results.splitlines(True))
if diffs:
new_filename = '{}{}'.format(aggres_path[:-10], 'actual.txt')
with open(new_filename, 'w') as new_file:
Expand Down
16 changes: 3 additions & 13 deletions taxcalc/tests/test_puf_var_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def calculate_mean_stats(calc, table, year):
table[str(year)] = means


def differences(new_filename, old_filename, stat_kind, small):
def differences(new_filename, old_filename, stat_kind, small=0.0):
"""
Return message string if there are differences at least as large as small;
otherwise (i.e., if there are only small differences) return empty string.
Expand Down Expand Up @@ -176,17 +176,7 @@ def test_puf_var_stats(tests_path, puf_fullsample):
table_corr.to_csv(corr_path, float_format='%8.2f',
columns=table_corr.index)
# compare new and old CSV files for nonsmall differences
if sys.version_info.major == 2:
# tighter tests for Python 2.7
mean_msg = differences(mean_path, mean_path[:-4],
'MEAN', small=0.0)
corr_msg = differences(corr_path, corr_path[:-4],
'CORR', small=0.0)
else:
# looser tests for Python 3.6
mean_msg = differences(mean_path, mean_path[:-4],
'MEAN', small=1.0)
corr_msg = differences(corr_path, corr_path[:-4],
'CORR', small=0.01)
mean_msg = differences(mean_path, mean_path[:-4], 'MEAN')
corr_msg = differences(corr_path, corr_path[:-4], 'CORR')
if mean_msg or corr_msg:
raise ValueError(mean_msg + corr_msg)
6 changes: 1 addition & 5 deletions taxcalc/tests/test_pufcsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ def test_agg(tests_path, puf_fullsample):
expected_results = txt.rstrip('\n\t ') + '\n' # cleanup end of file txt
expect = expected_results.splitlines(True)
# ensure actual and expect lines have differences no more than small value
if sys.version_info.major == 2:
small = 0.0 # tighter test for Python 2.7
else:
small = 0.1 # looser test for Python 3.6
diffs = nonsmall_diffs(actual, expect, small)
diffs = nonsmall_diffs(actual, expect)
if diffs:
new_filename = '{}{}'.format(aggres_path[:-10], 'actual.txt')
with open(new_filename, 'w') as new_file:
Expand Down
7 changes: 2 additions & 5 deletions taxcalc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,11 +1600,8 @@ def dec_graph_plot(data,
def nonsmall_diffs(linelist1, linelist2, small=0.0):
"""
Return True if line lists differ significantly; otherwise return False.
Significant difference means one or more numbers differ (between
linelist1 and linelist2) by more than the small amount.
NOTE: this function is meant to be used only in the unit tests to handle
small differences in floating point values generated by Python 2.7 and 3.6,
where a nonzero small amount is used only under Python 3.6.
Significant numerical difference means one or more numbers differ (between
linelist1 and linelist2) by more than the specified small amount.
"""
# embedded function used only in nonsmall_diffs function
def isfloat(value):
Expand Down

0 comments on commit d926b31

Please sign in to comment.