Testing#
Here we provide some high-level guidelines for contributors on how-to test
geovista with pytest, along with a summary of the automated quality assurance
infrastructure.
注釈
The unit tests are not bundled within the geovista package distributed
on conda-forge or PyPI.
Continuous Integration#
Reference:
.github/workflowspyproject.tomlrequirementstests
注釈
We follow Scientific Python Ecosystem Coordination (SPEC)
recommendation for Minimum Supported Dependencies (SPEC 0), and
typically support the latest 2-3 distributions of python.
The following testing workflows are available:
Workflow |
説明 |
|---|---|
The ci-tests.yml Action executes both the Image Tests
and Unit Tests for each SPEC 0 supported distribution of A codecov report is generated only for the latest supported distribution of Also see the testing Pixi Workflow tests-unit task. 注釈 Failed Image Tests are captured via the |
|
The ci-tests-lock.yml Prior to running the tests The purpose of this Action is to preemptively test against the latest resolved Any subsequent test failures will result in a bespoke Issue being raised for contributors to
investigate referencing the Action |
|
The ci-tests-pypi.yml Prior to running the tests The purpose of this Action is to preemptively test against the latest resolved Any subsequent test failures will result in a bespoke Issue being raised for contributors to
investigate referencing the Action 注意 pyvista performs a |
Image Tests#
Reference:
pyproject.tomlsrc/geovista/examplestests/plotting
This section outlines how to create and run our image tests, and also highlights the key infrastructure that underpins it.
Markers#
Reference:
pyproject.toml
The following pytest markers are configured for image unit tests:
Marker |
説明 |
|---|---|
image |
Generic marker to be used on all image unit tests. |
example |
Specific marker only to be used on 例 gallery unit tests. |
参考
For further details see the markers array entry in the [tool.pytest.ini_options]
table of the pyproject.toml manifest.
The following marker expressions can be used for finer-grained control of unit test selection for execution:
Marker Expression |
説明 |
|
Execute all image unit tests. |
|
Execute all unit tests except the image unit tests. |
|
Execute only the gallery unit tests. |
|
Execute all unit tests except the gallery unit tests. |
|
Execute all image unit tests that are not gallery unit tests. |
参考
Refer to the Pixi Workflow tests-unit task.
注意
pytest must be executed from within the geovista root directory.
Fixtures#
Reference:
tests/conftest.py
All image unit tests require to use the following pytest fixtures:
Fixture |
説明 |
|
This fixture generates the unique dotted The fixture also ensures that the baseline image for the unit test is available in the image cache. See Caching for further details. |
|
The pytest-pyvista This fixture requires the unit test to call the
参考 For further details see |
Template#
Reference:
pyproject.tomltests/conftest.py
Image unit tests should adopt the following usage pattern of Markers and Fixtures e.g.,
1import pytest
2
3import geovsita as gv
4
5
6@pytest.mark.image
7def test(plot_nodeid, verify_image_cache):
8 """Single line doc-string."""
9 verify_image_cache.test_name = plot_nodeid
10 p = gv.GeoPlotter()
11 ...
12 p.show()
Note that:
line: 6- The@pytest.mark.imagemarker must always decorate the unit testline: 7- Both theplot_nodeidandverify_image_cachefixures are usedline: 9- Theverify_image_cachefixure is configured with the name of the unit test baseline imageline: 12- Theshow()method of the plotter is called to render the unit test scene and then invoke image comparison via thepytest-pyvistaplugin configured by itsverify_image_cachefixture. Be aware that theshow()method must only be invoked once within the unit test. However the test itself may be decorated with the@pytest.mark.parametrizemarker to execute it multiple times.
Caching#
Reference:
pyproject.tomlsrc/geovista/cache/__init__.pysrc/geovista/config.pysrc/geovista/tests/plotting/__init__.pysrc/geovista/tests/plotting/unit_image_cache
The pytest-pyvista plugin performs the image comparison between a
unit test baseline image (expected) and rendered image (actual) via its
verify_image_cache fixture.
Unit test baseline images are automatically fetched and cached by the pooch
CACHE manager on request by the plot_nodeid fixture.
参考
The geovista download command may be used to cache offline assets.
The CACHE manager fetches assets for a specific
DATA_VERSION release tag from the geovista-data repository
and stores them according to the resource configuration
or the GEOVISTA_CACHEDIR
environment variable.
These cached assets are made available to the verify_image_cache fixture via
the tests/plotting/unit_image_cache symbolic-link, as configured
within the [tool.pytest.ini_options] table of the pyproject.toml manifest.
The tests/plotting/unit_image_cache symbolic-link to the CACHE
manager image cache is automatically verified and managed by the tests.plotting module.
Generation#
Reference:
pyproject.tomlsrc/geovista/cache/__init__.pysrc/geovista/cache/registry.txt
Unit test rendered image (actual) generation is managed through the
pytest-pyvista plugin.
For example, to serizalize all unit test rendered images to file within the
test_images directory e.g.,
$ pytest -m image --generated_image_dir test_images
To serialize both the baseline image (expected) and rendered image (actual) of
all unit test failures to file within the test_images_failed directory e.g.,
$ pytest -m image --failed_image_dir test_images_failed
注意
pytest must be executed from within the geovista root directory.
Typically, we recommend the following:
Use the
--generated_image_diroption to capture the rendered image (actual) of any new or existing unit testsUse the
--failed_image_diroption to capture and investigate any failed image unit tests
参考
Refer to pytest-pyvista for further CLI and configuration options.
Also see the tests-unit pixi task in the
following Pixi Workflow section, as a
convenience.
To register a new baseline image for a unit test:
Generate the baseline image using the
--generated_image_diroption to thepytest-pyvistapluginAdd the new baseline image to the
assets/tests/unitdirectory of the geovista-data repository via apull-requestOnce the
pull-requesthas been reviewed and merged, a newgeovista-datarelease will be tagged automaticallyUpdate the DATA_VERSION within
geovista.cacheto the newgeovista-datarelease versionFinally, update the
registry.txtwith the unit test baseline image name (relative to theassetsdirectory) along with the hexadecimalSHA256SUMof the baseline image file contents
The pooch CACHE manager will automatically download
and cache the new baseline image from the geovista-data repository
when re-running the unit test. Alternatively, download all the new assets for
the DATA_VERSION using the CLI e.g.,
$ geovista download --all --decompress
Pixi Workflow#
Reference:
pyproject.toml
Pixi Environment
The testing pixi tasks are available in the test,
geovista and py3xx variant of those pixi environments
e.g., geovista-py313. See Packaging
for further details.
Testing may be performed using the convenience of
pixi run tasks, which
do not require to be executed from within geovista root directory
e.g.,
$ pixi run <pixi-task>
Pixi Task |
説明 |
|---|---|
download |
Download and cache offline assets. This task calls the geovista download
command. Provide optional argument $ pixi run download rasters
|
tests-clean |
Purge both the documentation and unit test image caches, along with any images generated from previous test sessions e.g., $ pixi run tests-clean
|
tests-unit |
Perform the unit tests. This task calls the Accepts a valid $ pixi run tests-unit "not image"
Note that the tests-clean task is called prior to running this task. 注釈 Failed Image Tests are
automatically captured via the Additionally all generated images are captured via the
|
Tip
Apply the --frozen option to avoid pixi checking and updating the pixi.lock file.
E.g., To execute all non-image based unit tests:
$ pixi run --frozen tests-unit "not image"
Unit Tests#
Reference:
pyproject.tomltests
The unit tests are located within the tests root directory and are
organised into sub-directories, typically one for each geovista top-level
module or sub-package.
The exception to this rule is tests/plotting which contains the
Image Tests.
To execute all unit tests:
$ pytest
参考
Refer to the Pixi Workflow tests-unit task.
注意
pytest must be executed from within the geovista root directory.
Finer-grained control of unit test can be achieved by using our pytest
Markers.