Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test to run python-code example in readme #38

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- added test to check python codeblocks in README keep working as code changes
[\#38](https://github.com/mllam/weather-model-graphs/pull/38) @leifdenby

- Add coords_crs and graph_crs arguments to allow for using lat-lons coordinates
or other CRSs as input. These are then converted to the specific CRS used when
constructing the graph.
Expand Down
21 changes: 21 additions & 0 deletions tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re
from pathlib import Path

import pytest


def _parse_readme_examples():
lines = open(Path(__file__).parent.parent / "README.md").read().splitlines()

# use regex to find all python code blocks
code_blocks = re.findall(r"```python(.*?)```", "\n".join(lines), re.DOTALL)
leifdenby marked this conversation as resolved.
Show resolved Hide resolved

return code_blocks


@pytest.mark.parametrize("codeblock_example", _parse_readme_examples())
def test_readme_example(codeblock_example: str):
"""
Check that execution of the python code block in the README does not raise an exception.
"""
exec(codeblock_example)
leifdenby marked this conversation as resolved.
Show resolved Hide resolved
Loading