# Path: doubles/exceptions.py
# 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 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)
# 
# Path: doubles/object_double.py
# class ObjectDouble(object):
#     """
#     A pure double representing the target object.
# 
#     ::
# 
#         dummy_user = ObjectDouble(user)
# 
#     :param object target: The object the newly created ObjectDouble will verify against.
#     """
#     is_class = False
# 
#     def __init__(self, target):
#         self._doubles_target = target
# 
#     def __repr__(self):
#         """Provides a string representation of the double.
# 
#         NOTE: Includes the memory address and the name of the object being doubled.
# 
#         :return: A string representation of the double.
#         :rtype: str
#         """
# 
#         address = hex(id(self))
#         class_name = self.__class__.__name__
# 
#         return '<{} of {!r} object at {}>'.format(
#             class_name,
#             self._doubles_target,
#             address
#         )
# 
# 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


import re
from pytest import raises, mark
from doubles.exceptions import VerifyingDoubleArgumentError, VerifyingDoubleError
from doubles.object_double import ObjectDouble
from doubles.targets.allowance_target import allow
from doubles.testing import User, OldStyleUser
            repr(subject)
        )


@mark.parametrize('test_object', [user, old_style_user])
class TestObjectDouble(object):
    def test_allows_stubs_on_existing_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).get_name.and_return('Bob')

        assert doubled_user.get_name() == 'Bob'

    def test_raises_when_stubbing_nonexistent_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).foo

        assert re.search(r"does not implement it", str(e))

    def test_raises_when_stubbing_noncallable_attributes(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).class_attribute

        assert re.search(r"not a callable attribute", str(e))

    def test_raises_when_specifying_different_arity(self, test_object):

# Path: doubles/exceptions.py
# 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 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)
# 
# Path: doubles/object_double.py
# class ObjectDouble(object):
#     """
#     A pure double representing the target object.
# 
#     ::
# 
#         dummy_user = ObjectDouble(user)
# 
#     :param object target: The object the newly created ObjectDouble will verify against.
#     """
#     is_class = False
# 
#     def __init__(self, target):
#         self._doubles_target = target
# 
#     def __repr__(self):
#         """Provides a string representation of the double.
# 
#         NOTE: Includes the memory address and the name of the object being doubled.
# 
#         :return: A string representation of the double.
#         :rtype: str
#         """
# 
#         address = hex(id(self))
#         class_name = self.__class__.__name__
# 
#         return '<{} of {!r} object at {}>'.format(
#             class_name,
#             self._doubles_target,
#             address
#         )
# 
# 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


# Path: test/object_double_test.py
import re
from pytest import raises, mark
from doubles.exceptions import VerifyingDoubleArgumentError, VerifyingDoubleError
from doubles.object_double import ObjectDouble
from doubles.targets.allowance_target import allow
from doubles.testing import User, OldStyleUser

            repr(subject)
        )


@mark.parametrize('test_object', [user, old_style_user])
class TestObjectDouble(object):
    def test_allows_stubs_on_existing_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).get_name.and_return('Bob')

        assert doubled_user.get_name() == 'Bob'

    def test_raises_when_stubbing_nonexistent_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).foo

        assert re.search(r"does not implement it", str(e))

    def test_raises_when_stubbing_noncallable_attributes(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).class_attribute

        assert re.search(r"not a callable attribute", str(e))

    def test_raises_when_specifying_different_arity(self, test_object):

        doubled_user = ObjectDouble(test_object)