From 0b81d23dd1a17f42239523c4d5ea3f92b9465257 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Fri, 15 May 2020 13:47:59 -0700 Subject: [PATCH 1/2] Add basic console.input() test --- tests/test_console.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_console.py b/tests/test_console.py index 36707a22..a21fb0e3 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -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 From 369dff642883ded68eca98754ce81369634da94d Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Fri, 15 May 2020 13:48:23 -0700 Subject: [PATCH 2/2] Add box tests --- tests/test_box.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_box.py diff --git a/tests/test_box.py b/tests/test_box.py new file mode 100644 index 00000000..19b59828 --- /dev/null +++ b/tests/test_box.py @@ -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 == "┗━┻━━┻━━━┛"