-
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.
- Loading branch information
1 parent
40d9997
commit 7e83acb
Showing
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.message import Message | ||
from textual.widget import Widget | ||
|
||
|
||
async def test_message_inheritance_namespace(): | ||
"""Inherited messages get their correct namespaces. | ||
Regression test for https://github.com/Textualize/textual/issues/1814. | ||
""" | ||
|
||
class BaseWidget(Widget): | ||
class Fired(Message): | ||
pass | ||
|
||
def trigger(self) -> None: | ||
self.post_message(self.Fired()) | ||
|
||
class Left(BaseWidget): | ||
class Fired(BaseWidget.Fired): | ||
pass | ||
|
||
class Right(BaseWidget): | ||
class Fired(BaseWidget.Fired): | ||
pass | ||
|
||
handlers_called = [] | ||
|
||
class MessageInheritanceApp(App[None]): | ||
def compose(self) -> ComposeResult: | ||
yield Left() | ||
yield Right() | ||
|
||
def on_left_fired(self): | ||
handlers_called.append("left") | ||
|
||
def on_right_fired(self): | ||
handlers_called.append("right") | ||
|
||
app = MessageInheritanceApp() | ||
async with app.run_test(): | ||
app.query_one(Left).trigger() | ||
app.query_one(Right).trigger() | ||
|
||
assert handlers_called == ["left", "right"] |