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 | |
| 26 | .. index:: installing |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 27 | .. _installing: |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 28 | |
| 29 | Installing |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 30 | ++++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 31 | |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 32 | .. index:: repository |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 33 | .. index:: git |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 34 | |
Hugo | b67fe8a | 2017-10-28 16:01:45 +0300 | [diff] [blame] | 35 | You can checkout the latest development version from GitHub |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 36 | repository with the following command: |
| 37 | |
Chris Withers | 8a5e0c3 | 2019-04-27 14:29:03 +0100 | [diff] [blame] | 38 | ``git clone https://github.com/testing-cabal/mock.git`` |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | .. index:: pip |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 42 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 43 | You can install mock with pip: |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 44 | |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 45 | | ``pip install -U mock`` |
| 46 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 47 | .. index:: bug reports |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 48 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 49 | Bug Reports |
| 50 | +++++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 51 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 52 | Issues with the backport process, such as compatibility with a particular |
| 53 | Python, should be reported to the `bug tracker |
| 54 | <https://github.com/testing-cabal/mock/issues>`_. Feature requests and issues |
| 55 | with Mock functionality should be reported to the `Python bug tracker |
| 56 | <https://bugs.python.org>`_. |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 57 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 58 | .. index:: python changes |
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 | Python Changes |
| 61 | ++++++++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 62 | |
Chris Withers | b793c6a | 2019-04-30 09:11:06 +0100 | [diff] [blame] | 63 | See the :doc:`change log <changelog>`. |
Hugo | b67fe8a | 2017-10-28 16:01:45 +0300 | [diff] [blame] | 64 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 65 | .. index:: maintainer notes |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 66 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 67 | Maintainer Notes |
| 68 | ++++++++++++++++ |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 69 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 70 | Development |
Jon Dufresne | 0f7f20f | 2018-09-16 18:04:59 -0700 | [diff] [blame] | 71 | ----------- |
Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 72 | |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 73 | Checkout from git (see :ref:`installing`) and submit pull requests. |
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 | Committers can just push as desired: since all semantic development takes |
| 76 | 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] | 77 | |
Hugo | 59130a4 | 2018-05-08 08:23:53 +0300 | [diff] [blame] | 78 | mock is CI tested using Travis-CI on Python versions 2.7, 3.4, |
| 79 | 3.5, 3.6, nightly Python 3 builds, pypy, pypy3. Jython support is desired, if |
lord63 | 05a0ef0 | 2015-09-23 10:47:31 +0800 | [diff] [blame] | 80 | someone could contribute a patch to .travis.yml to support it that would be |
Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 81 | excellent. |
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. |