-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c902ec
commit 9d6dabc
Showing
5 changed files
with
112 additions
and
129 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,45 @@ | ||
import re | ||
from io import StringIO | ||
|
||
import pytest | ||
from _pytest._io import TerminalWriter | ||
|
||
|
||
# TODO: move this and the other two related attributes from test_terminal.py into conftest as a | ||
# fixture | ||
COLORS = { | ||
"red": "\x1b[31m", | ||
"green": "\x1b[32m", | ||
"yellow": "\x1b[33m", | ||
"bold": "\x1b[1m", | ||
"reset": "\x1b[0m", | ||
"kw": "\x1b[94m", | ||
"hl-reset": "\x1b[39;49;00m", | ||
"function": "\x1b[92m", | ||
"number": "\x1b[94m", | ||
"str": "\x1b[33m", | ||
"print": "\x1b[96m", | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"has_markup, expected", | ||
[ | ||
pytest.param( | ||
True, "{kw}assert{hl-reset} {number}0{hl-reset}\n", id="with markup" | ||
), | ||
pytest.param(False, "assert 0\n", id="no markup"), | ||
], | ||
) | ||
def test_code_highlight(has_markup, expected): | ||
f = StringIO() | ||
tw = TerminalWriter(f) | ||
tw.hasmarkup = has_markup | ||
tw._write_source(["assert 0"]) | ||
assert f.getvalue() == expected.format(**COLORS) | ||
|
||
with pytest.raises( | ||
ValueError, | ||
match=re.escape("indents size (2) should have same size as lines (1)"), | ||
): | ||
tw._write_source(["assert 0"], [" ", " "]) |
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