2014-04-01 21:19:21 +00:00
|
|
|
class TestCase:
|
|
|
|
|
|
|
|
def fail(self, msg):
|
|
|
|
assert False, msg
|
|
|
|
|
|
|
|
def assertEqual(self, x, y):
|
|
|
|
assert x == y, "%r vs %r" % (x, y)
|
|
|
|
|
|
|
|
def assertTrue(self, x):
|
|
|
|
assert x
|
|
|
|
|
|
|
|
def assertIn(self, x, y):
|
|
|
|
assert x in y
|
|
|
|
|
|
|
|
def assertIsInstance(self, x, y):
|
|
|
|
assert isinstance(x, y)
|
|
|
|
|
|
|
|
def assertRaises(self, exc, func, *args):
|
|
|
|
try:
|
|
|
|
func(*args)
|
|
|
|
assert False, "%r not raised" % exc
|
|
|
|
except Exception as e:
|
|
|
|
if isinstance(e, exc):
|
|
|
|
return
|
|
|
|
raise
|
2014-04-04 09:09:18 +00:00
|
|
|
|
|
|
|
|
2014-04-04 18:41:33 +00:00
|
|
|
def main(module="__main__"):
|
|
|
|
m = __import__(module)
|
|
|
|
for tn in dir(m):
|
|
|
|
c = getattr(m, tn)
|
2014-04-06 16:14:31 +00:00
|
|
|
if isinstance(c, object) and issubclass(c, TestCase):
|
2014-04-04 18:41:33 +00:00
|
|
|
o = c()
|
|
|
|
for name in dir(o):
|
|
|
|
if name.startswith("test"):
|
|
|
|
m = getattr(o, name)
|
|
|
|
m()
|
|
|
|
print(name, "...ok")
|