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_spinner.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_spinner.py')
-rw-r--r-- | tests/test_spinner.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_spinner.py b/tests/test_spinner.py new file mode 100644 index 0000000..7f2b0a1 --- /dev/null +++ b/tests/test_spinner.py @@ -0,0 +1,42 @@ +from time import time +import pytest + +from rich.console import Console +from rich.measure import Measurement +from rich.spinner import Spinner + + +def test_spinner_create(): + spinner = Spinner("dots") + assert spinner.time == 0.0 + with pytest.raises(KeyError): + Spinner("foobar") + + +def test_spinner_render(): + time = 0.0 + + def get_time(): + nonlocal time + return time + + console = Console( + width=80, color_system=None, force_terminal=True, get_time=get_time + ) + console.begin_capture() + spinner = Spinner("dots", "Foo") + console.print(spinner) + time += 80 / 1000 + console.print(spinner) + result = console.end_capture() + print(repr(result)) + expected = "⠋ Foo\n⠙ Foo\n" + assert result == expected + + +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, spinner, 80) + assert min_width == 3 + assert max_width == 5 |