From 8bf4f4ec0b6e97f1a62ce461121b523ee7f76d11 Mon Sep 17 00:00:00 2001 From: Michael Foord <michael@voidspace.org.uk> Date: Thu, 29 Dec 2011 14:40:32 +0000 Subject: [PATCH] Doc updates --- README.txt | 13 ++++++------- docs/changelog.txt | 2 +- docs/examples.txt | 4 ++++ docs/index.txt | 2 -- mock.py | 1 - 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.txt b/README.txt index db11006..69ed064 100644 --- a/README.txt +++ b/README.txt @@ -2,8 +2,8 @@ mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used. -mock provides a core Mock class removing the need to create a host of stubs -throughout your test suite. After performing an action, you can make +mock provides a core `MagicMock` class removing the need to create a host of +stubs throughout your test suite. After performing an action, you can make assertions about which methods / attributes were used and arguments they were called with. You can also specify return values and set needed attributes in the normal way. @@ -101,7 +101,7 @@ statement:: ... real = ProductionClass() ... real.method(1, 2, 3) ... - >>> mock_method.assert_called_with(1, 2, 3) + >>> mock_method.assert_called_once_with(1, 2, 3) There is also `patch.dict` for setting values in a dictionary just during the scope of a test and restoring the dictionary to its original state when the @@ -114,7 +114,7 @@ test ends:: ... >>> assert foo == original -Mock now supports the mocking of Python magic methods. The easiest way of +Mock supports the mocking of Python magic methods. The easiest way of using magic methods is with the `MagicMock` class. It allows you to do things like:: @@ -123,7 +123,7 @@ things like:: >>> mock.__str__.return_value = 'foobarbaz' >>> str(mock) 'foobarbaz' - >>> mock.__str__.assert_called_with() + >>> mock.__str__.assert_called_once_with() Mock allows you to assign functions (or other Mock instances) to magic methods and they will be called appropriately. The MagicMock class is just a Mock @@ -135,8 +135,7 @@ class:: >>> from mock import Mock >>> mock = Mock() - >>> mock.__str__ = Mock() - >>> mock.__str__.return_value = 'wheeeeee' + >>> mock.__str__ = Mock(return_value = 'wheeeeee') >>> str(mock) 'wheeeeee' diff --git a/docs/changelog.txt b/docs/changelog.txt index cbafd11..2162f73 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -161,7 +161,7 @@ mock 0.8.0 is the last version that will support Python 2.4. 2011/12/29 Version 0.8.0 release candidate 1 -------------------------------------------- -* `create_autospec` on the return value of a mock class will use `__call__` +* `create_autospec` on the return value of a mocked class will use `__call__` for the signature rather than `__init__` * Performance improvement instantiating `Mock` and `MagicMock` * Mocks used as magic methods have the same type as their parent instead of diff --git a/docs/examples.txt b/docs/examples.txt index 8acd038..461db0f 100644 --- a/docs/examples.txt +++ b/docs/examples.txt @@ -185,6 +185,10 @@ algorithm as the code under test, which is a classic testing anti-pattern. Calls to the date constructor are recorded in the `mock_date` attributes (`call_count` and friends) which may also be useful for your tests. +An alternative way of dealing with mocking dates, or other builtin classes, +is discussed in `this blog entry +<http://williamjohnbert.com/2011/07/how-to-unit-testing-in-django-with-mocking-and-patching/>`_. + Mocking open ============ diff --git a/docs/index.txt b/docs/index.txt index 1f649b8..3790ead 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -352,8 +352,6 @@ Older Versions Documentation for older versions of mock: -# XXXX - * `mock 0.7 <http://www.voidspace.org.uk/python/mock/0.7/>`_ * `mock 0.6 <http://www.voidspace.org.uk/python/mock/0.6.0/>`_ diff --git a/mock.py b/mock.py index 167e341..328e726 100644 --- a/mock.py +++ b/mock.py @@ -664,7 +664,6 @@ class NonCallableMock(Base): ret = self._mock_return_value if _is_instance_mock(ret) and ret is not self: ret.reset_mock() - # XXXX this doesn't reset the return value on a mocksignature mock def configure_mock(self, **kwargs): -- GitLab