Debian Codegraph @

project/snippet/assertRaises.py

raw symbols SCIP
1
2 class AssertRaises(object):
3 def __init__(self, expected):
4 self.expected = expected
5
6 def __enter__(self):
7 return self
8
9 def __exit__(self, exc_type, exc_value, tb):
10 if exc_type is None:
11 try:
12 exc_name = self.expected.__name__
13 except AttributeError:
14 exc_name = str(self.expected)
15 raise AssertionError("{0} not raised".format(exc_name))
16 if not issubclass(exc_type, self.expected):
17 # let unexpected exceptions pass through
18 return False
19 return True