Run black over the tests

This commit is contained in:
Dave Pearson
2022-12-14 10:58:09 +00:00
parent ca9c3b43dd
commit 5859437040

View File

@@ -31,6 +31,7 @@ MOVEMENT_KEYS = ["up", "down", "left", "right", "home", "end", "pageup", "pagedo
# bindings set anywhere, and uses a default screen, should only have the one # bindings set anywhere, and uses a default screen, should only have the one
# binding in place: ctrl+c; it's hard-coded in the app class for now. # binding in place: ctrl+c; it's hard-coded in the app class for now.
class NoBindings(App[None]): class NoBindings(App[None]):
"""An app with zero bindings.""" """An app with zero bindings."""
@@ -49,6 +50,7 @@ async def test_just_app_no_bindings() -> None:
# words avoiding anything to do with movement keys. The result should be # words avoiding anything to do with movement keys. The result should be
# that we see the letter a, ctrl+c, and nothing else. # that we see the letter a, ctrl+c, and nothing else.
class AlphaBinding(App[None]): class AlphaBinding(App[None]):
"""An app with a simple alpha key binding.""" """An app with a simple alpha key binding."""
@@ -71,6 +73,7 @@ async def test_just_app_alpha_binding() -> None:
# To start with the screen has no bindings -- it's just a direct subclass # To start with the screen has no bindings -- it's just a direct subclass
# with no other changes. # with no other changes.
class ScreenNoBindings(Screen): class ScreenNoBindings(Screen):
"""A screen with no added bindings.""" """A screen with no added bindings."""
@@ -90,7 +93,9 @@ class AppWithScreenNoBindings(App[None]):
async def test_app_screen_has_no_movement_bindings() -> None: async def test_app_screen_has_no_movement_bindings() -> None:
"""A screen with no bindings should not have movement key bindings.""" """A screen with no bindings should not have movement key bindings."""
async with AppWithScreenNoBindings().run_test() as pilot: async with AppWithScreenNoBindings().run_test() as pilot:
assert sorted(list(pilot.app.screen._bindings.keys.keys())) != sorted(MOVEMENT_KEYS) assert sorted(list(pilot.app.screen._bindings.keys.keys())) != sorted(
MOVEMENT_KEYS
)
############################################################################## ##############################################################################
@@ -100,6 +105,7 @@ async def test_app_screen_has_no_movement_bindings() -> None:
# now do the same thing but with a binding added that isn't for a movement # now do the same thing but with a binding added that isn't for a movement
# key. # key.
class ScreenWithBindings(Screen): class ScreenWithBindings(Screen):
"""A screen with a simple alpha key binding.""" """A screen with a simple alpha key binding."""
@@ -132,6 +138,7 @@ async def test_app_screen_with_bindings() -> None:
# to see zero bindings in place, but do so when the screen has a child; # to see zero bindings in place, but do so when the screen has a child;
# presumably making it pass as a container. # presumably making it pass as a container.
class NoBindingsAndStaticWidgetNoBindings(App[None]): class NoBindingsAndStaticWidgetNoBindings(App[None]):
"""An app with no bindings, enclosing a widget with no bindings.""" """An app with no bindings, enclosing a widget with no bindings."""
@@ -153,6 +160,7 @@ async def test_just_app_no_bindings_widget_no_bindings() -> None:
# any bindings that are in place actually fire the correct actions. To help # any bindings that are in place actually fire the correct actions. To help
# with this let's build a simple key/binding/action recorder base app. # with this let's build a simple key/binding/action recorder base app.
class AppKeyRecorder(App[None]): class AppKeyRecorder(App[None]):
"""Base application class that can be used to record keystrokes.""" """Base application class that can be used to record keystrokes."""
@@ -173,7 +181,8 @@ class AppKeyRecorder(App[None]):
list[Binding]: The resulting list of bindings. list[Binding]: The resulting list of bindings.
""" """
return [ return [
Binding( key, f"{prefix}record('{key}')", key ) for key in [*AppKeyRecorder.ALPHAS, *MOVEMENT_KEYS] Binding(key, f"{prefix}record('{key}')", key)
for key in [*AppKeyRecorder.ALPHAS, *MOVEMENT_KEYS]
] ]
def __init__(self) -> None: def __init__(self) -> None:
@@ -206,8 +215,10 @@ class AppKeyRecorder(App[None]):
# seeing what happens. First off let's start with an application that has # seeing what happens. First off let's start with an application that has
# bindings, both for an alpha key, and also for all of the movement keys. # bindings, both for an alpha key, and also for all of the movement keys.
class AppWithMovementKeysBound(AppKeyRecorder): class AppWithMovementKeysBound(AppKeyRecorder):
"""An application with bindings.""" """An application with bindings."""
BINDINGS = AppKeyRecorder.mk_bindings() BINDINGS = AppKeyRecorder.mk_bindings()
@@ -239,8 +250,10 @@ async def test_pressing_movement_keys_app() -> None:
# able to handle all of the test keys on its own and nothing else should # able to handle all of the test keys on its own and nothing else should
# grab them. # grab them.
class FocusableWidgetWithBindings(Static, can_focus=True): class FocusableWidgetWithBindings(Static, can_focus=True):
"""A widget that has its own bindings for the movement keys.""" """A widget that has its own bindings for the movement keys."""
BINDINGS = AppKeyRecorder.mk_bindings("local_") BINDINGS = AppKeyRecorder.mk_bindings("local_")
async def action_local_record(self, key: str) -> None: async def action_local_record(self, key: str) -> None:
@@ -265,6 +278,7 @@ async def test_focused_child_widget_with_movement_bindings() -> None:
await pilot.pause(2 / 100) await pilot.pause(2 / 100)
pilot.app.all_recorded("locally_") pilot.app.all_recorded("locally_")
############################################################################## ##############################################################################
# A focused widget within a screen that handles bindings. # A focused widget within a screen that handles bindings.
# #
@@ -274,9 +288,11 @@ async def test_focused_child_widget_with_movement_bindings() -> None:
# bindings. What we should expect to see is that the bindings don't fire on # bindings. What we should expect to see is that the bindings don't fire on
# the widget (it has none) and instead get caught by the screen. # the widget (it has none) and instead get caught by the screen.
class FocusableWidgetWithNoBindings(Static, can_focus=True): class FocusableWidgetWithNoBindings(Static, can_focus=True):
"""A widget that can receive focus but has no bindings.""" """A widget that can receive focus but has no bindings."""
class ScreenWithMovementBindings(Screen): class ScreenWithMovementBindings(Screen):
"""A screen that binds keys, including movement keys.""" """A screen that binds keys, including movement keys."""
@@ -292,6 +308,7 @@ class ScreenWithMovementBindings(Screen):
def on_mount(self) -> None: def on_mount(self) -> None:
self.query_one(FocusableWidgetWithNoBindings).focus() self.query_one(FocusableWidgetWithNoBindings).focus()
class AppWithScreenWithBindingsWidgetNoBindings(AppKeyRecorder): class AppWithScreenWithBindingsWidgetNoBindings(AppKeyRecorder):
"""An app with a non-default screen that handles movement key bindings.""" """An app with a non-default screen that handles movement key bindings."""
@@ -300,6 +317,7 @@ class AppWithScreenWithBindingsWidgetNoBindings(AppKeyRecorder):
def on_mount(self) -> None: def on_mount(self) -> None:
self.push_screen("main") self.push_screen("main")
@pytest.mark.xfail( @pytest.mark.xfail(
reason="Movement keys never make it to the screen with such bindings due to key inheritance and pre-bound movement keys [issue#1343]" reason="Movement keys never make it to the screen with such bindings due to key inheritance and pre-bound movement keys [issue#1343]"
) )
@@ -310,6 +328,7 @@ async def test_focused_child_widget_with_movement_bindings_on_screen() -> None:
await pilot.pause(2 / 100) await pilot.pause(2 / 100)
pilot.app.all_recorded("screenly_") pilot.app.all_recorded("screenly_")
############################################################################## ##############################################################################
# A focused widget within a container within a screen that handles bindings. # A focused widget within a container within a screen that handles bindings.
# #
@@ -322,6 +341,7 @@ async def test_focused_child_widget_with_movement_bindings_on_screen() -> None:
# Although it's not at the end of the unit tests, this is potentially the # Although it's not at the end of the unit tests, this is potentially the
# "final boss" of these tests. # "final boss" of these tests.
class ScreenWithMovementBindingsAndContainerAroundWidget(Screen): class ScreenWithMovementBindingsAndContainerAroundWidget(Screen):
"""A screen that binds keys, including movement keys.""" """A screen that binds keys, including movement keys."""
@@ -337,6 +357,7 @@ class ScreenWithMovementBindingsAndContainerAroundWidget(Screen):
def on_mount(self) -> None: def on_mount(self) -> None:
self.query_one(FocusableWidgetWithNoBindings).focus() self.query_one(FocusableWidgetWithNoBindings).focus()
class AppWithScreenWithBindingsWrappedWidgetNoBindings(AppKeyRecorder): class AppWithScreenWithBindingsWrappedWidgetNoBindings(AppKeyRecorder):
"""An app with a non-default screen that handles movement key bindings.""" """An app with a non-default screen that handles movement key bindings."""
@@ -345,6 +366,7 @@ class AppWithScreenWithBindingsWrappedWidgetNoBindings(AppKeyRecorder):
def on_mount(self) -> None: def on_mount(self) -> None:
self.push_screen("main") self.push_screen("main")
@pytest.mark.xfail( @pytest.mark.xfail(
reason="Movement keys never make it to the screen with such bindings due to key inheritance and pre-bound movement keys [issue#1343]" reason="Movement keys never make it to the screen with such bindings due to key inheritance and pre-bound movement keys [issue#1343]"
) )
@@ -355,6 +377,7 @@ async def test_contained_focused_child_widget_with_movement_bindings_on_screen()
await pilot.pause(2 / 100) await pilot.pause(2 / 100)
pilot.app.all_recorded("screenly_") pilot.app.all_recorded("screenly_")
############################################################################## ##############################################################################
# A focused widget with bindings but no inheriting of bindings, on app. # A focused widget with bindings but no inheriting of bindings, on app.
# #
@@ -365,8 +388,10 @@ async def test_contained_focused_child_widget_with_movement_bindings_on_screen()
# #
# We should expect to see all of the test keys recorded post-press. # We should expect to see all of the test keys recorded post-press.
class WidgetWithBindingsNoInherit(Static, can_focus=True, inherit_bindings=False): class WidgetWithBindingsNoInherit(Static, can_focus=True, inherit_bindings=False):
"""A widget that has its own bindings for the movement keys, no binding inheritance.""" """A widget that has its own bindings for the movement keys, no binding inheritance."""
BINDINGS = AppKeyRecorder.mk_bindings("local_") BINDINGS = AppKeyRecorder.mk_bindings("local_")
async def action_local_record(self, key: str) -> None: async def action_local_record(self, key: str) -> None:
@@ -391,6 +416,7 @@ async def test_focused_child_widget_with_movement_bindings_no_inherit() -> None:
await pilot.pause(2 / 100) await pilot.pause(2 / 100)
pilot.app.all_recorded("locally_") pilot.app.all_recorded("locally_")
############################################################################## ##############################################################################
# A focused widget with no bindings and no inheriting of bindings, on screen. # A focused widget with no bindings and no inheriting of bindings, on screen.
# #
@@ -403,9 +429,13 @@ async def test_focused_child_widget_with_movement_bindings_no_inherit() -> None:
# NOTE: no bindings are declared for the widget, which is different from # NOTE: no bindings are declared for the widget, which is different from
# zero bindings declared. # zero bindings declared.
class FocusableWidgetWithNoBindingsNoInherit(Static, can_focus=True, inherit_bindings=False):
class FocusableWidgetWithNoBindingsNoInherit(
Static, can_focus=True, inherit_bindings=False
):
"""A widget that can receive focus but has no bindings and doesn't inherit bindings.""" """A widget that can receive focus but has no bindings and doesn't inherit bindings."""
class ScreenWithMovementBindingsNoInheritChild(Screen): class ScreenWithMovementBindingsNoInheritChild(Screen):
"""A screen that binds keys, including movement keys.""" """A screen that binds keys, including movement keys."""
@@ -421,6 +451,7 @@ class ScreenWithMovementBindingsNoInheritChild(Screen):
def on_mount(self) -> None: def on_mount(self) -> None:
self.query_one(FocusableWidgetWithNoBindingsNoInherit).focus() self.query_one(FocusableWidgetWithNoBindingsNoInherit).focus()
class AppWithScreenWithBindingsWidgetNoBindingsNoInherit(AppKeyRecorder): class AppWithScreenWithBindingsWidgetNoBindingsNoInherit(AppKeyRecorder):
"""An app with a non-default screen that handles movement key bindings, child no-inherit.""" """An app with a non-default screen that handles movement key bindings, child no-inherit."""
@@ -429,6 +460,7 @@ class AppWithScreenWithBindingsWidgetNoBindingsNoInherit(AppKeyRecorder):
def on_mount(self) -> None: def on_mount(self) -> None:
self.push_screen("main") self.push_screen("main")
async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen() -> None: async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen() -> None:
"""A focused child widget, that doesn't inherit bindings, with movement bindings in the screen, should trigger screen actions.""" """A focused child widget, that doesn't inherit bindings, with movement bindings in the screen, should trigger screen actions."""
async with AppWithScreenWithBindingsWidgetNoBindingsNoInherit().run_test() as pilot: async with AppWithScreenWithBindingsWidgetNoBindingsNoInherit().run_test() as pilot:
@@ -436,6 +468,7 @@ async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen(
await pilot.pause(2 / 100) await pilot.pause(2 / 100)
pilot.app.all_recorded("screenly_") pilot.app.all_recorded("screenly_")
############################################################################## ##############################################################################
# A focused widget with zero bindings declared, but no inheriting of # A focused widget with zero bindings declared, but no inheriting of
# bindings, on screen. # bindings, on screen.
@@ -449,10 +482,15 @@ async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen(
# NOTE: zero bindings are declared for the widget, which is different from # NOTE: zero bindings are declared for the widget, which is different from
# no bindings declared. # no bindings declared.
class FocusableWidgetWithEmptyBindingsNoInherit(Static, can_focus=True, inherit_bindings=False):
class FocusableWidgetWithEmptyBindingsNoInherit(
Static, can_focus=True, inherit_bindings=False
):
"""A widget that can receive focus but has empty bindings and doesn't inherit bindings.""" """A widget that can receive focus but has empty bindings and doesn't inherit bindings."""
BINDINGS = [] BINDINGS = []
class ScreenWithMovementBindingsNoInheritEmptyChild(Screen): class ScreenWithMovementBindingsNoInheritEmptyChild(Screen):
"""A screen that binds keys, including movement keys.""" """A screen that binds keys, including movement keys."""
@@ -468,6 +506,7 @@ class ScreenWithMovementBindingsNoInheritEmptyChild(Screen):
def on_mount(self) -> None: def on_mount(self) -> None:
self.query_one(FocusableWidgetWithEmptyBindingsNoInherit).focus() self.query_one(FocusableWidgetWithEmptyBindingsNoInherit).focus()
class AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit(AppKeyRecorder): class AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit(AppKeyRecorder):
"""An app with a non-default screen that handles movement key bindings, child no-inherit.""" """An app with a non-default screen that handles movement key bindings, child no-inherit."""
@@ -476,6 +515,7 @@ class AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit(AppKeyRecorder):
def on_mount(self) -> None: def on_mount(self) -> None:
self.push_screen("main") self.push_screen("main")
async def test_focused_child_widget_no_inherit_empty_bindings_with_movement_bindings_on_screen() -> None: async def test_focused_child_widget_no_inherit_empty_bindings_with_movement_bindings_on_screen() -> None:
"""A focused child widget, that doesn't inherit bindings and sets BINDINGS empty, with movement bindings in the screen, should trigger screen actions.""" """A focused child widget, that doesn't inherit bindings and sets BINDINGS empty, with movement bindings in the screen, should trigger screen actions."""
async with AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit().run_test() as pilot: async with AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit().run_test() as pilot: