/usr/lib/python2.7/dist-packages/MiniMock-1.2.7.egg-info/PKG-INFO is in python-minimock 1.2.7-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | Metadata-Version: 1.1
Name: MiniMock
Version: 1.2.7
Summary: The simplest possible mock library
Home-page: http://pypi.python.org/pypi/MiniMock
Author: Ian Bicking
Author-email: ianb@colorstudy.com
License: MIT
Description: MiniMock
========
.. contents::
:depth: 1
--------------------
License & Repository
--------------------
MiniMock is by `Ian Bicking <http://blog.ianbicking.org>`_ with
substantial contributions by Mike Beachy, and is maintained by Josh
Bronson. It is licensed under an `MIT-style license
<http://bitbucket.org/jab/minimock/src/tip/docs/license.txt>`_.
It has a `bitbucket repository <http://bitbucket.org/jab/minimock/>`_
which you can clone with ``hg clone https://jab@bitbucket.org/jab/minimock/``,
download an archive of the tip from
`http://bitbucket.org/jab/minimock/get/tip.gz
<http://bitbucket.org/jab/minimock/get/tip.gz#egg=MiniMock-dev>`_,
or install from with ``easy_install MiniMock==dev``.
There is also a `Google Group <http://groups.google.com/group/minimock-dev>`_
for the development mailing list which can be emailed at
`minimock-dev@googlegroups.com <mailto:minimock-dev@googlegroups.com>`_.
------------
Introduction
------------
minimock is a simple library for doing Mock objects with doctest.
When using doctest, mock objects can be very simple.
Here's an example of something we might test, a simple email sender::
>>> import smtplib
>>> def send_email(from_addr, to_addr, subject, body):
... conn = smtplib.SMTP('localhost')
... msg = 'To: %s\nFrom: %s\nSubject: %s\n\n%s' % (
... to_addr, from_addr, subject, body)
... conn.sendmail(from_addr, [to_addr], msg)
... conn.quit()
Now we want to make a mock ``smtplib.SMTP`` object. We'll have to
inject our mock into the ``smtplib`` module::
>>> smtplib.SMTP = Mock('smtplib.SMTP')
>>> smtplib.SMTP.mock_returns = Mock('smtp_connection')
Now we do the test::
>>> send_email('ianb@colorstudy.com', 'joe@example.com',
... 'Hi there!', 'How is it going?')
Called smtplib.SMTP('localhost')
Called smtp_connection.sendmail(
'ianb@colorstudy.com',
['joe@example.com'],
'To: joe@example.com\nFrom: ianb@colorstudy.com\nSubject: Hi there!\n\nHow is it going?')
Called smtp_connection.quit()
Voila! We've tested implicitly that no unexpected methods were called
on the object. We've also tested the arguments that the mock object
got. We've provided fake return calls (for the ``smtplib.SMTP()``
constructor). These are all the core parts of a mock library. The
implementation is simple because most of the work is done by doctest.
-----------------
Controlling Mocks
-----------------
Mock objects have several attributes, all of which you can set when
instantiating the object. To avoid name collision, all the attributes
start with ``mock_``, while the constructor arguments don't.
``name``:
The name of the object, used when printing out messages. In the
example above it was ``'smtplib.SMTP'``.
``returns``:
When this object is called, it will return this value. By default
it is None.
``returns_iter``:
Alternately, you can give an iterable of return results, like
``returns_iter=[1, 2, 3]``; on each subsequent call it will return
the next value.
``returns_func``:
If given, this will be called to get the return value. In
essence, this function will be the *real* implementation of the
method.
``raises``:
An exception (instance or class) that will be raised when this
object is called.
``tracker``:
An object which is notified every time the mock object is called or
an attribute is set on it (assuming ``show_attrs`` is ``True``);
defaults to a ``Printer`` to stdout. ``TraceTracker`` can instead be
useful for non-doctest tests. Pass ``None`` to disable this behavior.
``show_attrs``:
If this is true, every time a new attribute is set on the mock
object the tracker will be notified. Otherwise attribute sets are
silent, and only calls trigger notification.
So to create an object that always raises ValueError, do::
>>> dummy_module = Mock('mylibrary')
>>> dummy_module.invalid_func.mock_raises = ValueError
--------------
Creating Mocks
--------------
Every attribute of a mock object will itself be another mock object,
unless you specifically set it to something else. For instance, you
can do::
>>> from minimock import Mock
>>> dummy_module = Mock('mylibrary')
>>> dummy_module.CONSTANT = 1
Then the ``CONSTANT`` value will persist. But you can also traverse
to whatever object you want, and you will get another mock object.
Another technique for creating a mock object is the ``mock(...)``
function. This works like::
>>> from minimock import mock
>>> import os.path
>>> mock('os.path.isfile', returns=True)
This looks up the ``os.path.isfile`` object, and changes it to a mock
object. Any keyword arguments you give (like ``returns=True`` in this
example) will be used to create the mock object; you can also give a
``mock_obj`` keyword argument to pass in a mock object you've already
created.
This function looks in the calling function to figure out what to
replace (``os.path.isfile`` in the example). You must import the
proper modules first. Alternately you can pass in a dictionary like
``[locals(), globals()]`` for it to use for lookup.
To restore all the objects mocked with ``mock()``, use
``minimock.restore()`` (with no arguments; all the mocks are kept
track of).
----
News
----
1.2.7
-----
* Fix for mocking proxy objects. Worked in 1.2.5 but broken in 1.2.6 by the
change to allow mocking static methods. Reported by Randy Syring.
* bugfix: ``mock_show_attrs`` was immutable after initialization because the
``mock_`` prefix was accidentally left off in ``Mock.__setattr__`` (Yusuke
Muraoka)
1.2.6
-----
* Allow changing the tracker on a mock object once it's been set (James Brady)
* Support doctest use case (Israel Tsadok)
* Fix issue 1: setting mock_returns_iter on existing Mock object (kenmacd)
* Fix issue 2: static methods become unbound methods after mock + restore
1.2.5
-----
* Deprecate ``MockTracker``. ``TraceTracker`` should be used instead.
1.2.4
-----
* Fix show_attrs=True bug (Kendrick Shaw)
1.2.3
-----
* Explicitly passing ``tracker=None`` to the ``Mock`` constructor now
suppresses tracking. If ``tracker`` is not passed it will still use
``Printer(sys.stdout)`` as before.
1.2.2
-----
* Added ``MinimockOutputChecker`` which normalizes whitespace in function call
traces; ``TraceTracker`` now uses this instead of ``doctest.OutputChecker``
(Ben Finney)
1.2.1
-----
* Allow mocking of built-in functions.
1.2
---
* Added ``TraceTracker``, a better ``Tracker`` to use with unittests (James Brady)
1.1
---
* Added ``MockTracker`` for use with unittests rather than doctests (James Brady)
1.0
---
* Fixed setting special attributes like ``mock_returns`` on
already-created Mock objects (Toby White)
* Separated out printing to a class that accepts call information
and provided an implementation that prints calls to a file.
0.9
---
* Added ``show_attrs``
0.8
---
First official release.
Keywords: mock testing unittest
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Software Development :: Testing
|