# Path: doubles/exceptions.py
# class VerifyingDoubleError(AssertionError):
#     """
#     An exception raised when attempting to double a method that does not exist on the real object.
#     """
# 
#     def __init__(self, method_name, doubled_obj):
#         """
#         :param str method_name: The name of the method to double.
#         :param object doubled_obj: The real object being doubled.
#         """
# 
#         self._method_name = method_name
#         self._doubled_obj = doubled_obj
#         self.args = (method_name, doubled_obj)
#         self.message = "Cannot double method '{}' of '{}'."
# 
#     def no_matching_method(self):
#         self.message = "Cannot double method '{}' because {} does not implement it."
# 
#         return self
# 
#     def not_callable(self):
#         self.message = "Cannot double method '{}' because it is not a callable attribute on {}."
# 
#         return self
# 
#     def requires_instance(self):
#         self.message = "Cannot double method '{}' because it is not callable directly on {}."
# 
#         return self
# 
#     def __str__(self):
#         return self.message.format(self._method_name, self._doubled_obj)
# 
# class VerifyingDoubleArgumentError(AssertionError):
#     """
#     An exception raised when attempting to double a method with arguments that do not match the
#     signature of the real method.
#     """
# 
#     pass
# 
# class UnallowedMethodCallError(AssertionError):
#     """An exception raised when an unallowed method call is made on a double."""
# 
#     pass
# 
# Path: doubles/lifecycle.py
# def teardown():
#     """Tears down the current Doubles environment. Must be called after each test case."""
#     if hasattr(_thread_local_data, 'current_space'):
#         _thread_local_data.current_space.teardown()
#         del _thread_local_data.current_space
# 
# Path: doubles/lifecycle.py
# @contextmanager
# def no_builtin_verification():
#     """Turn off validation for builtin methods
# 
#     While inside this context we will ignore errors raised while verifying the
#     arguments of builtins.
# 
#     Note: It is impossible to verify the expected arguments of built in functions
#     """
#     current_space().skip_builtin_verification = True
#     yield
#     current_space().skip_builtin_verification = False
# 
# Path: doubles/targets/allowance_target.py
# def allow(target):
#     """
#     Prepares a target object for a method call allowance (stub). The name of the method to allow
#     should be called as a method on the return value of this function::
# 
#         allow(foo).bar
# 
#     Accessing the ``bar`` attribute will return an ``Allowance`` which provides additional methods
#     to configure the stub.
# 
#     :param object target: The object that will be stubbed.
#     :return: An ``AllowanceTarget`` for the target object.
#     """
# 
#     return AllowanceTarget(target)
# 
# Path: doubles/testing.py
# class User(OldStyleUser, object):
#     pass
# 
# class OldStyleUser():
#     """An importable dummy class used for testing purposes."""
# 
#     class_attribute = 'foo'
#     callable_class_attribute = classmethod(lambda cls: 'dummy result')
#     arbitrary_callable = ArbitraryCallable('ArbitraryCallable Value')
# 
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#         self.callable_instance_attribute = lambda: 'dummy result'
# 
#     @staticmethod
#     def static_method(arg):
#         return 'static_method return value: {}'.format(arg)
# 
#     @classmethod
#     def class_method(cls, arg):
#         return 'class_method return value: {}'.format(arg)
# 
#     def get_name(self):
#         return self.name
# 
#     def instance_method(self):
#         return 'instance_method return value'
# 
#     def method_with_varargs(self, *args):
#         return 'method_with_varargs return value'
# 
#     def method_with_default_args(self, foo, bar='baz'):
#         return 'method_with_default_args return value'
# 
#     def method_with_varkwargs(self, **kwargs):
#         return 'method_with_varkwargs return value'
# 
#     def method_with_positional_arguments(self, foo):
#         return 'method_with_positional_arguments return value'
# 
#     def method_with_doc(self):
#         """A basic method of OldStyleUser to illustrate existence of a docstring"""
#         return
# 
#     @property
#     def some_property(self):
#         return 'some_property return value'
# 
#     def __call__(self, *args):
#         return 'user was called'
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         pass
# 
# class UserWithCustomNew(User):
#     def __new__(cls, name, age):
#         instance = User.__new__(cls)
#         instance.name_set_in__new__ = name
#         return instance


from pytest import raises, mark
from doubles.exceptions import (
    VerifyingDoubleError,
    VerifyingDoubleArgumentError,
    UnallowedMethodCallError,
)
from doubles.lifecycle import teardown
from doubles import allow, no_builtin_verification
from doubles.testing import User, OldStyleUser, UserWithCustomNew
import doubles.testing

        assert test_class.class_method('foo') == 'overridden value'

    def test_restores_class_methods_on_teardown(self, test_class):
        allow(test_class).class_method.and_return('overridden value')

        teardown()

        assert test_class.class_method('foo') == 'class_method return value: foo'

    def test_raises_when_stubbing_noncallable_attributes(self, test_class):
        with raises(VerifyingDoubleError):
            allow(test_class).class_attribute

    def test_raises_when_stubbing_nonexistent_class_methods(self, test_class):
        with raises(VerifyingDoubleError):
            allow(test_class).nonexistent_method


class TestBuiltInConstructorMethods(object):
    def test_stubs_constructors(self):
        with no_builtin_verification():
            user = object()

            allow(User).__new__.and_return(user)

            assert User('Alice', 25) is user

    def test_restores_constructor_on_teardown(self):
        user = object()

# Path: doubles/exceptions.py
# class VerifyingDoubleError(AssertionError):
#     """
#     An exception raised when attempting to double a method that does not exist on the real object.
#     """
# 
#     def __init__(self, method_name, doubled_obj):
#         """
#         :param str method_name: The name of the method to double.
#         :param object doubled_obj: The real object being doubled.
#         """
# 
#         self._method_name = method_name
#         self._doubled_obj = doubled_obj
#         self.args = (method_name, doubled_obj)
#         self.message = "Cannot double method '{}' of '{}'."
# 
#     def no_matching_method(self):
#         self.message = "Cannot double method '{}' because {} does not implement it."
# 
#         return self
# 
#     def not_callable(self):
#         self.message = "Cannot double method '{}' because it is not a callable attribute on {}."
# 
#         return self
# 
#     def requires_instance(self):
#         self.message = "Cannot double method '{}' because it is not callable directly on {}."
# 
#         return self
# 
#     def __str__(self):
#         return self.message.format(self._method_name, self._doubled_obj)
# 
# class VerifyingDoubleArgumentError(AssertionError):
#     """
#     An exception raised when attempting to double a method with arguments that do not match the
#     signature of the real method.
#     """
# 
#     pass
# 
# class UnallowedMethodCallError(AssertionError):
#     """An exception raised when an unallowed method call is made on a double."""
# 
#     pass
# 
# Path: doubles/lifecycle.py
# def teardown():
#     """Tears down the current Doubles environment. Must be called after each test case."""
#     if hasattr(_thread_local_data, 'current_space'):
#         _thread_local_data.current_space.teardown()
#         del _thread_local_data.current_space
# 
# Path: doubles/lifecycle.py
# @contextmanager
# def no_builtin_verification():
#     """Turn off validation for builtin methods
# 
#     While inside this context we will ignore errors raised while verifying the
#     arguments of builtins.
# 
#     Note: It is impossible to verify the expected arguments of built in functions
#     """
#     current_space().skip_builtin_verification = True
#     yield
#     current_space().skip_builtin_verification = False
# 
# Path: doubles/targets/allowance_target.py
# def allow(target):
#     """
#     Prepares a target object for a method call allowance (stub). The name of the method to allow
#     should be called as a method on the return value of this function::
# 
#         allow(foo).bar
# 
#     Accessing the ``bar`` attribute will return an ``Allowance`` which provides additional methods
#     to configure the stub.
# 
#     :param object target: The object that will be stubbed.
#     :return: An ``AllowanceTarget`` for the target object.
#     """
# 
#     return AllowanceTarget(target)
# 
# Path: doubles/testing.py
# class User(OldStyleUser, object):
#     pass
# 
# class OldStyleUser():
#     """An importable dummy class used for testing purposes."""
# 
#     class_attribute = 'foo'
#     callable_class_attribute = classmethod(lambda cls: 'dummy result')
#     arbitrary_callable = ArbitraryCallable('ArbitraryCallable Value')
# 
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#         self.callable_instance_attribute = lambda: 'dummy result'
# 
#     @staticmethod
#     def static_method(arg):
#         return 'static_method return value: {}'.format(arg)
# 
#     @classmethod
#     def class_method(cls, arg):
#         return 'class_method return value: {}'.format(arg)
# 
#     def get_name(self):
#         return self.name
# 
#     def instance_method(self):
#         return 'instance_method return value'
# 
#     def method_with_varargs(self, *args):
#         return 'method_with_varargs return value'
# 
#     def method_with_default_args(self, foo, bar='baz'):
#         return 'method_with_default_args return value'
# 
#     def method_with_varkwargs(self, **kwargs):
#         return 'method_with_varkwargs return value'
# 
#     def method_with_positional_arguments(self, foo):
#         return 'method_with_positional_arguments return value'
# 
#     def method_with_doc(self):
#         """A basic method of OldStyleUser to illustrate existence of a docstring"""
#         return
# 
#     @property
#     def some_property(self):
#         return 'some_property return value'
# 
#     def __call__(self, *args):
#         return 'user was called'
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         pass
# 
# class UserWithCustomNew(User):
#     def __new__(cls, name, age):
#         instance = User.__new__(cls)
#         instance.name_set_in__new__ = name
#         return instance


# Path: test/partial_double_test.py
from pytest import raises, mark
from doubles.exceptions import (
    VerifyingDoubleError,
    VerifyingDoubleArgumentError,
    UnallowedMethodCallError,
)
from doubles.lifecycle import teardown
from doubles import allow, no_builtin_verification
from doubles.testing import User, OldStyleUser, UserWithCustomNew
import doubles.testing


        assert test_class.class_method('foo') == 'overridden value'

    def test_restores_class_methods_on_teardown(self, test_class):
        allow(test_class).class_method.and_return('overridden value')

        teardown()

        assert test_class.class_method('foo') == 'class_method return value: foo'

    def test_raises_when_stubbing_noncallable_attributes(self, test_class):
        with raises(VerifyingDoubleError):
            allow(test_class).class_attribute

    def test_raises_when_stubbing_nonexistent_class_methods(self, test_class):
        with raises(VerifyingDoubleError):
            allow(test_class).nonexistent_method


class TestBuiltInConstructorMethods(object):
    def test_stubs_constructors(self):
        with no_builtin_verification():
            user = object()

            allow(User).__new__.and_return(user)

            assert User('Alice', 25) is user

    def test_restores_constructor_on_teardown(self):
        user = object()

        allow(User).__new__.and_return(user)