Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 1 | =================================== |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 2 | Mock - Mocking and Testing Library |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 3 | =================================== |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 4 | |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 5 | .. include:: ../README.rst |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 6 | |
| 7 | .. module:: mock |
| 8 | :synopsis: Mock object and testing library. |
| 9 | |
| 10 | .. index:: introduction |
| 11 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 12 | .. toctree:: |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 13 | :hidden: |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 14 | |
| 15 | changelog |
| 16 | |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 17 | Python Version Compatibility |
| 18 | ++++++++++++++++++++++++++++ |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 19 | |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 20 | * Version 1.0.1 is the last version compatible with Python < 2.6. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 21 | |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 22 | * Version 1.3.0 is the last version compatible with Python 3.2. |
Michael Foord | 2df6611 | 2012-10-07 18:33:12 +0100 | [diff] [blame] | 23 | |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 24 | * Version 2.0.0 is the last version compatible with Python 2.6. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 25 | |
Chris Withers | 0459be2 | 2019-05-02 00:17:02 +0100 | [diff] [blame] | 26 | * Version 2.0.0 is the last version offering official Jython support. |
| 27 | |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 28 | .. index:: installing |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 29 | .. _installing: |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 30 | |
| 31 | Installing |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 32 | ++++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 33 | |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 34 | .. index:: repository |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 35 | .. index:: git |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 36 | |
Hugo | b67fe8a | 2017-10-28 16:01:45 +0300 | [diff] [blame] | 37 | You can checkout the latest development version from GitHub |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 38 | repository with the following command: |
| 39 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 40 | ``git clone https://github.com/testing-cabal/mock.git`` |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 41 | |
| 42 | |
| 43 | .. index:: pip |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 44 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 45 | You can install mock with pip: |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 46 | |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 47 | | ``pip install -U mock`` |
| 48 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 49 | .. index:: bug reports |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 50 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 51 | Bug Reports |
| 52 | +++++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 53 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 54 | Issues with the backport process, such as compatibility with a particular |
| 55 | Python, should be reported to the `bug tracker |
| 56 | <https://github.com/testing-cabal/mock/issues>`_. Feature requests and issues |
| 57 | with Mock functionality should be reported to the `Python bug tracker |
| 58 | <https://bugs.python.org>`_. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 59 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 60 | .. index:: python changes |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 61 | |
Chris Withers | 66381c0 | 2019-05-02 13:24:39 +0100 | [diff] [blame^] | 62 | Changelog |
| 63 | +++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 64 | |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 65 | See the :doc:`change log <changelog>`. |
Hugo | b67fe8a | 2017-10-28 16:01:45 +0300 | [diff] [blame] | 66 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 67 | .. index:: maintainer notes |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 68 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 69 | Maintainer Notes |
| 70 | ++++++++++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 71 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 72 | Development |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 73 | ----------- |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 74 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 75 | Checkout from git (see :ref:`installing`) and submit pull requests. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 76 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 77 | Committers can just push as desired: since all semantic development takes |
| 78 | place in cPython, the backport process is as lightweight as we can make it. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 79 | |
Hugo | 59130a4 | 2018-05-08 08:23:53 +0300 | [diff] [blame] | 80 | mock is CI tested using Travis-CI on Python versions 2.7, 3.4, |
Chris Withers | 66381c0 | 2019-05-02 13:24:39 +0100 | [diff] [blame^] | 81 | 3.5, 3.6, pypy, pypy3. |
| 82 | |
| 83 | If you end up fixing anything backport-specific, please add an entry |
| 84 | to the top of ``CHANGELOG.rst`` so it shows up in the next release |
| 85 | notes. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 86 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 87 | Releasing |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 88 | --------- |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 89 | |
Robert Collins | e795a4a | 2015-07-10 14:32:36 +1200 | [diff] [blame] | 90 | NB: please use semver. Bump the major component on API breaks, minor on all |
| 91 | non-bugfix changes, patch on bugfix only changes. |
| 92 | |
Chris Withers | a9c087d | 2019-05-02 08:17:51 +0100 | [diff] [blame] | 93 | 1. Run ``release.py [major|minor|bugfix]`` which will roll out new |
| 94 | NEWS items, bump the version number and create a commit for the release. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 95 | |
Chris Withers | a9c087d | 2019-05-02 08:17:51 +0100 | [diff] [blame] | 96 | 2. Review that commit, feel free to amend it if you want to note anything |
| 97 | manually in ``CHANGELOG.rst``. |
| 98 | |
| 99 | 3. Push to the ``master`` branch on |
| 100 | https://github.com/testing-cabal/mock.git and the Circle CI |
| 101 | automation will take care of pushing releases to PyPI and |
| 102 | creating a tag. |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 103 | |
| 104 | Backporting rules |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 105 | ----------------- |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 106 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 107 | - ``isinstance`` checks in cPython to ``type`` need to check ``ClassTypes``. |
| 108 | Code calling ``obj.isidentifier`` needs to change to ``_isidentifier(obj)``. |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 109 | |
Chris Withers | e684d67 | 2019-04-28 20:48:13 +0100 | [diff] [blame] | 110 | - f-strings need to be rewritten using some other string substitution. |
| 111 | |
Chris Withers | d656380 | 2019-04-28 22:38:05 +0100 | [diff] [blame] | 112 | - ``assertRaisesRegex`` needs to be ``assertRaisesRegexp`` for Python 2. |
| 113 | |
Chris Withers | a2e00f4 | 2019-04-29 08:17:45 +0100 | [diff] [blame] | 114 | - If test code won't compile on a particular version of Python, move it to |
| 115 | a matching ``_py{version}.py`` file. If ``{version}`` isn't 3, adjust |
| 116 | ``conftest.py``. |
| 117 | |
Chris Withers | d52cb78 | 2019-05-02 07:54:29 +0100 | [diff] [blame] | 118 | - If code such as this causes coverage checking to drop below 100%: |
| 119 | |
| 120 | .. code-block:: python |
| 121 | |
| 122 | def will_never_be_called(): |
| 123 | pass |
| 124 | |
| 125 | It should be adjusted to the following pattern, preferably upstream, |
| 126 | so that the ``.coveragerc`` in this repo knows to ignore it: |
| 127 | |
| 128 | .. code-block:: python |
| 129 | |
| 130 | def will_never_be_called(): pass |
| 131 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 132 | Backporting process |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 133 | ------------------- |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 134 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 135 | 1. Clone cpython and mock into the same directory, eg: |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 136 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 137 | .. code-block:: bash |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 138 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 139 | mkdir vcs |
| 140 | cd vcs |
| 141 | git clone https://github.com/python/cpython.git |
| 142 | git clone https://github.com/testing-cabal/mock.git |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 143 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 144 | Make sure they both on master and up to date! |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 145 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 146 | 2. Create a branch in your ``mock`` clone and switch to it. |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 147 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 148 | 3. Make sure you build a suitable virtualenv for Mock development |
| 149 | and activate it. For backporting, this should use Python 3.7+. |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 150 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 151 | 4. Run ``backport.py``: |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 152 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 153 | .. code-block:: bash |
| 154 | |
| 155 | cd vcs/mock |
| 156 | python backport.py |
| 157 | |
| 158 | This will find the next cpython patch that needs to be applied, munge it |
| 159 | and attempt to apply it with ``git am``. |
| 160 | |
| 161 | If it succeeds, run the tests and/or push your branch up to a fork and |
| 162 | do a pull request into the master branch of the main repo to kick off |
| 163 | the continuous integration tests. |
| 164 | |
| 165 | If it fails, you'll have to manually work with what ``git status`` shows |
| 166 | to get the patch committed. |
| 167 | |
Chris Withers | a336518 | 2019-04-27 17:35:49 +0100 | [diff] [blame] | 168 | If it turns out that there's nothing that should be applied from the failed commit, |
Chris Withers | a137eb0 | 2019-04-28 22:38:16 +0100 | [diff] [blame] | 169 | run ``python backport.py --skip-current``, maybe with ``--skip-reason``. |
Chris Withers | a336518 | 2019-04-27 17:35:49 +0100 | [diff] [blame] | 170 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 171 | If you have to make changes, please do a ``git commit --amend`` and add notes |
| 172 | about what needed doing below the ``Signed-off-by`` block. |
| 173 | |
Chris Withers | b0b839f | 2019-04-27 14:48:34 +0100 | [diff] [blame] | 174 | If you have to make changes because tests fail with an applied patch, please |
| 175 | make those changes in a followup commit and take note of the "Backporting rules" |
| 176 | above. |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 177 | |
| 178 | 5. Rinse and repeat until ``backport.py`` reports no more patches need applying. |
Chris Withers | 871b526 | 2019-04-27 15:04:13 +0100 | [diff] [blame] | 179 | |
| 180 | 6. If ``backport.py`` has updated ``lastsync.txt``, now would be a good time |
| 181 | to commit that change. |