# Path: doubles/nose.py
# class NoseIntegration(Plugin):
#     name = 'doubles'
# 
#     def afterTest(self, test):
#         teardown()
# 
#     def prepareTestCase(self, test):
#         def wrapped(result):
#             test.test(result)
# 
#             try:
#                 verify()
#             except MockExpectationError:
#                 result.addFailure(test.test,  sys.exc_info())
# 
#         return wrapped
# 
# Path: doubles/instance_double.py
# class InstanceDouble(ObjectDouble):
#     """A pure double representing an instance of the target class.
# 
#     Any kwargs supplied will be set as attributes on the instance that is
#     created.
# 
#     ::
# 
#         user = InstanceDouble('myapp.User', name='Bob Barker')
# 
#     :param str path: The absolute module path to the class.
#     """
# 
#     def __init__(self, path, **kwargs):
#         module_path, class_name = get_path_components(path)
#         module = get_module(module_path, path)
#         self._doubles_target = _get_doubles_target(module, class_name, path)
#         for k, v in kwargs.items():
#             setattr(self, k, v)
# 
# Path: doubles/targets/expectation_target.py
# def expect(target):
#     """
#     Prepares a target object for a method call expectation (mock). The name of the method to expect
#     should be called as a method on the return value of this function::
# 
#         expect(foo).bar
# 
#     Accessing the ``bar`` attribute will return an ``Expectation`` which provides additional methods
#     to configure the mock.
# 
#     :param object target: The object that will be mocked.
#     :return: An ``ExpectationTarget`` for the target object.
#     """
# 
#     return ExpectationTarget(target)


import unittest
from nose.plugins import PluginTester
from doubles.nose import NoseIntegration
from doubles.instance_double import InstanceDouble
from doubles.targets.expectation_target import expect




def test_nose_plugin():
    class TestNosePlugin(PluginTester, unittest.TestCase):
        activate = '--with-doubles'
        plugins = [NoseIntegration()]

        def test_expect(self):
            assert 'MockExpectationError' in self.output
            assert 'FAILED (failures=1)' in self.output
            assert 'Ran 2 tests' in self.output

        def makeSuite(self):
            class TestCase(unittest.TestCase):
                def runTest(self):
                    subject = InstanceDouble('doubles.testing.User')


# Path: doubles/nose.py
# class NoseIntegration(Plugin):
#     name = 'doubles'
# 
#     def afterTest(self, test):
#         teardown()
# 
#     def prepareTestCase(self, test):
#         def wrapped(result):
#             test.test(result)
# 
#             try:
#                 verify()
#             except MockExpectationError:
#                 result.addFailure(test.test,  sys.exc_info())
# 
#         return wrapped
# 
# Path: doubles/instance_double.py
# class InstanceDouble(ObjectDouble):
#     """A pure double representing an instance of the target class.
# 
#     Any kwargs supplied will be set as attributes on the instance that is
#     created.
# 
#     ::
# 
#         user = InstanceDouble('myapp.User', name='Bob Barker')
# 
#     :param str path: The absolute module path to the class.
#     """
# 
#     def __init__(self, path, **kwargs):
#         module_path, class_name = get_path_components(path)
#         module = get_module(module_path, path)
#         self._doubles_target = _get_doubles_target(module, class_name, path)
#         for k, v in kwargs.items():
#             setattr(self, k, v)
# 
# Path: doubles/targets/expectation_target.py
# def expect(target):
#     """
#     Prepares a target object for a method call expectation (mock). The name of the method to expect
#     should be called as a method on the return value of this function::
# 
#         expect(foo).bar
# 
#     Accessing the ``bar`` attribute will return an ``Expectation`` which provides additional methods
#     to configure the mock.
# 
#     :param object target: The object that will be mocked.
#     :return: An ``ExpectationTarget`` for the target object.
#     """
# 
#     return ExpectationTarget(target)


# Path: test/nose_test.py
import unittest
from nose.plugins import PluginTester
from doubles.nose import NoseIntegration
from doubles.instance_double import InstanceDouble
from doubles.targets.expectation_target import expect





def test_nose_plugin():
    class TestNosePlugin(PluginTester, unittest.TestCase):
        activate = '--with-doubles'
        plugins = [NoseIntegration()]

        def test_expect(self):
            assert 'MockExpectationError' in self.output
            assert 'FAILED (failures=1)' in self.output
            assert 'Ran 2 tests' in self.output

        def makeSuite(self):
            class TestCase(unittest.TestCase):
                def runTest(self):
                    subject = InstanceDouble('doubles.testing.User')


                    expect(subject).instance_method