Ejemplo n.º 1
0
def test_align_bottom():
    console = Console(file=io.StringIO(), width=10)
    console.print(Align("foo", vertical="bottom"), height=5)
    expected = "          \n          \n          \n          \nfoo       \n"
    result = console.file.getvalue()
    print(repr(result))
    assert result == expected
Ejemplo n.º 2
0
def test_align_center_middle():
    console = Console(file=io.StringIO(), width=10)
    console.print(Align("foo\nbar", "center", vertical="middle"), height=5)
    expected = "          \n   foo    \n   bar    \n          \n          \n"
    result = console.file.getvalue()
    print(repr(result))
    assert result == expected
Ejemplo n.º 3
0
def test_align_width():
    console = Console(file=io.StringIO(), width=40)
    words = "Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic"
    console.print(Align(words, "center", width=30))
    result = console.file.getvalue()
    expected = "     Deep in the human unconscious      \n     is a pervasive need for a          \n     logical universe that makes        \n     sense. But the real universe       \n     is always one step beyond          \n     logic                              \n"
    assert result == expected
Ejemplo n.º 4
0
def test_align_right_style():
    console = Console(
        file=io.StringIO(),
        width=10,
        color_system="truecolor",
        force_terminal=True,
        _environ={},
    )
    console.print(Align("foo", "right", style="on blue"))
    assert console.file.getvalue() == "\x1b[44m       \x1b[0m\x1b[44mfoo\x1b[0m\n"
Ejemplo n.º 5
0
def test_bad_align_legal():

    # Legal
    Align("foo", "left")
    Align("foo", "center")
    Align("foo", "right")

    # illegal
    with pytest.raises(ValueError):
        Align("foo", None)
    with pytest.raises(ValueError):
        Align("foo", "middle")
    with pytest.raises(ValueError):
        Align("foo", "")
    with pytest.raises(ValueError):
        Align("foo", "LEFT")
    with pytest.raises(ValueError):
        Align("foo", vertical="somewhere")
Ejemplo n.º 6
0
def test_align_fit():
    console = Console(file=io.StringIO(), width=10)
    console.print(Align("foobarbaze", "center"))
    assert console.file.getvalue() == "foobarbaze\n"
Ejemplo n.º 7
0
def test_align_right():
    console = Console(file=io.StringIO(), width=10)
    console.print(Align("foo", "right"))
    assert console.file.getvalue() == "       foo\n"
Ejemplo n.º 8
0
def test_repr():
    repr(Align("foo", "left"))
    repr(Align("foo", "center"))
    repr(Align("foo", "right"))
Ejemplo n.º 9
0
def test_align_no_pad():
    console = Console(file=io.StringIO(), width=10)
    console.print(Align("foo", "center", pad=False))
    console.print(Align("foo", "left", pad=False))
    assert console.file.getvalue() == "   foo\nfoo\n"
Ejemplo n.º 10
0
def test_measure():
    console = Console(file=io.StringIO(), width=20)
    _min, _max = Measurement.get(console, console.options, Align("foo bar", "left"))
    assert _min == 3
    assert _max == 7