-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
115 lines (94 loc) · 4.16 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import functools
import sys
from lialib import liaBackend as backend
def test_parseHeader():
testString = ",,,date,,amount,,description,"
testOutput = backend.parseHeader(testString)
expectedOutput = ['', '', '', 'date', '', 'amount', '', 'description', '']
return(testOutput == expectedOutput)
def test_parseLine():
header = backend.parseHeader(",,date,amount,description,,")
lineData = backend.parseLine(",,09/06/1991,75.19,line statement,,", header)
expected = {'description': 'line statement'
, 'date': '09/06/1991'
, 'amount': '75.19'}
return(lineData == expected)
def test_cleanLineData():
lineData = {'description': 'line statement '
, 'date': '09/06/1991'
, 'amount': '75.19'}
dateFormat = "%m/%d/%Y"
cleanedLine = backend.cleanLineData(lineData, dateFormat)
expected = {'description': 'line statement'
, 'date': '1991/09/06'
, 'amount': '75.19'}
return(cleanedLine == expected)
def test_entryInfo():
lineData = {'description': 'line statement '
, 'date': '09/06/1991'
, 'amount': '75.19'}
resultLine = backend.entryInfo(lineData)
expected = '09/06/1991 line statement 75.19'
return(resultLine == expected)
def test_modifyData():
startLineData = {'description': 'line statement '
, 'date': '09/06/1991'
, 'amount': '75.19'}
newLineData = backend.modifyData(startLineData, "date", '10/14/1991')
expectedLinedData = {'description': 'line statement '
, 'date': '10/14/1991'
, 'amount': '75.19'}
return(newLineData == expectedLinedData)
### These tests require some refactoring to isolate IO
### I am going to see if I can factor out some common IO
### tasks into a few very basic IO functions, and then have
### the logic of these functions be pure and testable.
def test_setMainAccount():
startLineData = {'description': 'line statement'
, 'date': '1991/09/06'
, 'amount': '75.19'}
newLineData = backend.setMainAccount(startLineData, "Liabilities:Checking:Test")
expected = {'description': 'line statement'
, 'date': '1991/09/06'
, 'amount': '75.19'
, 'mainAccount' : "Liabilities:Checking:Test"}
return(newLineData == expected)
def test_setSecondAccounts():
startLineData = {'description': 'line statement'
, 'date': '1991/09/06'
, 'amount': '75.19'
, 'mainAccount' : "Liabilities:Checking:Test"}
newLineData = backend.setSecondAccounts(startLineData, [("acc1", "20.00"), ("acc2", "")])
expected = {'description': 'line statement'
, 'date': '1991/09/06'
, 'amount': '75.19'
, 'mainAccount' : "Liabilities:Checking:Test"
, 'secondAccounts' : [("acc1", "20.00"), ("acc2", "")]}
return(newLineData == expected)
def test_headTail():
l = [1,2,3]
head, tail = l[0], l[1:]
return(head == 1 and tail == [2,3])
# Just until I write real ones
def testTrue():
return(True)
# Execute Tests
testList = [["True", testTrue()]
,["parseHeader", test_parseHeader()]
,["parseLine", test_parseLine()]
,["cleanLineData", test_cleanLineData()]
,["entryInfo", test_entryInfo()]
,["modifyData", test_modifyData()]
,["setMainAccount", test_setMainAccount()]
,["setSecondAccounts", test_setSecondAccounts()]
,["Head *Tail", test_headTail()]]
failedTests = []
largestTestName = functools.reduce(max, map(lambda x: len(x[0]), testList))
for test in testList:
print(test[0].rjust(largestTestName), "Test: ", test[1])
if(test[1] == False):
failedTests.append(test[0])
## Break if 1 or more tests failed
if(len(failedTests) > 0):
failureMessage = "One or more tests failed! [" + ", ".join(failedTests) + "]"
sys.exit(failureMessage)