diff --git a/CHANGELOG.md b/CHANGELOG.md index a2fef38..81fb185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/tests/test_readme.py b/tests/test_readme.py new file mode 100644 index 0000000..7d06885 --- /dev/null +++ b/tests/test_readme.py @@ -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) + + 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)