summaryrefslogtreecommitdiffstats
path: root/tests/test_block_bar.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:18:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:18:28 +0000
commitf8363b456f1ab31ee56abad579b215af195093d5 (patch)
treeb1500c675c2e0a55fb75721a854e1510acf7c862 /tests/test_block_bar.py
parentInitial commit. (diff)
downloadrich-f8363b456f1ab31ee56abad579b215af195093d5.tar.xz
rich-f8363b456f1ab31ee56abad579b215af195093d5.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_block_bar.py')
-rw-r--r--tests/test_block_bar.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_block_bar.py b/tests/test_block_bar.py
new file mode 100644
index 0000000..973b9e8
--- /dev/null
+++ b/tests/test_block_bar.py
@@ -0,0 +1,53 @@
+from rich.bar import Bar
+
+from .render import render
+
+
+expected = [
+ "\x1b[39;49m ▐█████████████████████████ \x1b[0m\n",
+ "\x1b[39;49m ██████████████████████▌ \x1b[0m\n",
+ "\x1b[39;49m \x1b[0m\n",
+]
+
+
+def test_repr():
+ bar = Bar(size=100, begin=11, end=62, width=50)
+ assert repr(bar) == "Bar(100, 11, 62)"
+
+
+def test_render():
+ bar = Bar(size=100, begin=11, end=62, width=50)
+ bar_render = render(bar)
+ assert bar_render == expected[0]
+ bar = Bar(size=100, begin=12, end=57, width=50)
+ bar_render = render(bar)
+ assert bar_render == expected[1]
+ # begin after end
+ bar = Bar(size=100, begin=60, end=40, width=50)
+ bar_render = render(bar)
+ assert bar_render == expected[2]
+
+
+def test_measure():
+ bar = Bar(size=100, begin=11, end=62)
+ measurement = bar.__rich_measure__(None, 120)
+ assert measurement.minimum == 4
+ assert measurement.maximum == 120
+
+
+def test_zero_total():
+ # Shouldn't throw zero division error
+ bar = Bar(size=0, begin=0, end=0)
+ render(bar)
+
+
+if __name__ == "__main__":
+ bar = Bar(size=100, begin=11, end=62, width=50)
+ bar_render = render(bar)
+ print(repr(bar_render))
+ bar = Bar(size=100, begin=12, end=57, width=50)
+ bar_render = render(bar)
+ print(repr(bar_render))
+ bar = Bar(size=100, begin=60, end=40, width=50)
+ bar_render = render(bar)
+ print(repr(bar_render))