-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathtestlib.py
More file actions
27 lines (23 loc) · 772 Bytes
/
testlib.py
File metadata and controls
27 lines (23 loc) · 772 Bytes
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
def expects(n):
def check_output(output):
lines = output.splitlines()
if all(s == "OK" for s in lines):
if len(lines) == n:
print("OK")
else:
print("Expected", n, "outputs but got", len(lines))
else:
print(list(s for s in lines if s != "OK"))
def wrap(f):
def wrapped(*args, **kwargs):
from io import StringIO
import sys
capturer = StringIO()
old_stdout = sys.stdout
sys.stdout = capturer
f(*args, **kwargs)
sys.stdout = old_stdout
check_output(capturer.getvalue())
wrapped.__name__ = "[" + str(n) + "]" + f.__name__
return wrapped
return wrap