Skip to content

Commit

Permalink
Fix lights tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 31, 2023
1 parent e38b905 commit 217bd0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ async def actor(simulator: Simulator):

_actor.mock_replies.clear()
await _actor.stop()

tasks = asyncio.all_tasks()
for task in tasks:
task.cancel()
with suppress(asyncio.CancelledError):
await task
17 changes: 10 additions & 7 deletions tests/test_command_lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,31 @@ async def test_command_lights(actor: ECPActor):
await cmd

assert cmd.status.did_succeed
assert isinstance(cmd.replies.get("lights"), dict)
assert isinstance(cmd.replies.get("lights"), str)


async def test_command_lights_one(actor: ECPActor):
cmd = await actor.invoke_mock_command("lights tr")
cmd = await actor.invoke_mock_command("lights on tr")
await cmd

assert cmd.status.did_succeed
assert cmd.replies.get("lights") == {"telescope_red": False}
assert cmd.replies.get("lights_labels") == "TELESCOPE_RED"


@pytest.mark.parametrize("action", ["on", "off", "switch"])
@pytest.mark.parametrize("action", ["on", "off", "toggle"])
@pytest.mark.parametrize("light", ["telescope_bright", "tb", "telescope bright"])
async def test_command_lights_action(actor: ECPActor, action: str, light: str):
cmd = await actor.invoke_mock_command(f'lights "{light}" {action}')
cmd = await actor.invoke_mock_command(f'lights {action} "{light}"')
await cmd

assert cmd.status.did_succeed

if action == "on" or action == "switch":
if action == "on" or action == "toggle":
result = True
else:
result = False

assert cmd.replies.get("lights") == {"telescope_bright": result}
if result:
assert cmd.replies.get("lights_labels") == "TELESCOPE_BRIGHT"
else:
assert cmd.replies.get("lights_labels") == ""

0 comments on commit 217bd0b

Please sign in to comment.