2012-03-29 17:43:05 -04:00
|
|
|
# Just some helpers for test functions
|
|
|
|
|
|
|
|
import shutil, os
|
|
|
|
|
2012-04-04 18:34:01 -04:00
|
|
|
def myrepr(x):
|
|
|
|
if isinstance(x, basestring):
|
|
|
|
return '"' + x + '"'
|
|
|
|
else:
|
|
|
|
return repr(x)
|
|
|
|
|
2012-03-29 17:43:05 -04:00
|
|
|
def eq_(a, b):
|
|
|
|
if not a == b:
|
2012-04-04 18:34:01 -04:00
|
|
|
raise AssertionError("%s != %s" % (myrepr(a), myrepr(b)))
|
2012-03-29 17:43:05 -04:00
|
|
|
|
2013-01-09 17:36:47 -05:00
|
|
|
def lt_(a, b):
|
|
|
|
if not a < b:
|
|
|
|
raise AssertionError("%s is not less than %s" % (myrepr(a), myrepr(b)))
|
|
|
|
|
2012-03-29 17:43:05 -04:00
|
|
|
def in_(a, b):
|
|
|
|
if a not in b:
|
2012-04-04 18:34:01 -04:00
|
|
|
raise AssertionError("%s not in %s" % (myrepr(a), myrepr(b)))
|
2012-03-29 17:43:05 -04:00
|
|
|
|
2013-03-04 11:44:17 -05:00
|
|
|
def in2_(a1, a2, b):
|
|
|
|
if a1 not in b and a2 not in b:
|
|
|
|
raise AssertionError("(%s or %s) not in %s" % (myrepr(a1), myrepr(a2),
|
|
|
|
myrepr(b)))
|
|
|
|
|
2012-03-29 17:43:05 -04:00
|
|
|
def ne_(a, b):
|
|
|
|
if not a != b:
|
2012-04-04 18:34:01 -04:00
|
|
|
raise AssertionError("unexpected %s == %s" % (myrepr(a), myrepr(b)))
|
2012-03-29 17:43:05 -04:00
|
|
|
|
2012-12-11 23:31:55 -05:00
|
|
|
def lines_(a, n):
|
2012-12-12 19:25:27 -05:00
|
|
|
l = a.count('\n')
|
|
|
|
if not l == n:
|
2013-01-04 16:51:05 -05:00
|
|
|
if len(a) > 5000:
|
|
|
|
a = a[0:5000] + " ... truncated"
|
2012-12-12 19:25:27 -05:00
|
|
|
raise AssertionError("wanted %d lines, got %d in output: '%s'"
|
|
|
|
% (n, l, a))
|
2012-12-11 23:31:55 -05:00
|
|
|
|
2012-03-29 17:43:05 -04:00
|
|
|
def recursive_unlink(path):
|
|
|
|
try:
|
|
|
|
shutil.rmtree(path)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|