-
Notifications
You must be signed in to change notification settings - Fork 815
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 #4313 from davep/bug/4248/click-markup-crash
Fix a crash in `run_action` when an action is an empty tuple
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Test https://github.com/Textualize/textual/issues/4248""" | ||
|
||
from textual.app import App, ComposeResult | ||
from textual.widgets import Label | ||
|
||
|
||
async def test_issue_4248() -> None: | ||
"""Various forms of click parameters should be fine.""" | ||
|
||
bumps = 0 | ||
|
||
class ActionApp(App[None]): | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Label("[@click]click me and crash[/]", id="nothing") | ||
yield Label("[@click=]click me and crash[/]", id="no-params") | ||
yield Label("[@click=()]click me and crash[/]", id="empty-params") | ||
yield Label("[@click=foobar]click me[/]", id="unknown-sans-parens") | ||
yield Label("[@click=foobar()]click me[/]", id="unknown-with-parens") | ||
yield Label("[@click=bump]click me[/]", id="known-sans-parens") | ||
yield Label("[@click=bump()]click me[/]", id="known-empty-parens") | ||
yield Label("[@click=bump(100)]click me[/]", id="known-with-param") | ||
|
||
def action_bump(self, by_value: int = 1) -> None: | ||
nonlocal bumps | ||
bumps += by_value | ||
|
||
app = ActionApp() | ||
async with app.run_test() as pilot: | ||
assert bumps == 0 | ||
await pilot.click("#nothing") | ||
assert bumps == 0 | ||
await pilot.click("#no-params") | ||
assert bumps == 0 | ||
await pilot.click("#empty-params") | ||
assert bumps == 0 | ||
await pilot.click("#unknown-sans-parens") | ||
assert bumps == 0 | ||
await pilot.click("#unknown-with-parens") | ||
assert bumps == 0 | ||
await pilot.click("#known-sans-parens") | ||
assert bumps == 1 | ||
await pilot.click("#known-empty-parens") | ||
assert bumps == 2 | ||
await pilot.click("#known-with-param") | ||
assert bumps == 102 |