Skip to content

Commit bb503df

Browse files
author
Will Benfold
committed
Developer documentation on available testing conveniences
1 parent f2113a2 commit bb503df

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

docs/src/developers_guide/contributing_testing_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Testing
77
:maxdepth: 3
88

99
contributing_testing
10+
testing_tools
1011
contributing_graphics_tests
1112
imagehash_index
1213
contributing_running_tests
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. include:: ../common_links.inc
2+
3+
.. _testing_tools:
4+
5+
Testing tools
6+
*************
7+
8+
Iris has various internal convenience functions and utilities available to
9+
support writing tests. Using these makes tests quicker and easier to write, and
10+
also consistent with the rest of Iris (which makes it easier to work with the
11+
code). Most of these conveniences are accessed through the
12+
:class:`iris.tests.IrisTest` class, from which Iris' test classes inherit.
13+
14+
Custom assertions
15+
=================
16+
17+
:class:`iris.tests.IrisTest` supports a variety of custom unittest-style
18+
assertions, such as :meth:`~iris.tests.IrisTest_nometa.assertStringEqual`,
19+
:meth:`~iris.tests.IrisTest_nometa.assertArrayEqual`,
20+
:meth:`~iris.tests.IrisTest_nometa.assertArrayAlmostEqual`.
21+
22+
Saving results
23+
--------------
24+
25+
Some tests compare the generated output to the expected result contained in a
26+
file. Custom assertions for this include
27+
:meth:`~iris.tests.IrisTest_nometa.assertCMLApproxData`
28+
:meth:`~iris.tests.IrisTest_nometa.assertCDL`
29+
:meth:`~iris.tests.IrisTest_nometa.assertCML` and
30+
:meth:`~iris.tests.IrisTest_nometa.assertTextFile`. See docstrings for more
31+
information.
32+
33+
.. note::
34+
35+
Sometimes code changes alter the results expected from a test containing the
36+
above methods. These can be updated by removing the existing result files
37+
and then running the file containing the test with a ``--create-missing``
38+
command line argument, or setting the ``IRIS_TEST_CREATE_MISSING``
39+
environment variable to anything non-zero. This will create the files rather
40+
than erroring, allowing you to commit the updated results.
41+
42+
Context managers
43+
================
44+
45+
Capturing exceptions and logging
46+
--------------------------------
47+
48+
:class:`iris.tests.IrisTest` includes several context managers that can be used
49+
to make test code tidier and easier to read. These include
50+
:meth:`~iris.tests.IrisTest_nometa.assertWarnsRegexp` and
51+
:meth:`~iris.tests.IrisTest_nometa.assertLogs`.
52+
53+
Temporary files
54+
---------------
55+
56+
It's also possible to generate temporary files in a concise fashion with
57+
:meth:`~iris.tests.IrisTest_nometa.temp_filename`.
58+
59+
Patching
60+
========
61+
62+
:meth:`~iris.tests.IrisTest_nometa.patch` is a wrapper around ``unittest.patch``
63+
that will be automatically cleaned up at the end of the test.
64+
65+
Graphic tests
66+
=============
67+
68+
As a package capable of generating graphical outputs, Iris has utilities for
69+
creating and updating graphical tests - see :ref:`testing.graphics` for more
70+
information.

0 commit comments

Comments
 (0)