From f7d5b8a5cbaa5b9251a4c350d3736b9c8e8399a0 Mon Sep 17 00:00:00 2001 From: ezwelty Date: Thu, 6 Feb 2025 13:23:43 +0100 Subject: [PATCH] Run frictionless validate as pytest test Frictionless Repository has been failing to run in GitHub CI for an unknown reason. This avoids the problem and simplifies testing. --- .github/workflows/frictionless.yaml | 20 -------------------- README.md | 19 +++++++------------ tests/conftest.py | 10 ++++++++-- tests/test_data.py | 8 ++++++++ 4 files changed, 23 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/frictionless.yaml diff --git a/.github/workflows/frictionless.yaml b/.github/workflows/frictionless.yaml deleted file mode 100644 index 6529824..0000000 --- a/.github/workflows/frictionless.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: frictionless - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - validate: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Validate data - uses: frictionlessdata/repository@v2 - with: - packages: datapackage.yaml diff --git a/README.md b/README.md index b17164c..18a2aa4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ | :- | :- | [Tutorial notebook](tutorial.ipynb) | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mjacqu/glenglat/blob/main/tutorial.ipynb) Version history | [![GitHub Release](https://img.shields.io/github/v/release/mjacqu/glenglat?label=latest)](https://github.com/mjacqu/glenglat/releases) -Tests | [![Frictionless](https://github.com/mjacqu/glenglat/actions/workflows/frictionless.yaml/badge.svg)](https://github.com/mjacqu/glenglat/actions/workflows/frictionless.yaml) [![Pytest](https://github.com/mjacqu/glenglat/actions/workflows/pytest.yaml/badge.svg)](https://github.com/mjacqu/glenglat/actions/workflows/pytest.yaml) +Tests | [![Pytest](https://github.com/mjacqu/glenglat/actions/workflows/pytest.yaml/badge.svg)](https://github.com/mjacqu/glenglat/actions/workflows/pytest.yaml) _Our paper is currently in public review at [Earth System Science Data](https://essd.copernicus.org). Preview it and consider reviewing it at https://essd.copernicus.org/preprints/essd-2024-249/!_ @@ -146,31 +146,26 @@ cp .env.example .env ### Run tests -Run the basic (`frictionless`) tests. +Run all the tests in the [`tests`](tests) folder. ```sh -frictionless validate datapackage.yaml +pytest ``` -Run the custom (`pytest`) tests in the [`tests`](tests) folder. +Run only fast tests with the `--fast` option and only slow tests with the `--slow` option. ```sh -pytest +pytest --fast +pytest --slow ``` -An optional test checks that `borehole.glims_id` is consistent with borehole coordinates. To run, install `geopandas` and `pyarrow` and set the `GLIMS_PATH` environment variable before calling `pytest`. +An optional (slow) test checks that `borehole.glims_id` is consistent with borehole coordinates. To run, install `geopandas` and `pyarrow` and set the `GLIMS_PATH` environment variable before calling `pytest`. ```sh conda install -c conda-forge geopandas=0.13 pyarrow pytest ``` -Slow tests can be skipped by using the `--fast` option. - -```sh -pytest --fast -``` - ### Maintain the repository The [`glenglat.py`](glenglat.py) module contains functions used to maintain the repository. They can be run from the command line as `python glenglat.py {function}`. diff --git a/tests/conftest.py b/tests/conftest.py index 241df79..0c91cee 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,8 @@ def pytest_addoption(parser: pytest.Parser) -> None: - parser.addoption('--fast', action='store_true', default=False, help='Skip slow tests') + parser.addoption('--fast', action='store_true', default=False, help='Run fast tests') + parser.addoption('--slow', action='store_true', default=False, help='Run slow tests') def pytest_configure(config: pytest.Config) -> None: @@ -13,8 +14,13 @@ def pytest_collection_modifyitems( config: pytest.Config, items: list[pytest.Item] ) -> None: - if config.getoption('--fast'): + if config.getoption('--fast') and not config.getoption('--slow'): skip_slow = pytest.mark.skip(reason='--fast skips slow tests') for item in items: if 'slow' in item.keywords: item.add_marker(skip_slow) + elif config.getoption('--slow') and not config.getoption('--fast'): + skip_fast = pytest.mark.skip(reason='--slow skips fast tests') + for item in items: + if 'slow' not in item.keywords: + item.add_marker(skip_fast) diff --git a/tests/test_data.py b/tests/test_data.py index 7ce2b29..51c2212 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -1,3 +1,4 @@ +import frictionless import numpy as np import pandas as pd import pytest @@ -12,6 +13,13 @@ import glenglat +@pytest.mark.slow +def test_datapackage_is_valid() -> None: + """Frictionless datapackage is valid.""" + report = frictionless.validate('datapackage.yaml') + assert report.valid, report.to_summary() + + # ---- source ---- def test_profile_date_min_less_than_date_max() -> None: