testing

anemoi.utils.testing.url_for_test_data(path: str) → str

Generate the URL for the test data based on the given path.

Parameters:

path (str) – The relative path to the test data.

Returns:

The full URL to the test data.

Return type:

str

anemoi.utils.testing.packages_installed(*names: str) → bool

Check if all the given packages are installed.

Use this function to check if the required packages are installed before running tests.

>>> @pytest.mark.skipif(not packages_installed("foo", "bar"), reason="Packages 'foo' and 'bar' are not installed")
>>> def test_foo_bar() -> None:
>>>    ...
Parameters:

names (str) – The names of the packages to check.

Returns:

Flag indicating if all the packages are installed.”

Return type:

bool

anemoi.utils.testing.skip_missing_packages(*names: str) → MarkDecorator

Skip a test if any of the specified packages are missing.

Parameters:

names (str) – The names of the packages to check.

Returns:

A decorator that skips the test if any of the specified packages are missing.

Return type:

Callable

anemoi.utils.testing.skip_if_missing_command(cmd: str) → MarkDecorator

Skip a test if the specified command is not available.

Parameters:

cmd (str) – The name of the command to check.

Returns:

A decorator that skips the test if the specified command is not available.

Return type:

Callable

anemoi.utils.testing.cli_testing(package: str, cmd: str, *args: str) → None

Run a CLI command for testing purposes.

Parameters:
  • package (str) – The name of the package containing the CLI commands. Can be ‘anemoi-datasets’ or ‘anemoi.datasets’.

  • cmd (str) – The command to run.

  • *args (str) – Additional arguments to pass to the command.

anemoi.utils.testing.run_tests(globals: dict[str, Callable[[], None]]) → None

Run all test functions that start with test_.

Parameters:

globals (dict[str, Callable[[], None]]) – The global namespace containing the test functions.

Example

Call from a test file to run all tests in that file:

if __name__ == "__main__":
    from anemoi.utils.testing import run_tests
    run_tests(globals())

Useful for debugging or running tests in an interactive environment.