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 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 62 | Python Changes |
| 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 | 0459be2 | 2019-05-02 00:17:02 +0100 | [diff] [blame] | 81 | 3.5, 3.6, nightly Python 3 builds, pypy, pypy3. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 82 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 83 | Releasing |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 84 | --------- |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 85 | |
Robert Collins | e795a4a | 2015-07-10 14:32:36 +1200 | [diff] [blame] | 86 | NB: please use semver. Bump the major component on API breaks, minor on all |
| 87 | non-bugfix changes, patch on bugfix only changes. |
| 88 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 89 | 1. tag -s, push --tags origin master |
| 90 | 2. setup.py sdist bdist_wheel upload -s |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 91 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 92 | |
| 93 | Backporting rules |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 94 | ----------------- |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 95 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 96 | - ``isinstance`` checks in cPython to ``type`` need to check ``ClassTypes``. |
| 97 | Code calling ``obj.isidentifier`` needs to change to ``_isidentifier(obj)``. |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 98 | |
Chris Withers | e684d67 | 2019-04-28 20:48:13 +0100 | [diff] [blame] | 99 | - f-strings need to be rewritten using some other string substitution. |
| 100 | |
Chris Withers | d656380 | 2019-04-28 22:38:05 +0100 | [diff] [blame] | 101 | - ``assertRaisesRegex`` needs to be ``assertRaisesRegexp`` for Python 2. |
| 102 | |
Chris Withers | a2e00f4 | 2019-04-29 08:17:45 +0100 | [diff] [blame] | 103 | - If test code won't compile on a particular version of Python, move it to |
| 104 | a matching ``_py{version}.py`` file. If ``{version}`` isn't 3, adjust |
| 105 | ``conftest.py``. |
| 106 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 107 | Backporting process |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 108 | ------------------- |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 109 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 110 | 1. Clone cpython and mock into the same directory, eg: |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 111 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 112 | .. code-block:: bash |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 113 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 114 | mkdir vcs |
| 115 | cd vcs |
| 116 | git clone https://github.com/python/cpython.git |
| 117 | git clone https://github.com/testing-cabal/mock.git |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 118 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 119 | Make sure they both on master and up to date! |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 120 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 121 | 2. Create a branch in your ``mock`` clone and switch to it. |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 122 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 123 | 3. Make sure you build a suitable virtualenv for Mock development |
| 124 | and activate it. For backporting, this should use Python 3.7+. |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 125 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 126 | 4. Run ``backport.py``: |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 127 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 128 | .. code-block:: bash |
| 129 | |
| 130 | cd vcs/mock |
| 131 | python backport.py |
| 132 | |
| 133 | This will find the next cpython patch that needs to be applied, munge it |
| 134 | and attempt to apply it with ``git am``. |
| 135 | |
| 136 | If it succeeds, run the tests and/or push your branch up to a fork and |
| 137 | do a pull request into the master branch of the main repo to kick off |
| 138 | the continuous integration tests. |
| 139 | |
| 140 | If it fails, you'll have to manually work with what ``git status`` shows |
| 141 | to get the patch committed. |
| 142 | |
Chris Withers | a336518 | 2019-04-27 17:35:49 +0100 | [diff] [blame] | 143 | 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] | 144 | run ``python backport.py --skip-current``, maybe with ``--skip-reason``. |
Chris Withers | a336518 | 2019-04-27 17:35:49 +0100 | [diff] [blame] | 145 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 146 | If you have to make changes, please do a ``git commit --amend`` and add notes |
| 147 | about what needed doing below the ``Signed-off-by`` block. |
| 148 | |
Chris Withers | b0b839f | 2019-04-27 14:48:34 +0100 | [diff] [blame] | 149 | If you have to make changes because tests fail with an applied patch, please |
| 150 | make those changes in a followup commit and take note of the "Backporting rules" |
| 151 | above. |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 152 | |
| 153 | 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] | 154 | |
| 155 | 6. If ``backport.py`` has updated ``lastsync.txt``, now would be a good time |
| 156 | to commit that change. |