Skip to content

Commit

Permalink
Add regression test for #3931.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao committed Jan 8, 2024
1 parent ea5cd4f commit 0926caf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/css/css_reloading.tcss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* This file has no rules intentionally. */
65 changes: 65 additions & 0 deletions tests/css/test_css_reloading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Regression test for https://github.com/Textualize/textual/issues/3931
"""

from pathlib import Path

from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Label

CSS_PATH = (Path(__file__) / "../css_reloading.tcss").resolve()

Path(CSS_PATH).write_text(
"""\
Label {
height: 5;
border: panel white;
}
"""
)


class BaseScreen(Screen[None]):
def compose(self) -> ComposeResult:
yield Label("I am the base screen")


class TopScreen(Screen[None]):
DEFAULT_CSS = """
TopScreen {
opacity: 1;
background: green 0%;
}
"""


class MyApp(App[None]):
CSS_PATH = CSS_PATH

def on_mount(self) -> None:
self.push_screen(BaseScreen())
self.push_screen(TopScreen())


async def test_css_reloading_applies_to_non_top_screen(monkeypatch) -> None: # type: ignore
"""Regression test for https://github.com/Textualize/textual/issues/2063."""

monkeypatch.setenv(
"TEXTUAL", "debug"
) # This will make sure we create a file monitor.

app = MyApp()
async with app.run_test() as pilot:
await pilot.pause()
first_label = pilot.app.screen_stack[-2].query(Label).first()
# Sanity check.
assert first_label.styles.height is not None
assert first_label.styles.height.value == 5

# Clear the CSS from the file.
Path(CSS_PATH).write_text("/* This file has no rules intentionally. */\n")
await pilot.app._on_css_change()
# Height should fall back to 1.
assert first_label.styles.height is not None
assert first_label.styles.height.value == 1

0 comments on commit 0926caf

Please sign in to comment.