mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add wip test for user over widget css, use type alias
This commit is contained in:
11
sandbox/darren/just_a_box.css
Normal file
11
sandbox/darren/just_a_box.css
Normal file
@@ -0,0 +1,11 @@
|
||||
Screen {
|
||||
layout: dock;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#box {
|
||||
height: 50%;
|
||||
width: 50%;
|
||||
align: center middle;
|
||||
background: green;
|
||||
}
|
||||
12
sandbox/darren/just_a_box.py
Normal file
12
sandbox/darren/just_a_box.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class JustABox(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Hello, World!", id="box")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = JustABox(css_path="just_a_box.css", watch_css=True)
|
||||
app.run()
|
||||
@@ -7,6 +7,7 @@ from typing import Iterator, Iterable
|
||||
from rich import print
|
||||
|
||||
from textual.css.errors import UnresolvedVariableError
|
||||
from textual.css.types import Specificity3
|
||||
from ._styles_builder import StylesBuilder, DeclarationError
|
||||
from .model import (
|
||||
Declaration,
|
||||
@@ -20,7 +21,7 @@ from .styles import Styles
|
||||
from .tokenize import tokenize, tokenize_declarations, Token, tokenize_values
|
||||
from .tokenizer import EOFError, ReferencedBy
|
||||
|
||||
SELECTOR_MAP: dict[str, tuple[SelectorType, tuple[int, int, int]]] = {
|
||||
SELECTOR_MAP: dict[str, tuple[SelectorType, Specificity3]] = {
|
||||
"selector": (SelectorType.TYPE, (0, 0, 1)),
|
||||
"selector_start": (SelectorType.TYPE, (0, 0, 1)),
|
||||
"selector_class": (SelectorType.CLASS, (0, 1, 0)),
|
||||
|
||||
@@ -3,12 +3,15 @@ from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.utilities.test_app import AppTest
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.color import Color
|
||||
from textual.css._help_renderables import HelpText
|
||||
from textual.css.stylesheet import Stylesheet, StylesheetParseError
|
||||
from textual.css.tokenizer import TokenizeError
|
||||
from textual.dom import DOMNode
|
||||
from textual.geometry import Spacing
|
||||
from textual.widget import Widget
|
||||
|
||||
|
||||
def _make_stylesheet(css: str) -> Stylesheet:
|
||||
@@ -101,6 +104,24 @@ def test_stylesheet_apply_empty_rulesets():
|
||||
stylesheet.apply(node)
|
||||
|
||||
|
||||
@pytest.mark.xfail(reason="wip")
|
||||
def test_stylesheet_apply_user_css_over_widget_css():
|
||||
user_css = ".a {color: red;}"
|
||||
|
||||
class MyWidget(Widget):
|
||||
CSS = ".a {color: blue;}"
|
||||
|
||||
node = MyWidget()
|
||||
node.add_class("a")
|
||||
|
||||
print(node.styles.color)
|
||||
stylesheet = _make_stylesheet(user_css)
|
||||
stylesheet.apply(node)
|
||||
|
||||
assert node.styles.background == Color(0, 0, 255)
|
||||
# TODO: On Tuesday - writing the tests for prioritising user CSS above widget CSS.
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"css_value,expectation,expected_color",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user