test: improve ptk_shell tests (#4448)

* test: improve ptk_shell tests

* Update tests

* fix: failing tests
This commit is contained in:
Noorhteen Raja NJ 2021-09-03 20:26:05 +05:30 committed by GitHub
parent aec4860625
commit d701ea7282
Failed to generate hash of commit
2 changed files with 22 additions and 6 deletions

View file

@ -13,6 +13,7 @@ pygments>=2.2
coverage>=5.3.1
black==21.7b0
pre-commit
pyte>=0.8.0
# types related
mypy==0.910

View file

@ -4,6 +4,7 @@
import sys
import pytest
from xonsh.platform import minimum_required_ptk_version
import pyte
# verify error if ptk not installed or below min
@ -126,10 +127,24 @@ def test_remove_ansi_osc(raw_prompt, prompt, osc_tokens):
assert removed == ref
def test_ptk_prompt(ptk_shell):
@pytest.mark.parametrize(
"line, exp",
[
[repr("hello"), None],
["2 * 3", "6"],
],
)
def test_ptk_prompt(line, exp, ptk_shell, capsys):
inp, out, shell = ptk_shell
text = "hello"
inp.send_text(f"{text}\n") # note: terminate with '\n'
result = shell.singleline()
# todo: check rendered output using https://pyte.readthedocs.io/
assert result == text
inp.send_text(f"{line}\nexit\n") # note: terminate with '\n'
shell.cmdloop()
screen = pyte.Screen(80, 24)
stream = pyte.Stream(screen)
out, _ = capsys.readouterr()
# this will remove render any color codes
stream.feed(out.strip())
out = screen.display[0].strip()
assert out.strip() == (exp or line)