Skip to content

Commit bafc9bd

Browse files
committed
testing: merge code/test_terminal_writer.py into io/test_terminalwriter.py
1 parent 0e36596 commit bafc9bd

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

testing/code/test_terminal_writer.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

testing/io/test_terminalwriter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
22
import os
3+
import re
34
import shutil
45
import sys
56
from typing import Generator
@@ -207,3 +208,26 @@ def test_combining(self) -> None:
207208
assert len(text) == 10
208209
tw.write(text)
209210
assert tw.width_of_current_line == 9
211+
212+
213+
@pytest.mark.parametrize(
214+
"has_markup, expected",
215+
[
216+
pytest.param(
217+
True, "{kw}assert{hl-reset} {number}0{hl-reset}\n", id="with markup"
218+
),
219+
pytest.param(False, "assert 0\n", id="no markup"),
220+
],
221+
)
222+
def test_code_highlight(has_markup, expected, color_mapping):
223+
f = io.StringIO()
224+
tw = terminalwriter.TerminalWriter(f)
225+
tw.hasmarkup = has_markup
226+
tw._write_source(["assert 0"])
227+
assert f.getvalue().splitlines(keepends=True) == color_mapping.format([expected])
228+
229+
with pytest.raises(
230+
ValueError,
231+
match=re.escape("indents size (2) should have same size as lines (1)"),
232+
):
233+
tw._write_source(["assert 0"], [" ", " "])

0 commit comments

Comments
 (0)