1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/python/mock-1.0.0/PKG-INFO Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,208 @@ 1.4 +Metadata-Version: 1.0 1.5 +Name: mock 1.6 +Version: 1.0.0 1.7 +Summary: A Python Mocking and Patching Library for Testing 1.8 +Home-page: http://www.voidspace.org.uk/python/mock/ 1.9 +Author: Michael Foord 1.10 +Author-email: michael@voidspace.org.uk 1.11 +License: UNKNOWN 1.12 +Description: mock is a library for testing in Python. It allows you to replace parts of 1.13 + your system under test with mock objects and make assertions about how they 1.14 + have been used. 1.15 + 1.16 + mock is now part of the Python standard library, available as `unittest.mock < 1.17 + http://docs.python.org/py3k/library/unittest.mock.html#module-unittest.mock>`_ 1.18 + in Python 3.3 onwards. 1.19 + 1.20 + mock provides a core `MagicMock` class removing the need to create a host of 1.21 + stubs throughout your test suite. After performing an action, you can make 1.22 + assertions about which methods / attributes were used and arguments they were 1.23 + called with. You can also specify return values and set needed attributes in 1.24 + the normal way. 1.25 + 1.26 + mock is tested on Python versions 2.4-2.7 and Python 3. mock is also tested 1.27 + with the latest versions of Jython and pypy. 1.28 + 1.29 + The mock module also provides utility functions / objects to assist with 1.30 + testing, particularly monkey patching. 1.31 + 1.32 + * `PDF documentation for 1.0 beta 1 1.33 + <http://www.voidspace.org.uk/downloads/mock-1.0.0.pdf>`_ 1.34 + * `mock on google code (repository and issue tracker) 1.35 + <http://code.google.com/p/mock/>`_ 1.36 + * `mock documentation 1.37 + <http://www.voidspace.org.uk/python/mock/>`_ 1.38 + * `mock on PyPI <http://pypi.python.org/pypi/mock/>`_ 1.39 + * `Mailing list (testing-in-python@lists.idyll.org) 1.40 + <http://lists.idyll.org/listinfo/testing-in-python>`_ 1.41 + 1.42 + Mock is very easy to use and is designed for use with 1.43 + `unittest <http://pypi.python.org/pypi/unittest2>`_. Mock is based on 1.44 + the 'action -> assertion' pattern instead of 'record -> replay' used by many 1.45 + mocking frameworks. See the `mock documentation`_ for full details. 1.46 + 1.47 + Mock objects create all attributes and methods as you access them and store 1.48 + details of how they have been used. You can configure them, to specify return 1.49 + values or limit what attributes are available, and then make assertions about 1.50 + how they have been used:: 1.51 + 1.52 + >>> from mock import Mock 1.53 + >>> real = ProductionClass() 1.54 + >>> real.method = Mock(return_value=3) 1.55 + >>> real.method(3, 4, 5, key='value') 1.56 + 3 1.57 + >>> real.method.assert_called_with(3, 4, 5, key='value') 1.58 + 1.59 + `side_effect` allows you to perform side effects, return different values or 1.60 + raise an exception when a mock is called:: 1.61 + 1.62 + >>> mock = Mock(side_effect=KeyError('foo')) 1.63 + >>> mock() 1.64 + Traceback (most recent call last): 1.65 + ... 1.66 + KeyError: 'foo' 1.67 + >>> values = {'a': 1, 'b': 2, 'c': 3} 1.68 + >>> def side_effect(arg): 1.69 + ... return values[arg] 1.70 + ... 1.71 + >>> mock.side_effect = side_effect 1.72 + >>> mock('a'), mock('b'), mock('c') 1.73 + (3, 2, 1) 1.74 + >>> mock.side_effect = [5, 4, 3, 2, 1] 1.75 + >>> mock(), mock(), mock() 1.76 + (5, 4, 3) 1.77 + 1.78 + Mock has many other ways you can configure it and control its behaviour. For 1.79 + example the `spec` argument configures the mock to take its specification from 1.80 + another object. Attempting to access attributes or methods on the mock that 1.81 + don't exist on the spec will fail with an `AttributeError`. 1.82 + 1.83 + The `patch` decorator / context manager makes it easy to mock classes or 1.84 + objects in a module under test. The object you specify will be replaced with a 1.85 + mock (or other object) during the test and restored when the test ends:: 1.86 + 1.87 + >>> from mock import patch 1.88 + >>> @patch('test_module.ClassName1') 1.89 + ... @patch('test_module.ClassName2') 1.90 + ... def test(MockClass2, MockClass1): 1.91 + ... test_module.ClassName1() 1.92 + ... test_module.ClassName2() 1.93 + 1.94 + ... assert MockClass1.called 1.95 + ... assert MockClass2.called 1.96 + ... 1.97 + >>> test() 1.98 + 1.99 + .. note:: 1.100 + 1.101 + When you nest patch decorators the mocks are passed in to the decorated 1.102 + function in the same order they applied (the normal *python* order that 1.103 + decorators are applied). This means from the bottom up, so in the example 1.104 + above the mock for `test_module.ClassName2` is passed in first. 1.105 + 1.106 + With `patch` it matters that you patch objects in the namespace where they 1.107 + are looked up. This is normally straightforward, but for a quick guide 1.108 + read `where to patch 1.109 + <http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch>`_. 1.110 + 1.111 + As well as a decorator `patch` can be used as a context manager in a with 1.112 + statement:: 1.113 + 1.114 + >>> with patch.object(ProductionClass, 'method') as mock_method: 1.115 + ... mock_method.return_value = None 1.116 + ... real = ProductionClass() 1.117 + ... real.method(1, 2, 3) 1.118 + ... 1.119 + >>> mock_method.assert_called_once_with(1, 2, 3) 1.120 + 1.121 + There is also `patch.dict` for setting values in a dictionary just during the 1.122 + scope of a test and restoring the dictionary to its original state when the 1.123 + test ends:: 1.124 + 1.125 + >>> foo = {'key': 'value'} 1.126 + >>> original = foo.copy() 1.127 + >>> with patch.dict(foo, {'newkey': 'newvalue'}, clear=True): 1.128 + ... assert foo == {'newkey': 'newvalue'} 1.129 + ... 1.130 + >>> assert foo == original 1.131 + 1.132 + Mock supports the mocking of Python magic methods. The easiest way of 1.133 + using magic methods is with the `MagicMock` class. It allows you to do 1.134 + things like:: 1.135 + 1.136 + >>> from mock import MagicMock 1.137 + >>> mock = MagicMock() 1.138 + >>> mock.__str__.return_value = 'foobarbaz' 1.139 + >>> str(mock) 1.140 + 'foobarbaz' 1.141 + >>> mock.__str__.assert_called_once_with() 1.142 + 1.143 + Mock allows you to assign functions (or other Mock instances) to magic methods 1.144 + and they will be called appropriately. The MagicMock class is just a Mock 1.145 + variant that has all of the magic methods pre-created for you (well - all the 1.146 + useful ones anyway). 1.147 + 1.148 + The following is an example of using magic methods with the ordinary Mock 1.149 + class:: 1.150 + 1.151 + >>> from mock import Mock 1.152 + >>> mock = Mock() 1.153 + >>> mock.__str__ = Mock(return_value = 'wheeeeee') 1.154 + >>> str(mock) 1.155 + 'wheeeeee' 1.156 + 1.157 + For ensuring that the mock objects your tests use have the same api as the 1.158 + objects they are replacing, you can use "auto-speccing". Auto-speccing can 1.159 + be done through the `autospec` argument to patch, or the `create_autospec` 1.160 + function. Auto-speccing creates mock objects that have the same attributes 1.161 + and methods as the objects they are replacing, and any functions and methods 1.162 + (including constructors) have the same call signature as the real object. 1.163 + 1.164 + This ensures that your mocks will fail in the same way as your production 1.165 + code if they are used incorrectly:: 1.166 + 1.167 + >>> from mock import create_autospec 1.168 + >>> def function(a, b, c): 1.169 + ... pass 1.170 + ... 1.171 + >>> mock_function = create_autospec(function, return_value='fishy') 1.172 + >>> mock_function(1, 2, 3) 1.173 + 'fishy' 1.174 + >>> mock_function.assert_called_once_with(1, 2, 3) 1.175 + >>> mock_function('wrong arguments') 1.176 + Traceback (most recent call last): 1.177 + ... 1.178 + TypeError: <lambda>() takes exactly 3 arguments (1 given) 1.179 + 1.180 + `create_autospec` can also be used on classes, where it copies the signature of 1.181 + the `__init__` method, and on callable objects where it copies the signature of 1.182 + the `__call__` method. 1.183 + 1.184 + The distribution contains tests and documentation. The tests require 1.185 + `unittest2 <http://pypi.python.org/pypi/unittest2>`_ to run. 1.186 + 1.187 + Docs from the in-development version of `mock` can be found at 1.188 + `mock.readthedocs.org <http://mock.readthedocs.org>`_. 1.189 + 1.190 +Keywords: testing,test,mock,mocking,unittest,patching,stubs,fakes,doubles 1.191 +Platform: UNKNOWN 1.192 +Classifier: Development Status :: 5 - Production/Stable 1.193 +Classifier: Environment :: Console 1.194 +Classifier: Intended Audience :: Developers 1.195 +Classifier: License :: OSI Approved :: BSD License 1.196 +Classifier: Programming Language :: Python 1.197 +Classifier: Programming Language :: Python :: 2 1.198 +Classifier: Programming Language :: Python :: 3 1.199 +Classifier: Programming Language :: Python :: 2.4 1.200 +Classifier: Programming Language :: Python :: 2.5 1.201 +Classifier: Programming Language :: Python :: 2.6 1.202 +Classifier: Programming Language :: Python :: 2.7 1.203 +Classifier: Programming Language :: Python :: 3.1 1.204 +Classifier: Programming Language :: Python :: 3.2 1.205 +Classifier: Programming Language :: Python :: Implementation :: CPython 1.206 +Classifier: Programming Language :: Python :: Implementation :: PyPy 1.207 +Classifier: Programming Language :: Python :: Implementation :: Jython 1.208 +Classifier: Operating System :: OS Independent 1.209 +Classifier: Topic :: Software Development :: Libraries 1.210 +Classifier: Topic :: Software Development :: Libraries :: Python Modules 1.211 +Classifier: Topic :: Software Development :: Testing