rich/tests/test_columns_align.py

44 lines
3.5 KiB
Python
Raw Normal View History

2020-07-10 16:31:29 +00:00
# encoding=utf-8
2020-07-10 16:26:31 +00:00
import io
2020-07-10 16:31:29 +00:00
from rich import box
2020-07-10 16:26:31 +00:00
from rich.columns import Columns
from rich.console import Console
from rich.panel import Panel
def render():
console = Console(file=io.StringIO(), width=100, legacy_windows=False)
2020-07-10 16:31:29 +00:00
panel = Panel.fit("foo", box=box.SQUARE)
2020-07-10 16:26:31 +00:00
columns = Columns([panel] * 4)
columns.expand = True
console.rule("no align")
console.print(columns)
columns.align = "left"
console.rule("left align")
console.print(columns)
columns.align = "center"
console.rule("center align")
console.print(columns)
columns.align = "right"
console.rule("right align")
console.print(columns)
return console.file.getvalue()
def test_align():
result = render()
2020-07-10 16:31:29 +00:00
expected = "───────────────────────────────────────────── no align ─────────────────────────────────────────────\n┌───┐ ┌───┐ ┌───┐ ┌───┐ \n│foo│ │foo│ │foo│ │foo│ \n└───┘ └───┘ └───┘ └───┘ \n──────────────────────────────────────────── left align ────────────────────────────────────────────\n┌───┐ ┌───┐ ┌───┐ ┌───┐ \n│foo│ │foo│ │foo│ │foo│ \n└───┘ └───┘ └───┘ └───┘ \n─────────────────────────────────────────── center align ───────────────────────────────────────────\n ┌───┐ ┌───┐ ┌───┐ ┌───┐ \n │foo│ │foo│ │foo│ │foo│ \n └───┘ └───┘ └───┘ └───┘ \n─────────────────────────────────────────── right align ────────────────────────────────────────────\n ┌───┐ ┌───┐ ┌───┐ ┌───┐\n │foo│ │foo│ │foo│ │foo│\n └───┘ └───┘ └───┘ └───┘\n"
2020-07-10 16:26:31 +00:00
assert result == expected
if __name__ == "__main__":
rendered = render()
print(rendered)
print(repr(rendered))