def test_explicit_call(self): def p(x): if x == 'p': raise ValueError('p') def m(x): if x == 'm': raise ValueError('m') def n(x): if x == 'n': raise ValueError('n') dbc.before(func_zorro)((p,m)) dbc.after(func_zorro)(n) res = func_zorro(None) self.assertEquals(res, "zorro") with self.assertRaises(ValueError) as e: func_zorro('p') self.assertEquals(e.exception.message, 'p') with self.assertRaises(ValueError) as e: func_zorro('m') self.assertEquals(e.exception.message, 'm') with self.assertRaises(ValueError) as e: func_zorro('n') self.assertEquals(e.exception.message, 'n')
def test_calling_cond_alone(self): class Aloha: def m(self, x): return x+1 def p(self, x): if self == 8: raise ValueError("buffy") return 7 q = dbc.before(Aloha, 'm')(p) with self.assertRaises(ValueError) as e: q(8, 7) self.assertEquals(e.exception.message, "buffy") self.assertEquals(q(None, 3), 7) @dbc.after(Aloha.m) def z(self, x): return 17 self.assertEquals(z(None, None), 17)