def test_badnumber(self): try: int("a3") except: exc, stack = sys.get_exc() assert "TypeError" in exc try: float("3ffff") except: exc, stack = sys.get_exc() assert "TypeError" in exc assert int("3.0") == 3.0 assert int("-3.0") == -3.0
def test_index(self): a = "012345" assert a.index("0") == 0 try: assert a.index("9") == -1 except: assert "ValueError" in sys.get_exc()[0]
def test_str_exc(self): try: raise "Hello" except: exc, stack = sys.get_exc() assert exc == "Hello" assert "test_str_exc" in stack
def runone(self, test, testfunc): self.setup(test) try: testfunc(self) return TestResult(test, True, None, None) except: exc, stack = sys.get_exc() return TestResult(test, False, exc, stack) self.teardown(test)
def __exit__(self): assert self.active exc = (None, None, None) while self.contexts: try: if self.contexts.pop(-1).__exit__(*exc): exc = (None, None, None) except: exc = sys.get_exc() self.active = False if exc != (None, None, None): raise exc[0], exc[1], exc[2]
def __exit__(self): assert self.active exc = (None,None,None) while self.contexts: try: if self.contexts.pop(-1).__exit__(*exc): exc = (None,None,None) except: exc = sys.get_exc() self.active = False if exc != (None,None,None): raise exc[0],exc[1],exc[2]
def test_no_exc(self): assert sys.get_exc()[0] is None
def test_keyerror(self): try: {}['a'] except: assert "(tpd_dict_get) KeyError: a" in sys.get_exc()[0]
def test_lessthan(self): try: assert {'a': 1, 'b': 2} < {'a': 1, 'c': 2} except: assert 'TypeError' in sys.get_exc()[0]