mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 18:18:22 +00:00
tests
This commit is contained in:
parent
1d4cf489d8
commit
0c810d564c
2 changed files with 95 additions and 0 deletions
38
tests/test_theme.py
Normal file
38
tests/test_theme.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import io
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from rich.style import Style
|
||||
from rich.theme import Theme
|
||||
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue