Skip to content

Commit

Permalink
Improved end of FlowTest handling, raising intentional Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmukai committed Jul 15, 2024
1 parent 3957551 commit 5683a8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def run_sequence(self, sequence: list[FlowStep], initial_destination_view_args:
def run_view(destination: Destination, *args, **kwargs):
""" Replaces Destination._run_view() """
if len(sequence) == 0:
# Nothing left to do.
self.stop_test()

cur_flow_step = sequence[0]
Expand All @@ -184,6 +185,13 @@ def run_view(destination: Destination, *args, **kwargs):
# View class that is being run.
if destination.View_cls != cur_flow_step.expected_view:
raise FlowTestUnexpectedViewException(f"Expected {cur_flow_step.expected_view}, got {destination.View_cls}")

if len(sequence) == 1:
# This is the last step in the sequence
if cur_flow_step.screen_return_value is None and cur_flow_step.button_data_selection is None:
# This is the last View in the sequence and it doesn't specify any
# user-mimicking interactions for the Screen. Nothing left to do.
self.stop_test()

try:
if cur_flow_step.is_redirect and destination.view.has_redirect:
Expand Down Expand Up @@ -246,6 +254,10 @@ def run_screen(view: View, *args, **kwargs):

elif type(cur_flow_step.screen_return_value) in [StopFlowBasedTest, FlowBasedTestException]:
raise cur_flow_step.screen_return_value

elif isinstance(cur_flow_step.screen_return_value, Exception):
# The FlowStep wants to mimic the Screen raising an exception.
raise cur_flow_step.screen_return_value

return cur_flow_step.screen_return_value

Expand Down
6 changes: 3 additions & 3 deletions tests/test_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from seedsigner.gui.screens.screen import RET_CODE__BACK_BUTTON, RET_CODE__POWER_BUTTON
from seedsigner.models.seed import Seed
from seedsigner.views.psbt_views import PSBTSelectSeedView
from seedsigner.views.seed_views import SeedBackupView, SeedMnemonicEntryView, SeedOptionsView, SeedSelectSeedView, SeedsMenuView
from seedsigner.views.seed_views import SeedBackupView, SeedMnemonicEntryView, SeedOptionsView, SeedsMenuView
from seedsigner.views.view import MainMenuView, PowerOptionsView, UnhandledExceptionView
from seedsigner.views.tools_views import ToolsMenuView, ToolsCalcFinalWordNumWordsView

Expand Down Expand Up @@ -36,7 +36,7 @@ def test_FlowTestUnexpectedViewException(self):
with pytest.raises(FlowTestUnexpectedViewException):
self.run_sequence([
FlowStep(MainMenuView, button_data_selection=RET_CODE__POWER_BUTTON),
FlowStep(ToolsMenuView), # <-- Wrong target View! Should raise an AssertionError.
FlowStep(ToolsMenuView), # <-- Wrong target View!
])


Expand Down Expand Up @@ -74,7 +74,7 @@ def test_FlowTestUnexpectedRedirectException(self):
"""
with pytest.raises(FlowTestUnexpectedRedirectException) as e:
self.run_sequence([
FlowStep(SeedsMenuView, screen_return_value=0), # <-- No seeds loaded, so it'll redirect elsewhere
FlowStep(SeedsMenuView, button_data_selection=SeedsMenuView.LOAD), # <-- No seeds loaded, so it'll redirect elsewhere
])

# This time we'll show that we know it should redirect
Expand Down

0 comments on commit 5683a8e

Please sign in to comment.