Skip to content

Commit

Permalink
Add a test and remove dead code (#3514)
Browse files Browse the repository at this point in the history
* Remove dead code.

MouseScrollUp and MouseScrollDown inherit from MouseEvent so this branch is never taken.

* Add screen test.
  • Loading branch information
rodrigogiraoserrao authored Oct 23, 2023
1 parent 859cff3 commit 2ccc063
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
11 changes: 0 additions & 11 deletions src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,17 +976,6 @@ def _forward_event(self, event: events.Event) -> None:
else:
widget._forward_event(event._apply_offset(-region.x, -region.y))

elif isinstance(event, (events.MouseScrollDown, events.MouseScrollUp)):
try:
widget, _region = self.get_widget_at(event.x, event.y)
except errors.NoWidget:
return
scroll_widget = widget
if scroll_widget is not None:
if scroll_widget is self:
self.post_message(event)
else:
scroll_widget._forward_event(event)
else:
self.post_message(event)

Expand Down
23 changes: 21 additions & 2 deletions tests/test_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from textual import work
from textual.app import App, ComposeResult, ScreenStackError
from textual.events import MouseMove
from textual.events import MouseMove, MouseScrollDown, MouseScrollUp
from textual.geometry import Offset
from textual.screen import Screen
from textual.widgets import Button, Input, Label
from textual.widgets import Button, DataTable, Input, Label
from textual.worker import NoActiveWorker

skip_py310 = pytest.mark.skipif(
Expand Down Expand Up @@ -304,6 +304,25 @@ async def key_p(self) -> None:
app.bottom.dismiss()


async def test_dismiss_action():
class ConfirmScreen(Screen[bool]):
BINDINGS = [("y", "dismiss(True)", "Dismiss")]

class MyApp(App[None]):
bingo = False

def on_mount(self) -> None:
self.push_screen(ConfirmScreen(), callback=self.callback)

def callback(self, result: bool) -> None:
self.bingo = result

app = MyApp()
async with app.run_test() as pilot:
await pilot.press("y")
assert app.bingo


async def test_switch_screen_no_op():
"""Regression test for https://github.com/Textualize/textual/issues/2650"""

Expand Down

0 comments on commit 2ccc063

Please sign in to comment.