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_theme.py | |
parent | Initial commit. (diff) | |
download | rich-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 '')
-rw-r--r-- | tests/test_theme.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_theme.py b/tests/test_theme.py new file mode 100644 index 0000000..228cb18 --- /dev/null +++ b/tests/test_theme.py @@ -0,0 +1,53 @@ +import io +import os +import tempfile + +import pytest + +from rich.style import Style +from rich.theme import Theme, ThemeStack, ThemeStackError + + +def test_inherit(): + theme = Theme({"warning": "red"}) + assert theme.styles["warning"] == Style(color="red") + assert theme.styles["dim"] == Style(dim=True) + + +def test_config(): + theme = Theme({"warning": "red"}) + config = theme.config + assert "warning = red\n" in config + + +def test_from_file(): + theme = Theme({"warning": "red"}) + text_file = io.StringIO() + text_file.write(theme.config) + text_file.seek(0) + + load_theme = Theme.from_file(text_file) + assert theme.styles == load_theme.styles + + +def test_read(): + theme = Theme({"warning": "red"}) + with tempfile.TemporaryDirectory("richtheme") as name: + filename = os.path.join(name, "theme.cfg") + with open(filename, "wt") as write_theme: + write_theme.write(theme.config) + load_theme = Theme.read(filename) + assert theme.styles == load_theme.styles + + +def test_theme_stack(): + theme = Theme({"warning": "red"}) + stack = ThemeStack(theme) + assert stack.get("warning") == Style.parse("red") + new_theme = Theme({"warning": "bold yellow"}) + stack.push_theme(new_theme) + assert stack.get("warning") == Style.parse("bold yellow") + stack.pop_theme() + assert stack.get("warning") == Style.parse("red") + with pytest.raises(ThemeStackError): + stack.pop_theme() |