-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ChieloNewctle/dev
- Loading branch information
Showing
6 changed files
with
79 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,6 @@ dmypy.json | |
|
||
# IDE | ||
.vscode | ||
|
||
# pytest-readme | ||
tests/test_readme.py |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Chielo | ||
Copyright (c) 2023 Chielo Newctle <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
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,53 @@ | ||
def parse_from_readme(): | ||
""" | ||
Adapted from https://github.com/boxed/pytest-readme | ||
Copyright (c) 2020, Anders Hovmöller | ||
Under the BSD 3-Clause "New" or "Revised" License. | ||
""" | ||
with open( | ||
"tests/test_readme.py", | ||
"w", | ||
encoding="utf8", | ||
) as out, open("README.md", encoding="utf8") as readme: | ||
output, mode = [], None | ||
|
||
for i, line in enumerate(readme.readlines()): | ||
output.append("\n") | ||
|
||
if mode is None and line.strip() == "```python": | ||
mode = "first_line" | ||
output[i] = "def test_line_%s():\n" % i | ||
continue | ||
|
||
if line.strip() == "```": | ||
if mode == "doctest": | ||
output[i] = ' """\n' | ||
mode = None | ||
continue | ||
|
||
if mode == "first_line": | ||
if line.strip() == "": | ||
mode = None | ||
output[i - 1] = "\n" | ||
continue | ||
|
||
if line.strip().startswith(">>>"): | ||
mode = "doctest" | ||
output[i - 2] = ( | ||
output[i - 1][:-1] + " " + output[i - 2] | ||
) # move the def line one line up | ||
output[i - 1] = ' """\n' | ||
else: | ||
mode = "test" | ||
|
||
if mode in ("doctest", "test"): | ||
output[i] = " " + line | ||
else: | ||
output[i] = "# %s" % line | ||
|
||
out.writelines(output) | ||
|
||
|
||
parse_from_readme() |