testing: merge code/test_terminal_writer.py into io/test_terminalwriter.py
This commit is contained in:
parent
0e36596268
commit
bafc9bd58b
|
@ -1,28 +0,0 @@
|
||||||
import re
|
|
||||||
from io import StringIO
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
from _pytest._io import TerminalWriter
|
|
||||||
|
|
||||||
|
|
||||||
@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, color_mapping):
|
|
||||||
f = StringIO()
|
|
||||||
tw = TerminalWriter(f)
|
|
||||||
tw.hasmarkup = has_markup
|
|
||||||
tw._write_source(["assert 0"])
|
|
||||||
assert f.getvalue().splitlines(keepends=True) == color_mapping.format([expected])
|
|
||||||
|
|
||||||
with pytest.raises(
|
|
||||||
ValueError,
|
|
||||||
match=re.escape("indents size (2) should have same size as lines (1)"),
|
|
||||||
):
|
|
||||||
tw._write_source(["assert 0"], [" ", " "])
|
|
|
@ -1,5 +1,6 @@
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
@ -207,3 +208,26 @@ class TestTerminalWriterLineWidth:
|
||||||
assert len(text) == 10
|
assert len(text) == 10
|
||||||
tw.write(text)
|
tw.write(text)
|
||||||
assert tw.width_of_current_line == 9
|
assert tw.width_of_current_line == 9
|
||||||
|
|
||||||
|
|
||||||
|
@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, color_mapping):
|
||||||
|
f = io.StringIO()
|
||||||
|
tw = terminalwriter.TerminalWriter(f)
|
||||||
|
tw.hasmarkup = has_markup
|
||||||
|
tw._write_source(["assert 0"])
|
||||||
|
assert f.getvalue().splitlines(keepends=True) == color_mapping.format([expected])
|
||||||
|
|
||||||
|
with pytest.raises(
|
||||||
|
ValueError,
|
||||||
|
match=re.escape("indents size (2) should have same size as lines (1)"),
|
||||||
|
):
|
||||||
|
tw._write_source(["assert 0"], [" ", " "])
|
||||||
|
|
Loading…
Reference in New Issue