-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtestlib.py
executable file
·50 lines (40 loc) · 899 Bytes
/
testlib.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
#!/usr/bin/env python
from __future__ import division
import sys
from colors import *
NPASS = 0
NFAIL = 0
def begin(name=''):
"""Reset the pass and fail counters
"""
global NPASS, NFAIL
NPASS = NFAIL = 0
if name:
print 'beginning tests: ' + white(name)
else:
print 'beginning tests'
def end():
"""Print a summary of passes and fails
"""
global NPASS, NFAIL
print
if NFAIL:
print '%s tests passed'%NPASS
print red('%s tests failed'%NFAIL)
else:
print green('%s tests passed'%NPASS)
def passs():
global NPASS, NFAIL
print green('.'),
sys.stdout.flush()
NPASS += 1
def fail(msg=''):
global NPASS, NFAIL
NFAIL += 1
print
print red(' fail: %s'%msg)
def eq(a,b, msg=''):
"""Expect a and b to be equal. If not, fail.
"""
if a == b: passs()
else: fail(msg)