| 1 |
import io |
| 2 |
from textwrap import dedent |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
from rich import box |
| 7 |
from rich.console import Console |
| 8 |
from rich.rule import Rule |
| 9 |
from rich.table import Table |
| 10 |
|
| 11 |
|
| 12 |
@pytest.mark.parametrize("expand_kwarg", ({}, {"expand": False})) |
| 13 |
def test_rule_in_unexpanded_table(expand_kwarg): |
| 14 |
console = Console(width=32, file=io.StringIO(), legacy_windows=False, _environ={}) |
| 15 |
table = Table(box=box.ASCII, show_header=False, **expand_kwarg) |
| 16 |
table.add_column() |
| 17 |
table.add_column() |
| 18 |
table.add_row("COL1", "COL2") |
| 19 |
table.add_row("COL1", Rule()) |
| 20 |
table.add_row("COL1", "COL2") |
| 21 |
console.print(table) |
| 22 |
expected = dedent( |
| 23 |
"""\ |
| 24 |
+-------------+ |
| 25 |
| COL1 | COL2 | |
| 26 |
| COL1 | ──── | |
| 27 |
| COL1 | COL2 | |
| 28 |
+-------------+ |
| 29 |
""" |
| 30 |
) |
| 31 |
result = console.file.getvalue() |
| 32 |
assert result == expected |
| 33 |
|
| 34 |
|
| 35 |
def test_rule_in_expanded_table(): |
| 36 |
console = Console(width=32, file=io.StringIO(), legacy_windows=False, _environ={}) |
| 37 |
table = Table(box=box.ASCII, expand=True, show_header=False) |
| 38 |
table.add_column() |
| 39 |
table.add_column() |
| 40 |
table.add_row("COL1", "COL2") |
| 41 |
table.add_row("COL1", Rule(style=None)) |
| 42 |
table.add_row("COL1", "COL2") |
| 43 |
console.print(table) |
| 44 |
expected = dedent( |
| 45 |
"""\ |
| 46 |
+------------------------------+ |
| 47 |
| COL1 | COL2 | |
| 48 |
| COL1 | ──────────── | |
| 49 |
| COL1 | COL2 | |
| 50 |
+------------------------------+ |
| 51 |
""" |
| 52 |
) |
| 53 |
result = console.file.getvalue() |
| 54 |
assert result == expected |
| 55 |
|
| 56 |
|
| 57 |
def test_rule_in_ratio_table(): |
| 58 |
console = Console(width=32, file=io.StringIO(), legacy_windows=False, _environ={}) |
| 59 |
table = Table(box=box.ASCII, expand=True, show_header=False) |
| 60 |
table.add_column(ratio=1) |
| 61 |
table.add_column() |
| 62 |
table.add_row("COL1", "COL2") |
| 63 |
table.add_row("COL1", Rule(style=None)) |
| 64 |
table.add_row("COL1", "COL2") |
| 65 |
console.print(table) |
| 66 |
expected = dedent( |
| 67 |
"""\ |
| 68 |
+------------------------------+ |
| 69 |
| COL1 | COL2 | |
| 70 |
| COL1 | ──── | |
| 71 |
| COL1 | COL2 | |
| 72 |
+------------------------------+ |
| 73 |
""" |
| 74 |
) |
| 75 |
result = console.file.getvalue() |
| 76 |
assert result == expected |