-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3981 from Textualize/apply-css-changes-screen-stack
Apply css changes screen stack
- Loading branch information
Showing
4 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* This file has no rules intentionally. */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |