File: test_setting_themes.py

package info (click to toggle)
textual 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,084 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (56 lines) | stat: -rw-r--r-- 1,561 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pytest

from textual._text_area_theme import TextAreaTheme
from textual.app import App, ComposeResult
from textual.widgets import TextArea
from textual.widgets._text_area import ThemeDoesNotExist


class TextAreaApp(App[None]):
    def compose(self) -> ComposeResult:
        yield TextArea("print('hello')", language="python")


async def test_default_theme():
    app = TextAreaApp()

    async with app.run_test():
        text_area = app.query_one(TextArea)
        assert text_area.theme is "css"


async def test_setting_builtin_themes():
    class MyTextAreaApp(App[None]):
        def compose(self) -> ComposeResult:
            yield TextArea("print('hello')", language="python", theme="vscode_dark")

    app = MyTextAreaApp()

    async with app.run_test():
        text_area = app.query_one(TextArea)
        assert text_area.theme == "vscode_dark"

        text_area.theme = "monokai"
        assert text_area.theme == "monokai"


async def test_setting_unknown_theme_raises_exception():
    app = TextAreaApp()
    async with app.run_test():
        text_area = app.query_one(TextArea)
        with pytest.raises(ThemeDoesNotExist):
            text_area.theme = "this-theme-doesnt-exist"


async def test_registering_and_setting_theme():
    app = TextAreaApp()

    async with app.run_test():
        text_area = app.query_one(TextArea)
        text_area.register_theme(TextAreaTheme("my-theme"))

        assert "my-theme" in text_area.available_themes

        text_area.theme = "my-theme"

        assert text_area.theme == "my-theme"