Repository navigation
Expand file tree
/
Copy pathcommon.py
More file actions
46 lines (38 loc) · 1.5 KB
/
Copy pathcommon.py
File metadata and controls
46 lines (38 loc) · 1.5 KB
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
try:
from nose.plugins.skip import SkipTest
except ImportError:
try:
from unittest.case import SkipTest # Python >= 2.7
except ImportError:
try:
from unittest2.case import SkipTest # Python < 2.7
except ImportError:
class SkipTest(Exception):
"""Raise this exception to mark a test as skipped.
"""
pass
try:
from nose.tools import assert_equal, assert_in, assert_raises
except ImportError:
def assert_equal(expected, result):
print("Expected:\n%s\n" % expected)
print("Got:\n%s\n" % result)
assert expected == result
def assert_in(result, expected_set):
nums = xrange(1, len(expected_set)+1)
for i, expected in zip(nums, expected_set):
print("Expected %d:\n%s\n" % (i, expected))
print("Got:\n%s\n" % result)
assert result in expected_set
class assert_raises(object):
def __init__(self, exception_type):
self.watch_exception_type = exception_type
def __enter__(self):
pass
def __exit__(self, exception_type, exception_value, traceback):
if isinstance(exception_value, self.watch_exception_type):
return True # suppress exception
elif exception_type is None:
msg = "%s not raised" % self.watch_exception_type.__name__
raise AssertionError(msg)
# otherwise propagate whatever other exception is raised