def test_single_wrapped(self): @self._wrapper def wrapped(self, instance, red=None, blue=None): pass func = utils.get_wrapped_function(wrapped) func_code = func.__code__ self.assertEqual(4, len(func_code.co_varnames)) self.assertIn('self', func_code.co_varnames) self.assertIn('instance', func_code.co_varnames) self.assertIn('red', func_code.co_varnames) self.assertIn('blue', func_code.co_varnames)
def test_single_wrapped(self): @self._wrapper def wrapped(self, instance, red=None, blue=None): pass func = utils.get_wrapped_function(wrapped) func_code = func.func_code self.assertEqual(4, len(func_code.co_varnames)) self.assertIn("self", func_code.co_varnames) self.assertIn("instance", func_code.co_varnames) self.assertIn("red", func_code.co_varnames) self.assertIn("blue", func_code.co_varnames)
def test_single_wrapped(self): @self._wrapper def wrapped(self, instance, red=None, blue=None): pass func = utils.get_wrapped_function(wrapped) func_code = func.func_code self.assertEqual(4, len(func_code.co_varnames)) self.assertTrue('self' in func_code.co_varnames) self.assertTrue('instance' in func_code.co_varnames) self.assertTrue('red' in func_code.co_varnames) self.assertTrue('blue' in func_code.co_varnames)
def test_double_wrapped(self): @self._wrapper @self._wrapper def wrapped(self, instance, red=None, blue=None): pass func = utils.get_wrapped_function(wrapped) func_code = func.func_code self.assertEqual(4, len(func_code.co_varnames)) self.assertTrue('self' in func_code.co_varnames) self.assertTrue('instance' in func_code.co_varnames) self.assertTrue('red' in func_code.co_varnames) self.assertTrue('blue' in func_code.co_varnames)
def test_double_wrapped(self): @self._wrapper @self._wrapper def wrapped(self, instance, red=None, blue=None): pass func = utils.get_wrapped_function(wrapped) func_code = func.__code__ self.assertEqual(4, len(func_code.co_varnames)) self.assertIn('self', func_code.co_varnames) self.assertIn('instance', func_code.co_varnames) self.assertIn('red', func_code.co_varnames) self.assertIn('blue', func_code.co_varnames)
def test_public_api_signatures(self): # NOTE(claudiub): wrapped functions do not keep the same signature in # Python 2.7, which causes this test to fail. Instead, we should # compare the public API signatures of the unwrapped methods. for attr in driver.HyperVDriver.__dict__: class_member = getattr(driver.HyperVDriver, attr) if callable(class_member): mocked_method = mock.patch.object( driver.HyperVDriver, attr, utils.get_wrapped_function(class_member)) mocked_method.start() self.addCleanup(mocked_method.stop) self.assertPublicAPISignatures(base_driver.ComputeDriver, driver.HyperVDriver)