Ejemplo n.º 1
0
def test_tree_measure():
    tree = Tree("foo")
    tree.add("bar")
    tree.add("musroom risotto")
    console = Console()
    measurement = Measurement.get(console, console.options, tree)
    assert measurement == Measurement(11, 19)
Ejemplo n.º 2
0
def test_clamp():
    measurement = Measurement(20, 100)
    assert measurement.clamp(10, 50) == Measurement(20, 50)
    assert measurement.clamp(30, 50) == Measurement(30, 50)
    assert measurement.clamp(None, 50) == Measurement(20, 50)
    assert measurement.clamp(30, None) == Measurement(30, 100)
    assert measurement.clamp(None, None) == Measurement(20, 100)
Ejemplo n.º 3
0
def test_console_width():
    console = Console()
    test = Text("Hello World!\nfoobarbaz")
    assert test.__rich_measure__(console, 80) == Measurement(9, 12)
    assert Text(" " * 4).__rich_measure__(console, 80) == Measurement(4, 4)
    assert Text(" \n  \n   ").__rich_measure__(console,
                                               80) == Measurement(3, 3)
Ejemplo n.º 4
0
def test_styled():
    styled_foo = Styled("foo", "on red")
    console = Console(file=io.StringIO(), force_terminal=True, _environ={})
    assert Measurement.get(console, console.options,
                           styled_foo) == Measurement(3, 3)
    console.print(styled_foo)
    result = console.file.getvalue()
    expected = "\x1b[41mfoo\x1b[0m\n"
    assert result == expected
Ejemplo n.º 5
0
def test_rich_measure():

    console = Console()
    assert Table("test_header", width=-1).__rich_measure__(
        console, console.options
    ) == Measurement(0, 0)
    # Check __rich_measure__() for a positive width passed as an argument
    assert Table("test_header", width=None).__rich_measure__(
        console, console.options.update_width(10)
    ) == Measurement(10, 10)
Ejemplo n.º 6
0
def test_vertical_center():
    console = Console(color_system=None, height=6)
    console.begin_capture()
    vertical_center = VerticalCenter("foo")
    repr(vertical_center)
    console.print(vertical_center)
    result = console.end_capture()
    print(repr(result))
    expected = "   \n   \nfoo\n   \n   \n   \n"
    assert result == expected
    assert Measurement.get(console, console.options, vertical_center) == Measurement(
        3, 3
    )
Ejemplo n.º 7
0
def test_min_width():
    table = Table("foo", min_width=30)
    table.add_row("bar")
    console = Console()
    assert table.__rich_measure__(
        console, console.options.update_width(100)
    ) == Measurement(30, 30)
    console = Console(color_system=None)
    console.begin_capture()
    console.print(table)
    output = console.end_capture()
    print(output)
    assert all(len(line) == 30 for line in output.splitlines())
Ejemplo n.º 8
0
def render_tables():
    console = Console(
        width=60,
        force_terminal=True,
        file=io.StringIO(),
        legacy_windows=False,
        color_system=None,
        _environ={},
    )

    table = Table(title="test table", caption="table caption", expand=False)
    table.add_column("foo", footer=Text("total"), no_wrap=True, overflow="ellipsis")
    table.add_column("bar", justify="center")
    table.add_column("baz", justify="right")

    table.add_row("Averlongwordgoeshere", "banana pancakes", None)

    assert Measurement.get(console, console.options, table) == Measurement(41, 48)
    table.expand = True
    assert Measurement.get(console, console.options, table) == Measurement(41, 48)

    for width in range(10, 60, 5):
        console.print(table, width=width)

    table.expand = False
    console.print(table, justify="left")
    console.print(table, justify="center")
    console.print(table, justify="right")

    assert table.row_count == 1

    table.row_styles = ["red", "yellow"]
    table.add_row("Coffee")
    table.add_row("Coffee", "Chocolate", None, "cinnamon")

    assert table.row_count == 3

    console.print(table)

    table.show_lines = True
    console.print(table)

    table.show_footer = True
    console.print(table)

    table.show_edge = False

    console.print(table)

    table.padding = 1
    console.print(table)

    table.width = 20
    assert Measurement.get(console, console.options, table) == Measurement(20, 20)
    table.expand = False
    assert Measurement.get(console, console.options, table) == Measurement(20, 20)
    table.expand = True
    console.print(table)

    table.columns[0].no_wrap = True
    table.columns[1].no_wrap = True
    table.columns[2].no_wrap = True

    console.print(table)

    table.padding = 0
    table.width = 60
    table.leading = 1
    console.print(table)

    return console.file.getvalue()
Ejemplo n.º 9
0
def test_rich_measure():
    console = Console(width=80, color_system=None, force_terminal=True)
    spinner = Spinner("dots", "Foo")
    min_width, max_width = Measurement.get(console, console.options, spinner)
    assert min_width == 3
    assert max_width == 5
Ejemplo n.º 10
0
def test_span():
    measurement = Measurement(10, 100)
    assert measurement.span == 90
Ejemplo n.º 11
0
def test_measure_renderables():
    console = Console()
    assert measure_renderables(console, console.options,
                               "") == Measurement(0, 0)
    assert measure_renderables(console, console.options.update_width(0),
                               "hello") == Measurement(0, 0)
Ejemplo n.º 12
0
def test_no_renderable():
    console = Console()
    text = Text()

    with pytest.raises(NotRenderableError):
        Measurement.get(console, console.options, None)
Ejemplo n.º 13
0
 def __rich_measure__(self, console: "Console",
                      options: ConsoleOptions) -> Measurement:
     return Measurement(1, options.max_width)
Ejemplo n.º 14
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