def test_no_value_error(self): with ctx_mgr(raising=True) as cm: self.assertTrue(print(int('abcd')))
def test_key_error(self): with self.assertRaises(KeyError): with ctx_mgr(raising=True) as cm: mydct = {'a':1, 'b':2, 'c':3} print(mydct[1])
def test_zero_divide(self): with self.assertRaises(ZeroDivisionError): with ctx_mgr(raising=True) as cm: 3/0
def test_type_error(self): with self.assertRaises(TypeError): with ctx_mgr(raising=True) as cm: mylst = [1,2,3,4,5] print(mylst['a'])
def test_index_error(self): with self.assertRaises(IndexError): with ctx_mgr(raising=True) as cm: mylst = [1,2,3,4,5] print(mylst[7])