-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(ci): add readme snippet test runner - gather up and execute the python snippets in the Readme to make sure they work. * chore: update docs and mathy_pydoc version * chore: update docs
- Loading branch information
1 parent
e322083
commit 97f51a1
Showing
5 changed files
with
80 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import re | ||
from pathlib import Path | ||
from typing import List | ||
|
||
import typer | ||
|
||
|
||
def extract_code_snippets(lines: List[str]) -> List[str]: | ||
inside_codeblock = False | ||
blocks = [] | ||
current_block: List[str] = [] | ||
while len(lines) > 0: | ||
line = lines.pop(0) | ||
if not inside_codeblock: | ||
inside_codeblock = re.match(r"```(p|P)ython$", line.strip()) | ||
else: | ||
end_block = re.match(r"```", line.strip()) | ||
if end_block: | ||
blocks.append("\n".join(current_block)) | ||
current_block = [] | ||
inside_codeblock = False | ||
else: | ||
current_block.append(line) | ||
|
||
return blocks | ||
|
||
|
||
def exec_snippet(text: str): | ||
try: | ||
exec(text) | ||
except BaseException as identifier: | ||
typer.echo(f"TEST Failed! == ERROR: {identifier}") | ||
typer.echo("SNIPPET") | ||
typer.echo(text) | ||
typer.Exit(1) | ||
raise identifier | ||
|
||
|
||
def main(readme_file: Path): | ||
readme_lines = readme_file.read_text().split("\n") | ||
snippets = extract_code_snippets(readme_lines) | ||
for snip in snippets: | ||
exec_snippet(snip) | ||
typer.echo("All snippets in readme executed without error!") | ||
|
||
|
||
if __name__ == "__main__": | ||
typer.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -e | ||
. .env/bin/activate | ||
python tools/test_readme.py README.md |