Merge pull request #76 from mikesmith/add-input-and-box-tests

Add input and box tests
This commit is contained in:
Will McGugan 2020-05-16 12:51:08 +01:00 committed by GitHub
commit c6bbe819ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

35
tests/test_box.py Normal file
View File

@ -0,0 +1,35 @@
import pytest
from rich.box import ASCII, DOUBLE, ROUNDED, HEAVY
def test_str():
assert str(ASCII) == "+--+\n| ||\n|-+|\n| ||\n|-+|\n|-+|\n| ||\n+--+\n"
def test_repr():
assert repr(ASCII) == "Box(...)"
def test_get_top():
top = HEAVY.get_top(widths=[1, 2])
assert top == "┏━┳━━┓"
def test_get_row():
head_row = DOUBLE.get_row(widths=[3, 2, 1], level="head")
assert head_row == "╠═══╬══╬═╣"
row = ASCII.get_row(widths=[1, 2, 3], level="row")
assert row == "|-+--+---|"
foot_row = ROUNDED.get_row(widths=[2, 1, 3], level="foot")
assert foot_row == "├──┼─┼───┤"
with pytest.raises(ValueError):
ROUNDED.get_row(widths=[1, 2, 3], level="FOO")
def test_get_bottom():
bottom = HEAVY.get_bottom(widths=[1, 2, 3])
assert bottom == "┗━┻━━┻━━━┛"

View File

@ -115,6 +115,14 @@ def test_control():
assert console.file.getvalue() == "FOOBAR\n"
def test_input(monkeypatch, capsys):
monkeypatch.setattr('builtins.input', lambda: "bar")
console = Console()
user_input = console.input(prompt="foo:")
assert capsys.readouterr().out == "foo:"
assert user_input == "bar"
class BrokenRenderable:
def __console__(self, console, options):
pass