Skip to content

Commit 4e3f4b8

Browse files
committed
rearrange test order
1 parent 9577550 commit 4e3f4b8

1 file changed

Lines changed: 53 additions & 53 deletions

File tree

tests/test_cli.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,59 @@ async def passthrough_awaitable(awaitable):
662662
mock_hub.download.assert_called_once_with(new_path)
663663
mock_hub.run.assert_called_once_with(new_path, wait=True)
664664

665+
@pytest.mark.asyncio
666+
async def test_stay_connected_menu_run_stored(self):
667+
"""Test that the run_stored program option doesn't call an inaccessible method on an old hub."""
668+
669+
async def passthrough_awaitable(awaitable):
670+
return await awaitable
671+
672+
# Create a mock hub
673+
old_mock_hub = AsyncMock()
674+
675+
# simulate an old hub that can't handle the run_stored_program option
676+
old_mock_hub.fw_version = Version("3.2.0-beta.3")
677+
old_mock_hub.run = AsyncMock()
678+
old_mock_hub.connect = AsyncMock()
679+
old_mock_hub.start_user_program = AsyncMock()
680+
old_mock_hub.race_disconnect = old_mock_hub.race_power_button_press = AsyncMock(
681+
side_effect=passthrough_awaitable
682+
)
683+
684+
# create a mock questionary menu
685+
mock_selector = AsyncMock()
686+
mock_selector.ask_async.side_effect = [
687+
"Run Stored Program",
688+
"Exit",
689+
]
690+
691+
# Set up mocks using ExitStack
692+
with contextlib.ExitStack() as stack:
693+
# Create and manage temporary file
694+
695+
# Create args
696+
args = argparse.Namespace(
697+
conntype="ble",
698+
file=stack.enter_context(
699+
tempfile.NamedTemporaryFile(
700+
suffix=".py", mode="w+", delete=False, encoding="utf-8"
701+
)
702+
),
703+
name="MyHub",
704+
start=True,
705+
wait=True,
706+
stay_connected=True,
707+
)
708+
709+
stack.enter_context(patch("questionary.select", return_value=mock_selector))
710+
711+
# Run the command
712+
run_cmd = Run()
713+
await run_cmd.stay_connected_menu(old_mock_hub, args)
714+
715+
old_mock_hub.start_user_program.assert_not_called()
716+
old_mock_hub._wait_for_user_program_stop.assert_not_called()
717+
665718
@pytest.mark.asyncio
666719
async def test_stay_connected_menu_interruptions(self):
667720
"""Test the stay_connected_menu being interrupted by a power button press or hub disconnect."""
@@ -781,59 +834,6 @@ async def mock_menu_function():
781834
# this should only be called once because the menu was canceled the first two times it was called
782835
mock_hub.run.assert_called_once_with(temp_path, wait=True)
783836

784-
@pytest.mark.asyncio
785-
async def test_stay_connected_menu_run_stored(self):
786-
"""Test that the run_stored program option doesn't call an inaccessible method on an old hub."""
787-
788-
async def passthrough_awaitable(awaitable):
789-
return await awaitable
790-
791-
# Create a mock hub
792-
old_mock_hub = AsyncMock()
793-
794-
# simulate an old hub that can't handle the run_stored_program option
795-
old_mock_hub.fw_version = Version("3.2.0-beta.3")
796-
old_mock_hub.run = AsyncMock()
797-
old_mock_hub.connect = AsyncMock()
798-
old_mock_hub.start_user_program = AsyncMock()
799-
old_mock_hub.race_disconnect = old_mock_hub.race_power_button_press = AsyncMock(
800-
side_effect=passthrough_awaitable
801-
)
802-
803-
# create a mock questionary menu
804-
mock_selector = AsyncMock()
805-
mock_selector.ask_async.side_effect = [
806-
"Run Stored Program",
807-
"Exit",
808-
]
809-
810-
# Set up mocks using ExitStack
811-
with contextlib.ExitStack() as stack:
812-
# Create and manage temporary file
813-
814-
# Create args
815-
args = argparse.Namespace(
816-
conntype="ble",
817-
file=stack.enter_context(
818-
tempfile.NamedTemporaryFile(
819-
suffix=".py", mode="w+", delete=False, encoding="utf-8"
820-
)
821-
),
822-
name="MyHub",
823-
start=True,
824-
wait=True,
825-
stay_connected=True,
826-
)
827-
828-
stack.enter_context(patch("questionary.select", return_value=mock_selector))
829-
830-
# Run the command
831-
run_cmd = Run()
832-
await run_cmd.stay_connected_menu(old_mock_hub, args)
833-
834-
old_mock_hub.start_user_program.assert_not_called()
835-
old_mock_hub._wait_for_user_program_stop.assert_not_called()
836-
837837

838838
class TestCompile:
839839
"""Tests for the Compile command."""

0 commit comments

Comments
 (0)