# 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)
# 
# Path: doubles/utils.py
# def get_module(module_path, full_path):
#     """Return the module given its path.
# 
#     :param str module_path: The path to the module to import.
#     :param str full_path: The full path to the class that will be doubled.
#     :return: The module object.
#     :rtype: module
#     :raise: ``VerifyingDoubleImportError`` if the module can't be imported.
#     """
# 
#     try:
#         return import_module(module_path)
#     except ImportError:
#         raise VerifyingDoubleImportError('Cannot import object from path: {}.'.format(full_path))
# 
# def get_path_components(path):
#     """Extract the module name and class name out of the fully qualified path to the class.
# 
#     :param str path: The full path to the class.
#     :return: The module path and the class name.
#     :rtype: str, str
#     :raise: ``VerifyingDoubleImportError`` if the path is to a top-level module.
#     """
# 
#     path_segments = path.split('.')
#     module_path = '.'.join(path_segments[:-1])
# 
#     if module_path == '':
#         raise VerifyingDoubleImportError('Invalid import path: {}.'.format(path))
# 
#     class_name = path_segments[-1]
# 
#     return module_path, class_name


from doubles.exceptions import VerifyingDoubleError
from doubles.utils import get_module, get_path_components


class Patch(object):
    """
    A wrapper around an object that has been ``patched``
    """
    def __init__(self, target):
        """
        :param str path: The absolute module path to the class.
        """
        module_path, self._name = get_path_components(target)

# 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)
# 
# Path: doubles/utils.py
# def get_module(module_path, full_path):
#     """Return the module given its path.
# 
#     :param str module_path: The path to the module to import.
#     :param str full_path: The full path to the class that will be doubled.
#     :return: The module object.
#     :rtype: module
#     :raise: ``VerifyingDoubleImportError`` if the module can't be imported.
#     """
# 
#     try:
#         return import_module(module_path)
#     except ImportError:
#         raise VerifyingDoubleImportError('Cannot import object from path: {}.'.format(full_path))
# 
# def get_path_components(path):
#     """Extract the module name and class name out of the fully qualified path to the class.
# 
#     :param str path: The full path to the class.
#     :return: The module path and the class name.
#     :rtype: str, str
#     :raise: ``VerifyingDoubleImportError`` if the path is to a top-level module.
#     """
# 
#     path_segments = path.split('.')
#     module_path = '.'.join(path_segments[:-1])
# 
#     if module_path == '':
#         raise VerifyingDoubleImportError('Invalid import path: {}.'.format(path))
# 
#     class_name = path_segments[-1]
# 
#     return module_path, class_name


# Path: doubles/patch.py
from doubles.exceptions import VerifyingDoubleError
from doubles.utils import get_module, get_path_components



class Patch(object):
    """
    A wrapper around an object that has been ``patched``
    """
    def __init__(self, target):
        """
        :param str path: The absolute module path to the class.
        """
        module_path, self._name = get_path_components(target)

        self.target = get_module(module_path, target)