diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
commit | f8363b456f1ab31ee56abad579b215af195093d5 (patch) | |
tree | b1500c675c2e0a55fb75721a854e1510acf7c862 /tests/test_columns_align.py | |
parent | Initial commit. (diff) | |
download | rich-upstream.tar.xz rich-upstream.zip |
Adding upstream version 9.11.0.upstream/9.11.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_columns_align.py')
-rw-r--r-- | tests/test_columns_align.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_columns_align.py b/tests/test_columns_align.py new file mode 100644 index 0000000..456510a --- /dev/null +++ b/tests/test_columns_align.py @@ -0,0 +1,43 @@ +# encoding=utf-8 + +import io + +from rich import box +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) + panel = Panel.fit("foo", box=box.SQUARE, padding=0) + 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() + 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" + assert result == expected + + +if __name__ == "__main__": + rendered = render() + print(rendered) + print(repr(rendered)) |