-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): fix test readme on windows
- Loading branch information
1 parent
fa163f4
commit 8ca1ea9
Showing
3 changed files
with
54 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,4 +73,4 @@ docs/_build/ | |
.python-version | ||
|
||
# pytest-readme | ||
test_readme.py | ||
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
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,3 +1,53 @@ | ||
from pytest_readme import setup | ||
def parse_from_readme(): | ||
""" | ||
Adapted from https://github.com/boxed/pytest-readme | ||
setup() | ||
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() |