-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcases.py
43 lines (37 loc) · 1.5 KB
/
testcases.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
42
43
"""
Test cases
"""
from dataparser import DataParser, SPEC_FILE
dp = DataParser.factory(SPEC_FILE)
print("Test input file with full width fields", end='')
dp.parse("tests/test_input1.txt", "tests/_temp_output1.txt", delimiter=',')
with open("tests/_temp_output1.txt", 'r') as f:
derived_output = f.read()
with open("tests/test_output1.txt", 'r') as f:
expected_output = f.read()
assert derived_output == expected_output
print(" ==> passed!")
print("Test input file with left aligned fields and blank fields", end='')
dp.parse("tests/test_input2.txt", "tests/_temp_output2.txt", delimiter=',')
with open("tests/_temp_output2.txt", 'r') as f:
derived_output = f.read()
with open("tests/test_output2.txt", 'r') as f:
expected_output = f.read()
assert derived_output == expected_output
print(" ==> passed!")
print("Test input file with right aligned fields and blank fields", end='')
dp.parse("tests/test_input3.txt", "tests/_temp_output3.txt", delimiter=',')
with open("tests/_temp_output3.txt", 'r') as f:
derived_output = f.read()
with open("tests/test_output3.txt", 'r') as f:
expected_output = f.read()
assert derived_output == expected_output
print(" ==> passed!")
print("Test file with all blank fields", end='')
dp.parse("tests/test_input4.txt", "tests/_temp_output4.txt", delimiter=',')
with open("tests/_temp_output4.txt", 'r') as f:
derived_output = f.read()
with open("tests/test_output4.txt", 'r') as f:
expected_output = f.read()
assert derived_output == expected_output
print(" ==> passed!")