File: index.txt

package info (click to toggle)
python-mock 0.6.0-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 780 kB
  • ctags: 245
  • sloc: python: 755; makefile: 28
file content (102 lines) | stat: -rw-r--r-- 3,448 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
====================================
 Mock - Mocking and Testing Library
====================================

:Author: `Michael Foord <http://www.voidspace.org.uk/python/weblog/index.shtml>`_
:Version: Mock 0.6.0
:Date: 2009/08/22
:Homepage: `Mock Homepage`_
:Documentation: `PDF Documentation <http://www.voidspace.org.uk/downloads/mock.pdf>`_
:License: `BSD License`_
:Support: `Testing in Python Email List <http://lists.idyll.org/listinfo/testing-in-python>`_
:Contact: fuzzyman@voidspace.org.uk

.. _Mock Homepage: http://www.voidspace.org.uk/python/mock/
.. _BSD License: http://www.voidspace.org.uk/python/license.shtml


.. module:: mock
   :synopsis: Mock object and testing tool library.


Introduction
============

``mock`` provides a core :class:`mock.Mock` class that is intended to reduce the need to
create a host of trivial 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
specific attributes in the normal way.

It also provides a :func:`mock.patch` decorator that handles patching module and class
level attributes within the scope of a test, along with :const:`mock.sentinel` for 
creating unique objects.

Most mocking libraries follow the 'record -> replay' pattern of mocking. I
prefer the 'action -> assertion' pattern, which is more readable and intuitive;
particularly when working with the Python `unittest module
<http://docs.python.org/lib/module-unittest.html>`_. For a discussion of the
merits of the two approaches, see `Mocking, Patching, Stubbing: all that Stuff
<http://www.voidspace.org.uk/python/articles/mocking.shtml>`_.


Downloading
===========

The current version is **0.6.0**, dated 23rd August 2009. Mock is still 
experimental; the API may change. If you find bugs or 
have suggestions for improvements / extensions then please email me.

* `mock.py (module only) <http://www.voidspace.org.uk/downloads/mock.py>`_
* `mock-0.6.0.zip (module, tests and documentation) <http://www.voidspace.org.uk/downloads/mock-0.6.0.zip>`_
* `mock documentation as PDF <http://www.voidspace.org.uk/downloads/mock.pdf>`_
* `Google Code Home & Subversion Repository <http://code.google.com/p/mock/>`_

You can checkout the latest development version from the Google Code Subversion 
repository with the following command:

    ``svn checkout http://mock.googlecode.com/svn/trunk/ mock-read-only``

Mock is registered with PyPi (`Mock on PyPi <http://pypi.python.org/pypi/mock/>`_). 
If you have pip or Distribute you can install mock with:

    | ``easy_install mock``
    | ``pip mock``

    
API Documentation
=================

.. toctree::
   :maxdepth: 2
   
   mock
   patch
   sentinel


User Guide
==========

.. toctree::
   :maxdepth: 2

   getting-started
   examples
   todo
   changelog


References
==========

Articles and blog entries on testing with Mock:


* `Python mock testing techniques and tools <http://agiletesting.blogspot.com/2009/07/python-mock-testing-techniques-and.html>`_
* `How To Test Django Template Tags <http://techblog.ironfroggy.com/2008/10/how-to-test.html>`_
* `A presentation on Unit Testing with Mock <http://pypap.blogspot.com/2008/10/newbie-nugget-unit-testing-with-mock.html>`_
* `Mocking with Django and Google AppEngine <http://michael-a-nelson.blogspot.com/2008/09/mocking-with-django-and-google-app.html>`_