def test_spy_on(self): """Testing spy_on context manager""" obj = MathClass() with spy_on(obj.do_math): self.assertTrue(hasattr(obj.do_math, 'spy')) result = obj.do_math() self.assertEqual(result, 3) self.assertFalse(hasattr(obj.do_math, 'spy'))
def test_expose_spy(self): """Testing spy_on exposes `spy` via context manager""" obj = MathClass() with spy_on(obj.do_math) as spy: self.assertTrue(hasattr(obj.do_math, 'spy')) self.assertIs(obj.do_math.spy, spy) result = obj.do_math() self.assertEqual(result, 3) self.assertFalse(hasattr(obj.do_math, 'spy'))
def test_expose_spy(self): """Testing spy_on exposes `spy` via context manager""" obj = MathClass() orig_do_math = obj.do_math with spy_on(obj.do_math) as spy: self.assertTrue(isinstance(spy, FunctionSpy)) result = obj.do_math() self.assertEqual(result, 3) self.assertEqual(obj.do_math, orig_do_math)
def test_spy_on(self): """Testing spy_on context manager""" obj = MathClass() orig_do_math = obj.do_math with spy_on(obj.do_math): self.assertTrue(isinstance(obj.do_math, FunctionSpy)) result = obj.do_math() self.assertEqual(result, 3) self.assertEqual(obj.do_math, orig_do_math)