Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-python-testing-cabal-mock
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-python-testing-cabal-mock
Commits
1ff5b468
Commit
1ff5b468
authored
13 years ago
by
Michael Foord
Browse files
Options
Downloads
Patches
Plain Diff
Index page docs update
parent
ab1df11d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/index.txt
+22
-21
22 additions, 21 deletions
docs/index.txt
with
22 additions
and
21 deletions
docs/index.txt
+
22
−
21
View file @
1ff5b468
...
...
@@ -11,7 +11,7 @@
:Homepage: `Mock Homepage`_
:Download: `Mock on PyPI`_
:Documentation: `PDF Documentation
<http://www.voidspace.org.uk/downloads/mock-0.8.0
a2
.pdf>`_
<http://www.voidspace.org.uk/downloads/mock-0.8.0.pdf>`_
:License: `BSD License`_
:Support: `Mailing list (testing-in-python@lists.idyll.org)
<http://lists.idyll.org/listinfo/testing-in-python>`_
...
...
@@ -50,8 +50,8 @@ Mock is very easy to use and is designed for use with
the 'action -> assertion' pattern instead of `'record -> replay'` used by many
mocking frameworks.
mock is tested on Python versions 2.4-2.7
and
Python 3
. mock is also tested
with the latest versions of
Jython and pypy.
mock is tested on Python versions 2.4-2.7
,
Python 3
plus the latest versions of
Jython and pypy.
.. testsetup::
...
...
@@ -60,7 +60,7 @@ with the latest versions of Jython and pypy.
def method(self, *args):
pass
test_
module = sys.modules['
test_
module'] = ProductionClass
module = sys.modules['module'] = ProductionClass
ProductionClass.ClassName1 = ProductionClass
ProductionClass.ClassName2 = ProductionClass
...
...
@@ -104,7 +104,7 @@ stabilise). If you find bugs or have suggestions for improvements / extensions
then please contact us.
* `mock on PyPI <http://pypi.python.org/pypi/mock>`_
* `mock documentation as PDF <http://www.voidspace.org.uk/downloads/mock-0.
7.2
.pdf>`_
* `mock documentation as PDF <http://www.voidspace.org.uk/downloads/mock-0.
8.0
.pdf>`_
* `Google Code Home & Mercurial Repository <http://code.google.com/p/mock/>`_
.. index:: repository
...
...
@@ -142,14 +142,14 @@ available, and then make assertions about how they have been used:
.. doctest::
>>> from mock import Mock
>>>
real
= ProductionClass()
>>>
real
.method = Mock(return_value=3)
>>>
real
.method(3, 4, 5, key='value')
>>>
thing
= ProductionClass()
>>>
thing
.method = Mock(return_value=3)
>>>
thing
.method(3, 4, 5, key='value')
3
>>>
real
.method.assert_called_with(3, 4, 5, key='value')
>>>
thing
.method.assert_called_with(3, 4, 5, key='value')
:attr:`side_effect` allows you to perform side effects,
return different
values or raise an
exception when a mock is called:
:attr:`side_effect` allows you to perform side effects,
including raising an
exception when a mock is called:
.. doctest::
...
...
@@ -158,6 +158,7 @@ values or raise an exception when a mock is called:
Traceback (most recent call last):
...
KeyError: 'foo'
>>> values = {'a': 1, 'b': 2, 'c': 3}
>>> def side_effect(arg):
... return values[arg]
...
...
@@ -170,9 +171,9 @@ values or raise an exception when a mock is called:
(5, 4, 3)
Mock has many other ways you can configure it and control its behaviour. For
example the ``spec`` argument configures the mock to take its specification
from
another object. Attempting to access attributes or methods on the mock
that
don't exist on the spec will fail with an
`
`AttributeError`
`
.
example the ``spec`` argument configures the mock to take its specification
from
another object. Attempting to access attributes or methods on the mock
that
don't exist on the spec will fail with an `AttributeError`.
The :func:`patch` decorator / context manager makes it easy to mock classes or
objects in a module under test. The object you specify will be replaced with a
...
...
@@ -181,14 +182,14 @@ mock (or other object) during the test and restored when the test ends:
.. doctest::
>>> from mock import patch
>>> @patch('
test_
module.ClassName1')
... @patch('
test_
module.ClassName2')
>>> @patch('module.ClassName1')
... @patch('module.ClassName2')
... def test(MockClass2, MockClass1):
...
test_
module.ClassName1()
...
test_
module.ClassName2()
... module.ClassName1()
... module.ClassName2()
... assert MockClass1 is
test_
module.ClassName1
... assert MockClass2 is
test_
module.ClassName2
... assert MockClass1 is module.ClassName1
... assert MockClass2 is module.ClassName2
... assert MockClass1.called
... assert MockClass2.called
...
...
...
@@ -199,7 +200,7 @@ mock (or other object) during the test and restored when the test ends:
When you nest patch decorators the mocks are passed in to the decorated
function in the same order they applied (the normal *python* order that
decorators are applied). This means from the bottom up, so in the example
above the mock for `
test_
module.ClassName2` is passed in first.
above the mock for `module.ClassName2` is passed in first.
With `patch` it matters that you patch objects in the namespace where they
are looked up. This is normally straightforward, but for a quick guide
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment