Exemplo n.º 1
0
 def test_no_value_error(self):
     with ctx_mgr(raising=True) as cm:
         self.assertTrue(print(int('abcd')))
Exemplo n.º 2
0
 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])
Exemplo n.º 3
0
 def test_zero_divide(self):
     with self.assertRaises(ZeroDivisionError):
         with ctx_mgr(raising=True) as cm:
             3/0
Exemplo n.º 4
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'])
Exemplo n.º 5
0
 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])