-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtestc.py
More file actions
40 lines (32 loc) · 1.09 KB
/
testc.py
File metadata and controls
40 lines (32 loc) · 1.09 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
import io
def str_print(*objects):
out = io.StringIO()
print(*objects, file=out, end="")
res = out.getvalue()
return res
class test:
num_tests = 0
failed_tests = 0
def equal(self, expr, expected):
self.num_tests += 1
if(expr == expected):
print("Test Passed with result: '", expr, "'", sep = '')
else:
self.failed_tests += 1
print("Failed!\n expected: '", expected, "'\n but got : '", expr, "'", sep = '')
return
def output(self, *objects, expected=""):
out = str_print(*objects)
self.equal(out, expected)
return
def summary(self):
print("------------------------------")
if self.failed_tests == 0:
print("All", self.num_tests, "passed!")
else:
print("{} out of {} tests failed!".format(self.failed_tests, self.num_tests))
def __enter__(self, *args):
print("\n\n------------------------------\n New Test run\n------------------------------")
return self
def __exit__(self, *args):
self.summary()