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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Container
from textual.css.scalar import ScalarOffset
class StyleApp(App[None]):
CSS = """
Container {
border: round green !important;
outline: round green !important;
align: right bottom !important;
content-align: right bottom !important;
offset: 17 23 !important;
overflow: hidden hidden !important;
padding: 10 20 30 40 !important;
scrollbar-size: 23 42 !important;
}
Container.more-specific {
border: solid red;
outline: solid red;
align: center middle;
content-align: center middle;
offset: 0 0;
overflow: scroll scroll;
padding: 1 2 3 4;
scrollbar-size: 1 2;
}
"""
def compose(self) -> ComposeResult:
yield Container(classes="more-specific")
async def test_border_importance():
"""Border without sides should support !important"""
async with StyleApp().run_test() as pilot:
border = pilot.app.query_one(Container).styles.border
desired = ("round", Color.parse("green"))
assert border.top == desired
assert border.left == desired
assert border.bottom == desired
assert border.right == desired
async def test_outline_importance():
"""Outline without sides should support !important"""
async with StyleApp().run_test() as pilot:
outline = pilot.app.query_one(Container).styles.outline
desired = ("round", Color.parse("green"))
assert outline.top == desired
assert outline.left == desired
assert outline.bottom == desired
assert outline.right == desired
async def test_align_importance():
"""Align without direction should support !important"""
async with StyleApp().run_test() as pilot:
assert pilot.app.query_one(Container).styles.align == ("right", "bottom")
async def test_content_align_importance():
"""Content align without direction should support !important"""
async with StyleApp().run_test() as pilot:
assert pilot.app.query_one(Container).styles.content_align == (
"right",
"bottom",
)
async def test_offset_importance():
"""Offset without direction should support !important"""
async with StyleApp().run_test() as pilot:
assert pilot.app.query_one(Container).styles.offset == ScalarOffset.from_offset(
(17, 23)
)
async def test_overflow_importance():
"""Overflow without direction should support !important"""
async with StyleApp().run_test() as pilot:
assert pilot.app.query_one(Container).styles.overflow_x == "hidden"
assert pilot.app.query_one(Container).styles.overflow_y == "hidden"
async def test_padding_importance():
"""Padding without sides should support !important"""
async with StyleApp().run_test() as pilot:
padding = pilot.app.query_one(Container).styles.padding
assert padding.top == 10
assert padding.left == 40
assert padding.bottom == 30
assert padding.right == 20
async def test_scrollbar_size_importance():
"""Scrollbar size without direction should support !important"""
async with StyleApp().run_test() as pilot:
assert pilot.app.query_one(Container).styles.scrollbar_size_horizontal == 23
assert pilot.app.query_one(Container).styles.scrollbar_size_vertical == 42
|