Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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)
Comment thread
leifdenby marked this conversation as 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)
Comment thread
leifdenby marked this conversation as resolved.