Esempio n. 1
0
	def _get_target_for_method(self, name, in_dict):
		if not self._should_ever_assign_to_super(in_dict):
			return self._parent
		
		if not _special_method(name):
			return self._parent
			
		# otherwise, we'll be assigning to the *class* of self._parent
		# - so we better make it unique
		singletonclass.ensure_singleton_class(self._parent)
		return type(self._parent)
Esempio n. 2
0
def stub_method(obj, name):
	assert MockTransaction.started, "Mock transaction has not been started. Make sure you are inheriting from mocktest.TestCase"
	if _special_method(name) and not isinstance(obj, type):
		ensure_singleton_class(obj)
		obj = type(obj)
	add_teardown_for(obj, name)
	try:
		old_attr = getattr(obj, name)
		if isinstance(old_attr, StubbedMethod):
			return old_attr
	except AttributeError:
		pass
	new_attr = StubbedMethod(name)
	setattr(obj, name, new_attr)
	return new_attr