python/mock-1.0.0/docs/changelog.txt

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 .. currentmodule:: mock
     4 CHANGELOG
     5 =========
     7 2012/10/07 Version 1.0.0
     8 ------------------------
    10 No changes since 1.0.0 beta 1. This version has feature parity with
    11 `unittest.mock
    12 <http://docs.python.org/py3k/library/unittest.mock.html#module-unittest.mock>`_
    13 in Python 3.3.
    15 Full list of changes since 0.8:
    17 * `mocksignature`, along with the `mocksignature` argument to `patch`, removed
    18 * Support for deleting attributes (accessing deleted attributes will raise an
    19   `AttributeError`)
    20 * Added the `mock_open` helper function for mocking the builtin `open`
    21 * `__class__` is assignable, so a mock can pass an `isinstance` check without
    22   requiring a spec
    23 * Addition of `PropertyMock`, for mocking properties
    24 * `MagicMocks` made unorderable by default (in Python 3). The comparison
    25   methods (other than equality and inequality) now return `NotImplemented`
    26 * Propagate traceback info to support subclassing of `_patch` by other
    27   libraries
    28 * `create_autospec` works with attributes present in results of `dir` that
    29   can't be fetched from the object's class. Contributed by Konstantine Rybnikov
    30 * Any exceptions in an iterable `side_effect` will be raised instead of
    31   returned
    32 * In Python 3, `create_autospec` now supports keyword only arguments
    33 * Added `patch.stopall` method to stop all active patches created by `start`
    34 * BUGFIX: calling `MagicMock.reset_mock` wouldn't reset magic method mocks
    35 * BUGFIX: calling `reset_mock` on a `MagicMock` created with autospec could
    36   raise an exception
    37 * BUGFIX: passing multiple spec arguments to patchers (`spec` , `spec_set` and
    38   `autospec`) had unpredictable results, now it is an error
    39 * BUGFIX: using `spec=True` *and* `create=True` as arguments to patchers could
    40   result in using `DEFAULT` as the spec. Now it is an error instead
    41 * BUGFIX: using `spec` or `autospec` arguments to patchers, along with
    42   `spec_set=True` did not work correctly
    43 * BUGFIX: using an object that evaluates to False as a spec could be ignored
    44 * BUGFIX: a list as the `spec` argument to a patcher would always result in a
    45   non-callable mock. Now if `__call__` is in the spec the mock is callable
    48 2012/07/13 Version 1.0.0 beta 1
    49 --------------------------------
    51 * Added `patch.stopall` method to stop all active patches created by `start`
    52 * BUGFIX: calling `MagicMock.reset_mock` wouldn't reset magic method mocks
    53 * BUGFIX: calling `reset_mock` on a `MagicMock` created with autospec could
    54   raise an exception
    57 2012/05/04 Version 1.0.0 alpha 2
    58 --------------------------------
    60 * `PropertyMock` attributes are now standard `MagicMocks`
    61 * `create_autospec` works with attributes present in results of `dir` that
    62   can't be fetched from the object's class. Contributed by Konstantine Rybnikov
    63 * Any exceptions in an iterable `side_effect` will be raised instead of
    64   returned
    65 * In Python 3, `create_autospec` now supports keyword only arguments
    68 2012/03/25 Version 1.0.0 alpha 1
    69 --------------------------------
    71 The standard library version!
    73 * `mocksignature`, along with the `mocksignature` argument to `patch`, removed
    74 * Support for deleting attributes (accessing deleted attributes will raise an
    75   `AttributeError`)
    76 * Added the `mock_open` helper function for mocking the builtin `open`
    77 * `__class__` is assignable, so a mock can pass an `isinstance` check without
    78   requiring a spec
    79 * Addition of `PropertyMock`, for mocking properties
    80 * `MagicMocks` made unorderable by default (in Python 3). The comparison
    81   methods (other than equality and inequality) now return `NotImplemented`
    82 * Propagate traceback info to support subclassing of `_patch` by other
    83   libraries
    84 * BUGFIX: passing multiple spec arguments to patchers (`spec` , `spec_set` and
    85   `autospec`) had unpredictable results, now it is an error
    86 * BUGFIX: using `spec=True` *and* `create=True` as arguments to patchers could
    87   result in using `DEFAULT` as the spec. Now it is an error instead
    88 * BUGFIX: using `spec` or `autospec` arguments to patchers, along with
    89   `spec_set=True` did not work correctly
    90 * BUGFIX: using an object that evaluates to False as a spec could be ignored
    91 * BUGFIX: a list as the `spec` argument to a patcher would always result in a
    92   non-callable mock. Now if `__call__` is in the spec the mock is callable
    95 2012/02/13 Version 0.8.0
    96 ------------------------
    98 The only changes since 0.8rc2 are:
   100 * Improved repr of :data:`sentinel` objects
   101 * :data:`ANY` can be used for comparisons against :data:`call` objects
   102 * The return value of `MagicMock.__iter__` method can be set to
   103   any iterable and isn't required to be an iterator
   105 Full List of changes since 0.7:
   107 mock 0.8.0 is the last version that will support Python 2.4.
   109 * Addition of :attr:`~Mock.mock_calls` list for *all* calls (including magic
   110   methods and chained calls)
   111 * :func:`patch` and :func:`patch.object` now create a :class:`MagicMock`
   112   instead of a :class:`Mock` by default
   113 * The patchers (`patch`, `patch.object` and `patch.dict`), plus `Mock` and
   114   `MagicMock`, take arbitrary keyword arguments for configuration
   115 * New mock method :meth:`~Mock.configure_mock` for setting attributes and
   116   return values / side effects on the mock and its attributes
   117 * New mock assert methods :meth:`~Mock.assert_any_call` and
   118   :meth:`~Mock.assert_has_calls`
   119 * Implemented :ref:`auto-speccing` (recursive, lazy speccing of mocks with
   120   mocked signatures for functions/methods), as the `autospec` argument to
   121   `patch`
   122 * Added the :func:`create_autospec` function for manually creating
   123   'auto-specced' mocks
   124 * :func:`patch.multiple` for doing multiple patches in a single call, using
   125   keyword arguments
   126 * Setting :attr:`~Mock.side_effect` to an iterable will cause calls to the mock
   127   to return the next value from the iterable
   128 * New `new_callable` argument to `patch` and `patch.object` allowing you to
   129   pass in a class or callable object (instead of `MagicMock`) that will be
   130   called to replace the object being patched
   131 * Addition of :class:`NonCallableMock` and :class:`NonCallableMagicMock`, mocks
   132   without a `__call__` method
   133 * Addition of :meth:`~Mock.mock_add_spec` method for adding (or changing) a
   134   spec on an existing mock
   135 * Protocol methods on :class:`MagicMock` are magic mocks, and are created
   136   lazily on first lookup. This means the result of calling a protocol method is
   137   a `MagicMock` instead of a `Mock` as it was previously
   138 * Addition of :meth:`~Mock.attach_mock` method
   139 * Added :data:`ANY` for ignoring arguments in :meth:`~Mock.assert_called_with`
   140   calls
   141 * Addition of :data:`call` helper object
   142 * Improved repr for mocks
   143 * Improved repr for :attr:`Mock.call_args` and entries in
   144   :attr:`Mock.call_args_list`, :attr:`Mock.method_calls` and
   145   :attr:`Mock.mock_calls`
   146 * Improved repr for :data:`sentinel` objects
   147 * `patch` lookup is done at use time not at decoration time
   148 * In Python 2.6 or more recent, `dir` on a mock will report all the dynamically
   149   created attributes (or the full list of attributes if there is a spec) as
   150   well as all the mock methods and attributes.
   151 * Module level :data:`FILTER_DIR` added to control whether `dir(mock)` filters
   152   private attributes. `True` by default.
   153 * `patch.TEST_PREFIX` for controlling how patchers recognise test methods when
   154   used to decorate a class
   155 * Support for using Java exceptions as a :attr:`~Mock.side_effect` on Jython
   156 * `Mock` call lists (`call_args_list`, `method_calls` & `mock_calls`) are now
   157   custom list objects that allow membership tests for "sub lists" and have
   158   a nicer representation if you `str` or `print` them
   159 * Mocks attached as attributes or return values to other mocks have calls
   160   recorded in `method_calls` and `mock_calls` of the parent (unless a name is
   161   already set on the child)
   162 * Improved failure messages for `assert_called_with` and
   163   `assert_called_once_with`
   164 * The return value of the :class:`MagicMock` `__iter__` method can be set to
   165   any iterable and isn't required to be an iterator
   166 * Added the Mock API (`assert_called_with` etc) to functions created by
   167   :func:`mocksignature`
   168 * Tuples as well as lists can be used to specify allowed methods for `spec` &
   169   `spec_set` arguments
   170 * Calling `stop` on an unstarted patcher fails with  a more meaningful error
   171   message
   172 * Renamed the internal classes `Sentinel` and `SentinelObject` to prevent abuse
   173 * BUGFIX: an error creating a patch, with nested patch decorators, won't leave
   174   patches in place
   175 * BUGFIX: `__truediv__` and `__rtruediv__` not available as magic methods on
   176   mocks in Python 3
   177 * BUGFIX: `assert_called_with` / `assert_called_once_with` can be used with
   178   `self` as a keyword argument
   179 * BUGFIX: when patching a class with an explicit spec / spec_set (not a
   180   boolean) it applies "spec inheritance" to the return value of the created
   181   mock (the "instance")
   182 * BUGFIX: remove the `__unittest` marker causing traceback truncation
   183 * Removal of deprecated `patch_object`
   184 * Private attributes `_name`, `_methods`, '_children', `_wraps` and `_parent`
   185   (etc) renamed to reduce likelihood of clash with user attributes.
   186 * Added license file to the distribution
   189 2012/01/10 Version 0.8.0 release candidate 2
   190 --------------------------------------------
   192 * Removed the `configure` keyword argument to `create_autospec` and allow
   193   arbitrary keyword arguments (for the `Mock` constructor) instead
   194 * Fixed `ANY` equality with some types in `assert_called_with` calls
   195 * Switched to a standard Sphinx theme (compatible with
   196   `readthedocs.org <http://mock.readthedocs.org>`_)
   199 2011/12/29 Version 0.8.0 release candidate 1
   200 --------------------------------------------
   202 * `create_autospec` on the return value of a mocked class will use `__call__`
   203   for the signature rather than `__init__`
   204 * Performance improvement instantiating `Mock` and `MagicMock`
   205 * Mocks used as magic methods have the same type as their parent instead of
   206   being hardcoded to `MagicMock`
   208 Special thanks to Julian Berman for his help with diagnosing and improving
   209 performance in this release.
   212 2011/10/09 Version 0.8.0 beta 4
   213 -------------------------------
   215 * `patch` lookup is done at use time not at decoration time
   216 * When attaching a Mock to another Mock as a magic method, calls are recorded
   217   in mock_calls
   218 * Addition of `attach_mock` method
   219 * Renamed the internal classes `Sentinel` and `SentinelObject` to prevent abuse
   220 * BUGFIX: various issues around circular references with mocks (setting a mock
   221   return value to be itself etc)
   224 2011/08/15 Version 0.8.0 beta 3
   225 -------------------------------
   227 * Mocks attached as attributes or return values to other mocks have calls
   228   recorded in `method_calls` and `mock_calls` of the parent (unless a name is
   229   already set on the child)
   230 * Addition of `mock_add_spec` method for adding (or changing) a spec on an
   231   existing mock
   232 * Improved repr for `Mock.call_args` and entries in `Mock.call_args_list`,
   233   `Mock.method_calls` and `Mock.mock_calls`
   234 * Improved repr for mocks
   235 * BUGFIX: minor fixes in the way `mock_calls` is worked out,
   236   especially for "intermediate" mocks in a call chain
   239 2011/08/05 Version 0.8.0 beta 2
   240 -------------------------------
   242 * Setting `side_effect` to an iterable will cause calls to the mock to return
   243   the next value from the iterable
   244 * Added `assert_any_call` method
   245 * Moved `assert_has_calls` from call lists onto mocks
   246 * BUGFIX: `call_args` and all members of `call_args_list` are two tuples of
   247   `(args, kwargs)` again instead of three tuples of `(name, args, kwargs)`
   250 2011/07/25 Version 0.8.0 beta 1
   251 -------------------------------
   253 * `patch.TEST_PREFIX` for controlling how patchers recognise test methods when
   254   used to decorate a class
   255 * `Mock` call lists (`call_args_list`, `method_calls` & `mock_calls`) are now
   256   custom list objects that allow membership tests for "sub lists" and have
   257   an `assert_has_calls` method for unordered call checks
   258 * `callargs` changed to *always* be a three-tuple of `(name, args, kwargs)`
   259 * Addition of `mock_calls` list for *all* calls (including magic methods and
   260   chained calls)
   261 * Extension of `call` object to support chained calls and `callargs` for better
   262   comparisons with or without names. `call` object has a `call_list` method for
   263   chained calls
   264 * Added the public `instance` argument to `create_autospec`
   265 * Support for using Java exceptions as a `side_effect` on Jython
   266 * Improved failure messages for `assert_called_with` and
   267   `assert_called_once_with`
   268 * Tuples as well as lists can be used to specify allowed methods for `spec` &
   269   `spec_set` arguments
   270 * BUGFIX: Fixed bug in `patch.multiple` for argument passing when creating
   271   mocks
   272 * Added license file to the distribution
   275 2011/07/16 Version 0.8.0 alpha 2
   276 --------------------------------
   278 * `patch.multiple` for doing multiple patches in a single call, using keyword
   279   arguments
   280 * New `new_callable` argument to `patch` and `patch.object` allowing you to
   281   pass in a class or callable object (instead of `MagicMock`) that will be
   282   called to replace the object being patched
   283 * Addition of `NonCallableMock` and `NonCallableMagicMock`, mocks without a
   284   `__call__` method
   285 * Mocks created by `patch` have a `MagicMock` as the `return_value` where a
   286   class is being patched
   287 * `create_autospec` can create non-callable mocks for non-callable objects.
   288   `return_value` mocks of classes will be non-callable unless the class has
   289   a `__call__` method
   290 * `autospec` creates a `MagicMock` without a spec for properties and slot
   291   descriptors, because we don't know the type of object they return
   292 * Removed the "inherit" argument from `create_autospec`
   293 * Calling `stop` on an unstarted patcher fails with  a more meaningful error
   294   message
   295 * BUGFIX: an error creating a patch, with nested patch decorators, won't leave
   296   patches in place
   297 * BUGFIX: `__truediv__` and `__rtruediv__` not available as magic methods on
   298   mocks in Python 3
   299 * BUGFIX: `assert_called_with` / `assert_called_once_with` can be used with
   300   `self` as a keyword argument
   301 * BUGFIX: autospec for functions / methods with an argument named self that
   302   isn't the first argument no longer broken
   303 * BUGFIX: when patching a class with an explicit spec / spec_set (not a
   304   boolean) it applies "spec inheritance" to the return value of the created
   305   mock (the "instance")
   306 * BUGFIX: remove the `__unittest` marker causing traceback truncation
   309 2011/06/14 Version 0.8.0 alpha 1
   310 --------------------------------
   312 mock 0.8.0 is the last version that will support Python 2.4.
   314 * The patchers (`patch`, `patch.object` and `patch.dict`), plus `Mock` and
   315   `MagicMock`, take arbitrary keyword arguments for configuration
   316 * New mock method `configure_mock` for setting attributes and return values /
   317   side effects on the mock and its attributes
   318 * In Python 2.6 or more recent, `dir` on a mock will report all the dynamically
   319   created attributes (or the full list of attributes if there is a spec) as
   320   well as all the mock methods and attributes.
   321 * Module level `FILTER_DIR` added to control whether `dir(mock)` filters
   322   private attributes. `True` by default. Note that `vars(Mock())` can still be
   323   used to get all instance attributes and `dir(type(Mock())` will still return
   324   all the other attributes (irrespective of `FILTER_DIR`)
   325 * `patch` and `patch.object` now create a `MagicMock` instead of a `Mock` by
   326   default
   327 * Added `ANY` for ignoring arguments in `assert_called_with` calls
   328 * Addition of `call` helper object
   329 * Protocol methods on `MagicMock` are magic mocks, and are created lazily on
   330   first lookup. This means the result of calling a protocol method is a
   331   MagicMock instead of a Mock as it was previously
   332 * Added the Mock API (`assert_called_with` etc) to functions created by
   333   `mocksignature`
   334 * Private attributes `_name`, `_methods`, '_children', `_wraps` and `_parent`
   335   (etc) renamed to reduce likelihood of clash with user attributes.
   336 * Implemented auto-speccing (recursive, lazy speccing of mocks with mocked
   337   signatures for functions/methods)
   339   Limitations:
   341   - Doesn't mock magic methods or attributes (it creates MagicMocks, so the
   342     magic methods are *there*, they just don't have the signature mocked nor
   343     are attributes followed)
   344   - Doesn't mock function / method attributes
   345   - Uses object traversal on the objects being mocked to determine types - so
   346     properties etc may be triggered
   347   - The return value of mocked classes (the 'instance') has the same call
   348     signature as the class __init__ (as they share the same spec)
   350   You create auto-specced mocks by passing `autospec=True` to `patch`.
   352   Note that attributes that are None are special cased and mocked without a
   353   spec (so any attribute / method can be used). This is because None is
   354   typically used as a default value for attributes that may be of some other
   355   type, and as we don't know what type that may be we allow all access.
   357   Note that the `autospec` option to `patch` obsoletes the `mocksignature`
   358   option.
   360 * Added the `create_autospec` function for manually creating 'auto-specced'
   361   mocks
   362 * Removal of deprecated `patch_object`
   365 2011/05/30 Version 0.7.2
   366 ------------------------
   368 * BUGFIX: instances of list subclasses can now be used as mock specs
   369 * BUGFIX: MagicMock equality / inequality protocol methods changed to use the
   370   default equality / inequality. This is done through a `side_effect` on
   371   the mocks used for `__eq__` / `__ne__`
   374 2011/05/06 Version 0.7.1
   375 ------------------------
   377 Package fixes contributed by Michael Fladischer. No code changes.
   379 * Include template in package
   380 * Use isolated binaries for the tox tests
   381 * Unset executable bit on docs
   382 * Fix DOS line endings in getting-started.txt
   385 2011/03/05 Version 0.7.0
   386 ------------------------
   388 No API changes since 0.7.0 rc1. Many documentation changes including a stylish
   389 new `Sphinx theme <https://github.com/coordt/ADCtheme/>`_.
   391 The full set of changes since 0.6.0 are:
   393 * Python 3 compatibility
   394 * Ability to mock magic methods with `Mock` and addition of `MagicMock`
   395   with pre-created magic methods
   396 * Addition of `mocksignature` and `mocksignature` argument to `patch` and
   397   `patch.object`
   398 * Addition of `patch.dict` for changing dictionaries during a test
   399 * Ability to use `patch`, `patch.object` and `patch.dict` as class decorators
   400 * Renamed ``patch_object`` to `patch.object` (``patch_object`` is
   401   deprecated)
   402 * Addition of soft comparisons: `call_args`, `call_args_list` and `method_calls`
   403   now return tuple-like objects which compare equal even when empty args
   404   or kwargs are skipped
   405 * patchers (`patch`, `patch.object` and `patch.dict`) have start and stop
   406   methods
   407 * Addition of `assert_called_once_with` method
   408 * Mocks can now be named (`name` argument to constructor) and the name is used
   409   in the repr
   410 * repr of a mock with a spec includes the class name of the spec
   411 * `assert_called_with` works with `python -OO`
   412 * New `spec_set` keyword argument to `Mock` and `patch`. If used,
   413   attempting to *set* an attribute on a mock not on the spec will raise an
   414   `AttributeError`
   415 * Mocks created with a spec can now pass `isinstance` tests (`__class__`
   416   returns the type of the spec)
   417 * Added docstrings to all objects
   418 * Improved failure message for `Mock.assert_called_with` when the mock
   419   has not been called at all
   420 * Decorated functions / methods have their docstring and `__module__`
   421   preserved on Python 2.4.
   422 * BUGFIX: `mock.patch` now works correctly with certain types of objects that
   423   proxy attribute access, like the django settings object
   424 * BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting and
   425   diagnosing this)
   426 * BUGFIX: `spec=True` works with old style classes
   427 * BUGFIX: ``help(mock)`` works now (on the module). Can no longer use ``__bases__``
   428   as a valid sentinel name (thanks to Stephen Emslie for reporting and
   429   diagnosing this)
   430 * BUGFIX: ``side_effect`` now works with ``BaseException`` exceptions like
   431   ``KeyboardInterrupt``
   432 * BUGFIX: `reset_mock` caused infinite recursion when a mock is set as its own
   433   return value
   434 * BUGFIX: patching the same object twice now restores the patches correctly
   435 * with statement tests now skipped on Python 2.4
   436 * Tests require unittest2 (or unittest2-py3k) to run
   437 * Tested with `tox <http://pypi.python.org/pypi/tox>`_ on Python 2.4 - 3.2,
   438   jython and pypy (excluding 3.0)
   439 * Added 'build_sphinx' command to setup.py (requires setuptools or distribute)
   440   Thanks to Florian Bauer
   441 * Switched from subversion to mercurial for source code control
   442 * `Konrad Delong <http://konryd.blogspot.com/>`_ added as co-maintainer
   445 2011/02/16 Version 0.7.0 RC 1
   446 -----------------------------
   448 Changes since beta 4:
   450 * Tested with jython, pypy and Python 3.2 and 3.1
   451 * Decorated functions / methods have their docstring and `__module__`
   452   preserved on Python 2.4
   453 * BUGFIX: `mock.patch` now works correctly with certain types of objects that
   454   proxy attribute access, like the django settings object
   455 * BUGFIX: `reset_mock` caused infinite recursion when a mock is set as its own
   456   return value
   459 2010/11/12 Version 0.7.0 beta 4
   460 -------------------------------
   462 * patchers (`patch`, `patch.object` and `patch.dict`) have start and stop
   463   methods
   464 * Addition of `assert_called_once_with` method
   465 * repr of a mock with a spec includes the class name of the spec
   466 * `assert_called_with` works with `python -OO`
   467 * New `spec_set` keyword argument to `Mock` and `patch`. If used,
   468   attempting to *set* an attribute on a mock not on the spec will raise an
   469   `AttributeError`
   470 * Attributes and return value of a `MagicMock` are `MagicMock` objects
   471 * Attempting to set an unsupported magic method now raises an `AttributeError`
   472 * `patch.dict` works as a class decorator
   473 * Switched from subversion to mercurial for source code control
   474 * BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting and
   475   diagnosing this)
   476 * BUGFIX: `spec=True` works with old style classes
   477 * BUGFIX: `mocksignature=True` can now patch instance methods via
   478   `patch.object`
   481 2010/09/18 Version 0.7.0 beta 3
   482 -------------------------------
   484 * Using spec with :class:`MagicMock` only pre-creates magic methods in the spec
   485 * Setting a magic method on a mock with a ``spec`` can only be done if the
   486   spec has that method
   487 * Mocks can now be named (`name` argument to constructor) and the name is used
   488   in the repr
   489 * `mocksignature` can now be used with classes (signature based on `__init__`)
   490   and callable objects (signature based on `__call__`)
   491 * Mocks created with a spec can now pass `isinstance` tests (`__class__`
   492   returns the type of the spec)
   493 * Default numeric value for MagicMock is 1 rather than zero (because the
   494   MagicMock bool defaults to True and 0 is False)
   495 * Improved failure message for :meth:`~Mock.assert_called_with` when the mock
   496   has not been called at all
   497 * Adding the following to the set of supported magic methods:
   499   - ``__getformat__`` and ``__setformat__``
   500   - pickle methods
   501   - ``__trunc__``, ``__ceil__`` and ``__floor__``
   502   - ``__sizeof__``
   504 * Added 'build_sphinx' command to setup.py (requires setuptools or distribute)
   505   Thanks to Florian Bauer
   506 * with statement tests now skipped on Python 2.4
   507 * Tests require unittest2 to run on Python 2.7
   508 * Improved several docstrings and documentation
   511 2010/06/23 Version 0.7.0 beta 2
   512 -------------------------------
   514 * :func:`patch.dict` works as a context manager as well as a decorator
   515 * ``patch.dict`` takes a string to specify dictionary as well as a dictionary
   516   object. If a string is supplied the name specified is imported
   517 * BUGFIX: ``patch.dict`` restores dictionary even when an exception is raised
   520 2010/06/22 Version 0.7.0 beta 1
   521 -------------------------------
   523 * Addition of :func:`mocksignature`
   524 * Ability to mock magic methods
   525 * Ability to use ``patch`` and ``patch.object`` as class decorators
   526 * Renamed ``patch_object`` to :func:`patch.object` (``patch_object`` is
   527   deprecated)
   528 * Addition of :class:`MagicMock` class with all magic methods pre-created for you
   529 * Python 3 compatibility (tested with 3.2 but should work with 3.0 & 3.1 as
   530   well)
   531 * Addition of :func:`patch.dict` for changing dictionaries during a test
   532 * Addition of ``mocksignature`` argument to ``patch`` and ``patch.object``
   533 * ``help(mock)`` works now (on the module). Can no longer use ``__bases__``
   534   as a valid sentinel name (thanks to Stephen Emslie for reporting and
   535   diagnosing this)
   536 * Addition of soft comparisons: `call_args`, `call_args_list` and `method_calls`
   537   now return tuple-like objects which compare equal even when empty args
   538   or kwargs are skipped
   539 * Added docstrings.
   540 * BUGFIX: ``side_effect`` now works with ``BaseException`` exceptions like
   541   ``KeyboardInterrupt``
   542 * BUGFIX: patching the same object twice now restores the patches correctly
   543 * The tests now require `unittest2 <http://pypi.python.org/pypi/unittest2>`_
   544   to run
   545 * `Konrad Delong <http://konryd.blogspot.com/>`_ added as co-maintainer
   548 2009/08/22 Version 0.6.0
   549 ------------------------
   551 * New test layout compatible with test discovery
   552 * Descriptors (static methods / class methods etc) can now be patched and
   553   restored correctly
   554 * Mocks can raise exceptions when called by setting ``side_effect`` to an
   555   exception class or instance
   556 * Mocks that wrap objects will not pass on calls to the underlying object if
   557   an explicit return_value is set
   560 2009/04/17 Version 0.5.0
   561 ------------------------
   563 * Made DEFAULT part of the public api.
   564 * Documentation built with Sphinx.
   565 * ``side_effect`` is now called with the same arguments as the mock is called with and
   566   if returns a non-DEFAULT value that is automatically set as the ``mock.return_value``.
   567 * ``wraps`` keyword argument used for wrapping objects (and passing calls through to the wrapped object).
   568 * ``Mock.reset`` renamed to ``Mock.reset_mock``, as reset is a common API name.
   569 * ``patch`` / ``patch_object`` are now context managers and can be used with ``with``.
   570 * A new 'create' keyword argument to patch and patch_object that allows them to patch
   571   (and unpatch) attributes that don't exist. (Potentially unsafe to use - it can allow
   572   you to have tests that pass when they are testing an API that doesn't exist - use at
   573   your own risk!)
   574 * The methods keyword argument to Mock has been removed and merged with spec. The spec
   575   argument can now be a list of methods or an object to take the spec from.
   576 * Nested patches may now be applied in a different order (created mocks passed
   577   in the opposite order). This is actually a bugfix.
   578 * patch and patch_object now take a spec keyword argument. If spec is
   579   passed in as 'True' then the Mock created will take the object it is replacing
   580   as its spec object. If the object being replaced is a class, then the return
   581   value for the mock will also use the class as a spec.
   582 * A Mock created without a spec will not attempt to mock any magic methods / attributes
   583   (they will raise an ``AttributeError`` instead).
   586 2008/10/12 Version 0.4.0
   587 ------------------------
   589 * Default return value is now a new mock rather than None
   590 * return_value added as a keyword argument to the constructor
   591 * New method 'assert_called_with'
   592 * Added 'side_effect' attribute / keyword argument called when mock is called
   593 * patch decorator split into two decorators:
   595     - ``patch_object`` which takes an object and an attribute name to patch
   596       (plus optionally a value to patch with which defaults to a mock object)
   597     - ``patch`` which takes a string specifying a target to patch; in the form
   598       'package.module.Class.attribute'. (plus optionally a value to
   599       patch with which defaults to a mock object)
   601 * Can now patch objects with ``None``
   602 * Change to patch for nose compatibility with error reporting in wrapped functions
   603 * Reset no longer clears children / return value etc - it just resets
   604   call count and call args. It also calls reset on all children (and
   605   the return value if it is a mock).
   607 Thanks to Konrad Delong, Kevin Dangoor and others for patches and suggestions.
   610 2007/12/03  Version 0.3.1
   611 -------------------------
   613 ``patch`` maintains the name of decorated functions for compatibility with nose
   614 test autodiscovery.
   616 Tests decorated with ``patch`` that use the two argument form (implicit mock
   617 creation) will receive the mock(s) passed in as extra arguments.
   619 Thanks to Kevin Dangoor for these changes.
   622 2007/11/30  Version 0.3.0
   623 -------------------------
   625 Removed ``patch_module``. ``patch`` can now take a string as the first
   626 argument for patching modules.
   628 The third argument to ``patch`` is optional - a mock will be created by
   629 default if it is not passed in.
   632 2007/11/21  Version 0.2.1
   633 -------------------------
   635 Bug fix, allows reuse of functions decorated with ``patch`` and ``patch_module``.
   638 2007/11/20  Version 0.2.0
   639 -------------------------
   641 Added ``spec`` keyword argument for creating ``Mock`` objects from a
   642 specification object.
   644 Added ``patch`` and ``patch_module`` monkey patching decorators.
   646 Added ``sentinel`` for convenient access to unique objects.
   648 Distribution includes unit tests.
   651 2007/11/19  Version 0.1.0
   652 -------------------------
   654 Initial release.
   657 TODO and Limitations
   658 ====================
   660 Contributions, bug reports and comments welcomed!
   662 Feature requests and bug reports are handled on the issue tracker:
   664  * `mock issue tracker <http://code.google.com/p/mock/issues/list>`_
   666 `wraps` is not integrated with magic methods.
   668 `patch` could auto-do the patching in the constructor and unpatch in the
   669 destructor. This would be useful in itself, but violates TOOWTDI and would be
   670 unsafe for IronPython & PyPy (non-deterministic calling of destructors).
   671 Destructors aren't called in CPython where there are cycles, but a weak
   672 reference with a callback can be used to get round this.
   674 `Mock` has several attributes. This makes it unsuitable for mocking objects
   675 that use these attribute names. A way round this would be to provide methods
   676 that *hide* these attributes when needed. In 0.8 many, but not all, of these
   677 attributes are renamed to gain a `_mock` prefix, making it less likely that
   678 they will clash. Any outstanding attributes that haven't been modified with
   679 the prefix should be changed.
   681 If a patch is started using `patch.start` and then not stopped correctly then
   682 the unpatching is not done. Using weak references it would be possible to
   683 detect and fix this when the patch object itself is garbage collected. This
   684 would be tricky to get right though.
   686 When a `Mock` is created by `patch`, arbitrary keywords can be used to set
   687 attributes. If `patch` is created with a `spec`, and is replacing a class, then
   688 a `return_value` mock is created. The keyword arguments are not applied to the
   689 child mock, but could be.
   691 When mocking a class with `patch`, passing in `spec=True` or `autospec=True`,
   692 the mock class has an instance created from the same spec. Should this be the
   693 default behaviour for mocks anyway (mock return values inheriting the spec
   694 from their parent), or should it be controlled by an additional keyword
   695 argument (`inherit`) to the Mock constructor? `create_autospec` does this, so
   696 an additional keyword argument to Mock is probably unnecessary.
   698 The `mocksignature` argument to `patch` with a non `Mock` passed into
   699 `new_callable` will *probably* cause an error. Should it just be invalid?
   701 Note that `NonCallableMock` and `NonCallableMagicMock` still have the unused
   702 (and unusable) attributes: `return_value`, `side_effect`, `call_count`,
   703 `call_args` and `call_args_list`. These could be removed or raise errors on
   704 getting / setting. They also have the `assert_called_with` and
   705 `assert_called_once_with` methods. Removing these would be pointless as
   706 fetching them would create a mock (attribute) that could be called without
   707 error.
   709 Some outstanding technical debt. The way autospeccing mocks function
   710 signatures was copied and modified from `mocksignature`. This could all be
   711 refactored into one set of functions instead of two. The way we tell if
   712 patchers are started and if a patcher is being used for a `patch.multiple`
   713 call are both horrible. There are now a host of helper functions that should
   714 be rationalised. (Probably time to split mock into a package instead of a
   715 module.)
   717 Passing arbitrary keyword arguments to `create_autospec`, or `patch` with
   718 `autospec`, when mocking a *function* works fine. However, the arbitrary
   719 attributes are set on the created mock - but `create_autospec` returns a
   720 real function (which doesn't have those attributes). However, what is the use
   721 case for using autospec to create functions with attributes that don't exist
   722 on the original?
   724 `mocksignature`, plus the `call_args_list` and `method_calls` attributes of
   725 `Mock` could all be deprecated.

mercurial