-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathlibtest.py
45 lines (37 loc) · 1.12 KB
/
libtest.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
# Copyright 2018 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
"""
Simple test harness
"""
def assertRaises(expecting, fn, *args, **kwargs):
"""Check the exception was raised - don't check the text"""
try:
fn(*args, **kwargs)
except expecting as e:
pass
else:
assert False, "%s not raised" % (expecting,)
def assertRaisesText(expecting, text, fn, *args, **kwargs):
"""Check the exception with text in is raised"""
try:
fn(*args, **kwargs)
except expecting as e:
assert text in e.args[0], "'%s' not found in '%s'" % (text, e.args[0])
else:
assert False, "%s not raised" % (expecting,)
def assertTrue(x):
"""assert x is True"""
assert x
def assertFalse(x):
"""assert x is False"""
assert not x
def assertEqual(x, y):
"""assert x == y"""
assert x == y
def assertAlmostEqual(x, y, places=7):
"""assert x == y to places"""
assert round(abs(y-x), places) == 0
def fail(x):
"""Fails with error message"""
assert False, x