forked from dr-leo/pandaSDMX
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from khaeru/enh/testing
Improve test suite, utilities
- Loading branch information
Showing
20 changed files
with
876 additions
and
549 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -38,28 +38,69 @@ Code style | |
|
||
.. _testing: | ||
|
||
Test specimens | ||
============== | ||
Testing | ||
======= | ||
|
||
Specimens and data | ||
------------------ | ||
|
||
.. versionadded:: 2.0 | ||
|
||
A variety of *specimens*—example files from real web services, or published with the standards—are used to test that :mod:`sdmx` correctly reads and writes the different SDMX message formats. | ||
Since v2.0, specimens are stored in the separate `sdmx-test-data <https://github.com/khaeru/sdmx-test-data>`_ repository. | ||
|
||
Specimens are stored in the separate `sdmx-test-data <https://github.com/khaeru/sdmx-test-data>`_ repository. | ||
|
||
Running the test suite requires these files. | ||
To retrieve them, use one of the following methods: | ||
The simplest way to do this is to give the :program:`--sdmx-fetch-data` option when invoking :program:`pytest`:: | ||
|
||
$ pytest --sdmx-fetch-data | ||
|
||
This invokes :meth:`SpecimenCollection.fetch`, which uses :program:`git` (via `GitPython <https://gitpython.readthedocs.io>`_) to retrieve and unpack the files to a directory like :file:`$HOME/.cache/sdmx/test-data/`. | ||
:ref:`See below <sdmx-test-data>` for more advanced options. | ||
|
||
Contents and layout | ||
~~~~~~~~~~~~~~~~~~~ | ||
|
||
**Specimen files** are: | ||
|
||
- Arranged in directories with names matching particular sources in :file:`sources.json`. | ||
- Named with: | ||
|
||
- Certain keywords: | ||
|
||
- ``-structure``: a structure message, often associated with a file with a similar name containing a data message. | ||
- ``ts``: time-series data, i.e. with a TimeDimensions at the level of individual Observations. | ||
- ``xs``: cross-sectional data arranged in other ways. | ||
- ``flat``: flat DataSets with all Dimensions at the Observation level. | ||
- ``ss``: structure-specific data messages. | ||
|
||
- In some cases, the query string or data flow/structure ID as the file name. | ||
- Hyphens ``-`` instead of underscores ``_``. | ||
|
||
.. _recorded-responses: | ||
|
||
The :file:`recorded/` directory contains **recorded HTTP responses** from certain SDMX-REST web services. | ||
These files are stored using the :mod:`requests_cache` :doc:`file system backend <requests-cache:user_guide/backends/filesystem>`; see those docs for the name and format of the files. | ||
|
||
.. _sdmx-test-data: | ||
|
||
Custom test data directory | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
It is also possible to place the test data in a specific directory; for instance, in order to commit new files to the specimen collection. | ||
Use one of the following methods: | ||
|
||
1. Obtain the files by one of two methods: | ||
|
||
a. Clone ``khaeru/sdmx-test-data``:: | ||
a. Clone ``sdmx-test-data``:: | ||
|
||
$ git clone [email protected]:khaeru/sdmx-test-data.git | ||
|
||
b. Download https://github.com/khaeru/sdmx-test-data/archive/main.zip | ||
|
||
2. Indicate where pytest can find the files, by one of two methods: | ||
2. Indicate where :program:`pytest` can find the files, by one of two methods: | ||
|
||
a. Set the `SDMX_TEST_DATA` environment variable:: | ||
a. Set the ``SDMX_TEST_DATA`` environment variable:: | ||
|
||
# Set the variable only for one command | ||
$ SDMX_TEST_DATA=/path/to/files pytest | ||
|
@@ -68,26 +109,35 @@ To retrieve them, use one of the following methods: | |
$ export SDMX_TEST_DATA | ||
$ pytest | ||
|
||
b. Give the option ``--sdmx-test-data=<PATH>`` when invoking pytest:: | ||
b. Give the option ``--sdmx-test-data=<PATH>`` when invoking :program:`pytest`:: | ||
|
||
$ pytest --sdmx-test-data=/path/to/files | ||
|
||
The files are: | ||
.. _test-network: | ||
|
||
- Arranged in directories with names matching particular sources in :file:`sources.json`. | ||
- Named with: | ||
Network vs. offline tests | ||
------------------------- | ||
|
||
- Certain keywords: | ||
Tests related to particular SDMX-REST web services can be categorized as: | ||
|
||
- ``-structure``: a structure message, often associated with a file with a similar name containing a data message. | ||
- ``ts``: time-series data, i.e. with a TimeDimensions at the level of individual Observations. | ||
- ``xs``: cross-sectional data arranged in other ways. | ||
- ``flat``: flat DataSets with all Dimensions at the Observation level. | ||
- ``ss``: structure-specific data messages. | ||
- Ensuring :mod:`sdmx` can interact with the service *as-is*. | ||
|
||
- In some cases, the query string or data flow/structure ID as the file name. | ||
- Hyphens ``-`` instead of underscores ``_``. | ||
These include the :ref:`full matrix of source-endpoint tests <source-policy>`, which run on a nightly schedule because they are slow. | ||
They also include other tests (for instance, of code snippets appearing in this documentation) marked with the custom pytest mark :py:`@pytest.mark.network` that make actual network requests. | ||
These tests may appear ‘flaky’: they are vulnerable to network interruptions, or temporary downtime/incapacity of the targeted service(s). | ||
|
||
- Ensuring :mod:`sdmx` can handle certain SDMX messages or HTTP responses returned by services. | ||
This should remain true *whether or not* those services actually return the same content as they did at the moment the tests were written. | ||
|
||
These are handled using :ref:`recorded responses <recorded-responses>`, as described above. | ||
This makes the test outcomes deterministic, even if the services are periodically unavailable. | ||
|
||
These tests use :func:`.session_with_stored_responses`, which is an in-memory :class:`~requests_cache.CachedSession` prepared using: | ||
|
||
- The recorded/stored responses from ``sdmx-test-data``. | ||
- Other responses generated by :func:`.add_responses` / :func:`.save_response`. | ||
- :func:`.offline` / :class:`.OfflineAdapter`. | ||
This ensures that *only* the cached URLs/requests can be queried; all other queries raise :class:`.RuntimeError`. | ||
|
||
Releasing | ||
========= | ||
|
@@ -154,11 +204,26 @@ Internal code reference | |
:undoc-members: | ||
:show-inheritance: | ||
|
||
.. automodule:: sdmx.testing.data | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
.. automodule:: sdmx.testing.report | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
``util``: Utilities | ||
------------------- | ||
|
||
.. automodule:: sdmx.util | ||
:noindex: | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
.. automodule:: sdmx.util.requests | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
|
This file contains 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 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 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 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
Oops, something went wrong.