|
| 1 | +Testing ``pytest-mpl`` using the ``tests/subtests`` |
| 2 | +************************************************** |
| 3 | + |
| 4 | +``pytest-mpl`` can output JSON summaries (``--mpl-generate-summary=json``) which contain lots of machine readable information relating to the internal state of the plugin while it was run. |
| 5 | +This test module (``test_subtest.py``) runs the test file ``subtest.py`` multiple times with different combinations of z |
| 6 | +``pytest-mpl`` arguments. |
| 7 | +After each test, it compares the outputted JSON summary to a "baseline" JSON summary for that specific combination of arguments (``summaries/*.json``). |
| 8 | + |
| 9 | +These tests are very sensitive to deviations in the documented behaviour of the ``pytest-mpl`` configuration arguments. |
| 10 | +And the exact behaviour of each comparison mode (such as images, hashes or both) can be asserted. |
| 11 | +If the format of the hash libraries or the baseline summaries are changed, ``test_subtest.py`` and ``helpers.py`` may require modifications. |
| 12 | + |
| 13 | +By using various helper functions defined in ``helpers.py``, the baseline summaries are not specific to the MPL/FreeType versions. |
| 14 | +This is implemented through regex in the log output, and by replacing baseline hashes with hashes in a version specific baseline hash library ``hashes/*.json`` and replacing result hashes with hashes in a version specific "baseline" result hash library ``result_hashes/*.json``. |
| 15 | +The baseline images used for the image comparison tests are included in ``baseline/*.png``. |
| 16 | + |
| 17 | +Generating baseline data |
| 18 | +======================== |
| 19 | + |
| 20 | +The baseline image, hashes and summaries are generated automatically without the need to manually set the data which should fail the tests which are expected to fail. |
| 21 | +All of the test names should follow the existing convention (e.g., ``test_hdiff_imatch``), including one flag from both of the categories below. |
| 22 | +This ensures the script generates the correct baseline data which should achieve the expected test result. |
| 23 | +Full details on how the baselines are modified for each case are given below: |
| 24 | + |
| 25 | +**Hash comparison status flags:** |
| 26 | + |
| 27 | +:``hmatch``: Hash comparison must pass, so same hash in baseline and result hash libraries. |
| 28 | + |
| 29 | +:``hdiff``: Hash comparison must fail, so baseline hash is set to the same as the result hash except the first four characters are changed to ``d1ff``. |
| 30 | + |
| 31 | +:``hmissing``: Baseline hash must be missing, so baseline hash is deleted from the baseline hash library but not the result hash library. |
| 32 | + |
| 33 | +**Image comparison status flags:** |
| 34 | + |
| 35 | +:``imatch``: Image comparison must pass, so correct image in included in the baseline directory. |
| 36 | + |
| 37 | +:``idiff``: Image comparison must fail, so baseline image is edited to include a red cross such that the RMS is greater than the tolerance. |
| 38 | + |
| 39 | +:``idiffshape``: Image comparison must fail due to a different shape, so baseline image is resized to be half the generated width and height before saving. |
| 40 | + |
| 41 | +:``imissing``: Baseline image must be missing, so baseline image is deleted from the baseline directory. |
| 42 | + |
| 43 | +Generating for each version of matplotlib |
| 44 | +----------------------------------------- |
| 45 | + |
| 46 | +Baseline data should be generated for each version of matplotlib separately. |
| 47 | +For each version of matplotlib (defined within the tox environments in ``tox.ini``), follow the three steps in this section. (Only update one version at a time.) |
| 48 | + |
| 49 | +So the baseline data can be recreated easily, do not make any manual adjustments to the generated files. |
| 50 | +Instead, updates the functions which generate the baseline data. |
| 51 | + |
| 52 | +To generate the baseline hashes, result hashes and baseline images run the following command. |
| 53 | +If you are generating for a new version of matplotlib, create empty files such as ``hashes/mpl39_ft261.json`` and ``result_hashes/mpl39_ft261.json`` so it knows you require hashes for this version. |
| 54 | + |
| 55 | +:: |
| 56 | + |
| 57 | + MPL_UPDATE_BASELINE=1 tox -e <envname> |
| 58 | + |
| 59 | +Make sure this command runs without any failures or errors. |
| 60 | +Inspect the generated data to ensure it looks correct, and ``git add``. |
| 61 | +Then generate baseline summaries for the baseline hashes and images by running: |
| 62 | + |
| 63 | +:: |
| 64 | + |
| 65 | + MPL_UPDATE_SUMMARY=1 tox -e <envname> |
| 66 | + |
| 67 | +This will update/create baseline summaries in the ``summaries`` directory. |
| 68 | +Make sure this command runs without any failures or errors. |
| 69 | +It is very important that you check every change made to the baseline summaries as these summaries define how the plugin should be running internally for each test, for each plugin configuration. |
| 70 | +If the summaries are correct, ``git add``. |
| 71 | + |
| 72 | +Now run tox normally to ensure the tests pass: |
| 73 | + |
| 74 | +:: |
| 75 | + |
| 76 | + tox -e <envname> |
| 77 | + |
| 78 | +If the tests pass, ``git commit`` the updated baselines. |
0 commit comments