forked from bbreslauer/wash-sale-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_integ_tests.py
41 lines (34 loc) · 1.16 KB
/
run_integ_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import lots as lots_lib
import wash as wash_lib
import os
from functools import cmp_to_key
def run_test(infile, outfile):
"""Runs a single test.
Args:
infile: Input filename.
outfile: Expected output filename.
"""
lots = lots_lib.Lots.create_from_csv_data(open(infile))
wash_lib.wash_all_lots(lots)
expected = lots_lib.Lots.create_from_csv_data(open(outfile))
lots.sort(key=cmp_to_key(lots_lib.Lot.cmp_by_buy_date))
expected.sort(key=cmp_to_key(lots_lib.Lot.cmp_by_buy_date))
if not lots.contents_equal(expected):
print('Test failed: {}'.format(infile))
print('Got result:')
lots.do_print()
print('Expected:')
expected.do_print()
print('\n\n')
else:
print("Test passed: {}".format(infile))
def main():
tests_dir = os.path.join(os.getcwd(), 'tests')
tests = [name
for name in os.listdir(tests_dir)
if name.endswith('.csv') and not name.endswith('_out.csv')]
for test in tests:
run_test(os.path.join(tests_dir, test),
os.path.join(tests_dir, test.rsplit('.', 1)[0] + "_out.csv"))
if __name__ == "__main__":
main()