-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBC_test.py
More file actions
104 lines (77 loc) · 2.67 KB
/
DBC_test.py
File metadata and controls
104 lines (77 loc) · 2.67 KB
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
'''
Filename: DBC_test.py
Author: Tyler Phillips
Test program for DBC module
'''
from DBC import *
import unit_testing as ut
# Class tests
class TestArgumentError(ut.ClassTest):
def __init__(self):
ut.ClassTest.__init__(self)
def test___init__(self):
ut.test(isinstance(ArgumentError('function', 'parameter', tuple),
ArgumentError))
argumenterror1 = ArgumentError('test', 'expression', bool)
ut.test(argumenterror1.function_name == 'test')
ut.test(argumenterror1.parameter_name == 'expression')
ut.test(argumenterror1.acceptable_types == bool)
ut.test(argumenterror1.error_message == ('test requires bool for '
'expression.'))
argumenterror = TestArgumentError()
class TestOutputError(ut.ClassTest):
def __init__(self):
ut.ClassTest.__init__(self)
def test___init__(self):
ut.test(isinstance(OutputError('hi'), OutputError))
outputerror1 = OutputError('Function should return int.')
ut.test(outputerror1.error_message == 'Function should return int.')
outputerror = TestOutputError()
# Function tests
def test_check_arg_type():
ut.test(check_arg_type(1, 'num', (int, float)) == None)
ut.test(check_arg_type('', 'string', str) == None)
ut.test(check_arg_type([], 'data', (str, int, list, tuple)) == None)
errors = 0
try:
ut.test(check_arg_type(1, 'string', str) == None)
except ArgumentError:
errors += 1
try:
ut.test(check_arg_type('', 'num', (int, float)) == None)
except ArgumentError:
errors += 1
try:
ut.test(check_arg_type(1.5, 'parameter', (int, str, tuple, list, bool))
== None)
except ArgumentError:
errors += 1
ut.test(errors == 3)
def test_check_output_type():
ut.test(check_output_type(5, int) == None)
ut.test(check_output_type('', str) == None)
ut.test(check_output_type('', (list, str, int)) == None)
errors = 0
try:
ut.test(check_output_type('', int) == None)
except OutputError:
errors += 1
try:
ut.test(check_output_type('', list) == None)
except OutputError:
errors += 1
try:
ut.test(check_output_type(8.7, (list, str, tuple)) == None)
except OutputError:
errors += 1
ut.test(errors == 3)
def main():
# Class tests
argumenterror.test_all()
outputerror.test_all()
# Function tests
test_check_arg_type()
test_check_output_type()
print('All tests passed.')
if __name__ == '__main__':
main()