-
Notifications
You must be signed in to change notification settings - Fork 297
Developer documentation on available testing conveniences #4600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wjbenfold
merged 4 commits into
SciTools:main
from
wjbenfold:wjbenfold-document-create-missing
May 25, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.. include:: ../common_links.inc | ||
|
||
.. _testing_tools: | ||
|
||
Testing tools | ||
************* | ||
|
||
Iris has various internal convenience functions and utilities available to | ||
support writing tests. Using these makes tests quicker and easier to write, and | ||
also consistent with the rest of Iris (which makes it easier to work with the | ||
code). Most of these conveniences are accessed through the | ||
:class:`iris.tests.IrisTest` class, from | ||
which Iris' test classes then inherit. | ||
|
||
.. tip:: | ||
|
||
All functions listed on this page are defined within | ||
:mod:`iris.tests.__init__.py` as methods of | ||
:class:`iris.tests.IrisTest_nometa` (which :class:`iris.tests.IrisTest` | ||
inherits from). They can be accessed within a test using | ||
``self.exampleFunction``. | ||
|
||
Custom assertions | ||
================= | ||
|
||
:class:`iris.tests.IrisTest` supports a variety of custom unittest-style | ||
assertions, such as :meth:`~iris.tests.IrisTest_nometa.assertStringEqual`, | ||
:meth:`~iris.tests.IrisTest_nometa.assertArrayEqual`, | ||
:meth:`~iris.tests.IrisTest_nometa.assertArrayAlmostEqual`. | ||
|
||
Saving results | ||
-------------- | ||
|
||
Some tests compare the generated output to the expected result contained in a | ||
file. Custom assertions for this include | ||
:meth:`~iris.tests.IrisTest_nometa.assertCMLApproxData` | ||
:meth:`~iris.tests.IrisTest_nometa.assertCDL` | ||
:meth:`~iris.tests.IrisTest_nometa.assertCML` and | ||
:meth:`~iris.tests.IrisTest_nometa.assertTextFile`. See docstrings for more | ||
information. | ||
|
||
.. note:: | ||
|
||
Sometimes code changes alter the results expected from a test containing the | ||
above methods. These can be updated by removing the existing result files | ||
and then running the file containing the test with a ``--create-missing`` | ||
command line argument, or setting the ``IRIS_TEST_CREATE_MISSING`` | ||
environment variable to anything non-zero. This will create the files rather | ||
than erroring, allowing you to commit the updated results. | ||
|
||
Context managers | ||
================ | ||
|
||
Capturing exceptions and logging | ||
-------------------------------- | ||
|
||
:class:`iris.tests.IrisTest` includes several context managers that can be used | ||
to make test code tidier and easier to read. These include | ||
:meth:`~iris.tests.IrisTest_nometa.assertWarnsRegexp` and | ||
:meth:`~iris.tests.IrisTest_nometa.assertLogs`. | ||
|
||
Temporary files | ||
--------------- | ||
|
||
It's also possible to generate temporary files in a concise fashion with | ||
:meth:`~iris.tests.IrisTest_nometa.temp_filename`. | ||
|
||
Patching | ||
======== | ||
|
||
:meth:`~iris.tests.IrisTest_nometa.patch` is a wrapper around ``unittest.patch`` | ||
that will be automatically cleaned up at the end of the test. | ||
|
||
Graphic tests | ||
============= | ||
|
||
As a package capable of generating graphical outputs, Iris has utilities for | ||
creating and updating graphical tests - see :ref:`testing.graphics` for more | ||
information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.