From 0ab12c4671a62dd67febc1805ec083cb81b1e1bd Mon Sep 17 00:00:00 2001 From: Michael Foord <michael@python.org> Date: Sat, 14 May 2011 12:12:52 +0200 Subject: [PATCH] Testing call --- README.txt | 4 ++-- docs/index.txt | 10 ++++++---- tests/testhelpers.py | 37 ++++++++++++++++++------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/README.txt b/README.txt index 4b423aa..16b7dec 100644 --- a/README.txt +++ b/README.txt @@ -9,8 +9,8 @@ mock is tested on Python versions 2.4-2.7 and Python 3. The mock module also provides utility functions / objects to assist with testing, particularly monkey patching. -* `PDF documentation for 0.7.1 - <http://www.voidspace.org.uk/downloads/mock-0.7.1.pdf>`_ +* `PDF documentation for 0.8.0 alpha 1 + <http://www.voidspace.org.uk/downloads/mock-0.8.0a1.pdf>`_ * `mock on google code (repository and issue tracker) <http://code.google.com/p/mock/>`_ * `mock documentation diff --git a/docs/index.txt b/docs/index.txt index 7169f84..291a20f 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -7,10 +7,10 @@ :Author: `Michael Foord <http://www.voidspace.org.uk/python/weblog/index.shtml>`_ :Co-maintainer: `Konrad Delong <http://konryd.blogspot.com/>`_ :Version: |release| -:Date: 2011/03/05 +:Date: 2011/XX/XX :Homepage: `Mock Homepage`_ :Download: `Mock on PyPI`_ -:Documentation: `PDF Documentation <http://www.voidspace.org.uk/downloads/mock-0.7.1.pdf>`_ +:Documentation: `PDF Documentation <http://www.voidspace.org.uk/downloads/mock-0.8.0a1.pdf>`_ :License: `BSD License`_ :Support: `Mailing list (testing-in-python@lists.idyll.org) <http://lists.idyll.org/listinfo/testing-in-python>`_ :Issue tracker: `Google code project <http://code.google.com/p/mock/issues/list>`_ @@ -44,7 +44,6 @@ mocking frameworks. mock is tested on Python versions 2.4-2.7 and Python 3. - .. testsetup:: import sys @@ -333,7 +332,10 @@ Older Versions Documentation for older versions of mock: -* `mock 0.6.0 <http://www.voidspace.org.uk/python/mock/0.6.0/>`_ +# 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/>`_ Terminology diff --git a/tests/testhelpers.py b/tests/testhelpers.py index 155f13d..134b0da 100644 --- a/tests/testhelpers.py +++ b/tests/testhelpers.py @@ -28,25 +28,6 @@ class AnyTest(unittest2.TestCase): class CallTest(unittest2.TestCase): """ - >>> mock = Mock(return_value=None) - >>> mock(1, 2, 3) - >>> mock(a=3, b=6) - >>> mock.call_args_list == [call(1, 2, 3), call(a=3, b=6)] - True - - >>> mock = Mock() - >>> mock.foo(1, 2 ,3) - <mock.Mock object at 0x...> - >>> mock.bar.baz(a=3, b=6) - <mock.Mock object at 0x...> - >>> mock.method_calls == [call.foo(1, 2, 3), call.bar.baz(a=3, b=6)] - True - -And for good measure, the first example (tracking order of calls between -mocks) using the new `call` object for assertions: - -.. doctest:: - >>> manager = Mock() >>> mock_foo = manager.foo @@ -71,3 +52,21 @@ mocks) using the new `call` object for assertions: self.assertEqual(call(), ((), {})) self.assertEqual(call('foo', 'bar', one=3, two=4), (('foo', 'bar'), {'one': 3, 'two': 4})) + + mock = Mock() + mock(1, 2, 3) + mock(a=3, b=6) + self.assertEqual(mock.call_args_list, + [call(1, 2, 3), call(a=3, b=6)]) + + def test_attribute_call(self): + self.assertEqual(call.foo(1), ('foo', (1,), {})) + self.assertEqual(call.bar.baz(fish='eggs'), + ('bar.baz', (), {'fish': 'eggs'})) + + mock = Mock() + mock.foo(1, 2 ,3) + mock.bar.baz(a=3, b=6) + self.assertEqual(mock.method_calls, + [call.foo(1, 2, 3), call.bar.baz(a=3, b=6)]) + -- GitLab