-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test to ensure all rst ini blocks parse correctly (#901)
- Loading branch information
1 parent
6ec1354
commit 98d6e02
Showing
8 changed files
with
92 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ configuration: | |
|
||
.. code-block:: ini | ||
[testenv:devenv] | ||
commands = | ||
deps = | ||
|
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
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 @@ | ||
import os.path | ||
import re | ||
import textwrap | ||
|
||
import pytest | ||
|
||
from tox.config import parseconfig | ||
|
||
INI_BLOCK_RE = re.compile( | ||
r"(?P<before>" | ||
r"^(?P<indent> *)\.\. (code-block|sourcecode):: ini\n" | ||
r"((?P=indent) +:.*\n)*" | ||
r"\n*" | ||
r")" | ||
r"(?P<code>(^((?P=indent) +.*)?\n)+)", | ||
re.MULTILINE, | ||
) | ||
|
||
|
||
RST_FILES = [] | ||
TOX_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__))) | ||
for root, _, filenames in os.walk(os.path.join(TOX_ROOT, "doc")): | ||
for f in filenames: | ||
if f.endswith(".rst"): | ||
RST_FILES.append(os.path.join(root, f)) | ||
|
||
|
||
def test_some_files_exist(): | ||
assert RST_FILES | ||
|
||
|
||
@pytest.mark.parametrize("filename", RST_FILES) | ||
def test_all_rst_ini_blocks_parse(filename, tmpdir): | ||
with open(filename) as f: | ||
contents = f.read() | ||
for match in INI_BLOCK_RE.finditer(contents): | ||
code = textwrap.dedent(match.group("code")) | ||
f = tmpdir.join("tox.ini") | ||
f.write(code) | ||
try: | ||
parseconfig(("-c", str(f))) | ||
except Exception as e: | ||
raise AssertionError( | ||
"Error parsing ini block\n\n" | ||
"{filename}:{lineno}\n\n" | ||
"{code}\n\n" | ||
"{error}\n\n{error!r}".format( | ||
filename=filename, | ||
lineno=contents[: match.start()].count("\n") + 1, | ||
code="\t" + code.replace("\n", "\n\t").strip(), | ||
error=e, | ||
) | ||
) |