From 19d4933e080fb5980e2d2ac861c1fa7bd090902d Mon Sep 17 00:00:00 2001 From: Leif Denby Date: Thu, 28 Nov 2024 17:23:15 +0100 Subject: [PATCH 1/4] add test to run python-code example in readme Add missing test that ensures that python-code example in README executes without error. --- tests/test_readme.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/test_readme.py diff --git a/tests/test_readme.py b/tests/test_readme.py new file mode 100644 index 0000000..02ddaaf --- /dev/null +++ b/tests/test_readme.py @@ -0,0 +1,18 @@ +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("example", _parse_readme_examples()) +def test_readme_example(example): + exec(example) From 61ba1ec40d06605b91f34d0e4c7e6511a5d87387 Mon Sep 17 00:00:00 2001 From: Leif Denby Date: Fri, 29 Nov 2024 11:30:26 +0100 Subject: [PATCH 2/4] clearer docstring and types --- tests/test_readme.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_readme.py b/tests/test_readme.py index 02ddaaf..c580a11 100644 --- a/tests/test_readme.py +++ b/tests/test_readme.py @@ -13,6 +13,9 @@ def _parse_readme_examples(): return code_blocks -@pytest.mark.parametrize("example", _parse_readme_examples()) -def test_readme_example(example): - exec(example) +@pytest.mark.parametrize("codeblock_examples", _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) From a770cfdda3b59fc10ae233589325bbb47f1c1b0b Mon Sep 17 00:00:00 2001 From: Leif Denby Date: Fri, 29 Nov 2024 11:34:07 +0100 Subject: [PATCH 3/4] fix typo --- tests/test_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_readme.py b/tests/test_readme.py index c580a11..7d06885 100644 --- a/tests/test_readme.py +++ b/tests/test_readme.py @@ -13,7 +13,7 @@ def _parse_readme_examples(): return code_blocks -@pytest.mark.parametrize("codeblock_examples", _parse_readme_examples()) +@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. From f5bcf2746a93644c4e1f5e1da46ebf13f8f74528 Mon Sep 17 00:00:00 2001 From: Leif Denby Date: Fri, 29 Nov 2024 11:46:24 +0100 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ca907..9fc515f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased](https://github.com/mllam/weather-model-graphs/compare/v0.2.0...HEAD) +### 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 + ## [v0.2.0](https://github.com/mllam/weather-model-graphs/releases/tag/v0.2.0)