Skip to content

Commit

Permalink
Instantiate MockStep members by function
Browse files Browse the repository at this point in the history
Format files
  • Loading branch information
sondreo committed Feb 27, 2024
1 parent 0fd49e5 commit 74aae96
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tests/isar/services/readers/test_base_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class TestBaseReader:
"dataclass_dict, expected_dataclass",
[
(asdict(MockMissionDefinition.default_mission), Mission),
(asdict(MockStep.drive_to), Step),
(asdict(MockStep.take_image_in_coordinate_direction), Step),
(asdict(MockStep.drive_to()), Step),
(asdict(MockStep.take_image_in_coordinate_direction()), Step),
(asdict(MockPose.default_pose), Pose),
],
)
Expand Down
4 changes: 2 additions & 2 deletions tests/isar/state_machine/states/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
)
def test_step_finished(monitor: Monitor, mock_status, expected_output):
step: Step = MockStep.drive_to
step: Step = MockStep.drive_to()
step.status = mock_status
step_completed: bool = monitor._step_finished(
step=step,
Expand All @@ -36,7 +36,7 @@ def test_step_finished(monitor: Monitor, mock_status, expected_output):
def test_should_only_upload_if_status_is_completed(
monitor: Monitor, mock_status, should_queue_upload
):
step: TakeImage = MockStep.take_image_in_coordinate_direction
step: TakeImage = MockStep.take_image_in_coordinate_direction()
step.status = mock_status
task: Task = Task(steps=[step])
mission: Mission = Mission(tasks=[task])
Expand Down
10 changes: 5 additions & 5 deletions tests/isar/state_machine/test_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_state_machine_failed_dependency(
injector, state_machine_thread, mocker
) -> None:
drive_to_step: Step = DriveToPose(pose=MockPose.default_pose)
inspection_step: Step = MockStep.take_image_in_coordinate_direction
inspection_step: Step = MockStep.take_image_in_coordinate_direction()
mission: Mission = Mission(tasks=[Task(steps=[drive_to_step, inspection_step])]) # type: ignore

mocker.patch.object(MockRobot, "step_status", return_value=StepStatus.Failed)
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_state_machine_with_successful_collection(
) -> None:
storage_mock: StorageInterface = injector.get(List[StorageInterface])[0]

step: TakeImage = MockStep.take_image_in_coordinate_direction
step: TakeImage = MockStep.take_image_in_coordinate_direction()
mission: Mission = Mission(tasks=[Task(steps=[step])])
scheduling_utilities: SchedulingUtilities = injector.get(SchedulingUtilities)

Expand Down Expand Up @@ -207,7 +207,7 @@ def test_state_machine_with_unsuccessful_collection(

mocker.patch.object(MockRobot, "get_inspections", return_value=[])

step: TakeImage = MockStep.take_image_in_coordinate_direction
step: TakeImage = MockStep.take_image_in_coordinate_direction()
mission: Mission = Mission(tasks=[Task(steps=[step])])
scheduling_utilities: SchedulingUtilities = injector.get(SchedulingUtilities)

Expand Down Expand Up @@ -236,7 +236,7 @@ def test_state_machine_with_successful_mission_stop(
state_machine_thread: StateMachineThread,
caplog: pytest.LogCaptureFixture,
) -> None:
step: TakeImage = MockStep.take_image_in_coordinate_direction
step: TakeImage = MockStep.take_image_in_coordinate_direction()
mission: Mission = Mission(tasks=[Task(steps=[step])])

scheduling_utilities: SchedulingUtilities = injector.get(SchedulingUtilities)
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_state_machine_with_unsuccessful_mission_stop(
state_machine_thread: StateMachineThread,
caplog: pytest.LogCaptureFixture,
) -> None:
step: TakeImage = MockStep.take_image_in_coordinate_direction
step: TakeImage = MockStep.take_image_in_coordinate_direction()
mission: Mission = Mission(tasks=[Task(steps=[step])])

scheduling_utilities: SchedulingUtilities = injector.get(SchedulingUtilities)
Expand Down
9 changes: 6 additions & 3 deletions tests/mocks/mission_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ class MockMissionDefinition:
id="default_mission",
tasks=[
Task(
steps=[MockStep.take_image_in_coordinate_direction, MockStep.drive_to]
steps=[
MockStep.take_image_in_coordinate_direction(),
MockStep.drive_to(),
]
),
Task(
steps=[
MockStep.take_image_in_coordinate_direction,
MockStep.take_image_in_coordinate_direction,
MockStep.take_image_in_coordinate_direction(),
MockStep.take_image_in_coordinate_direction(),
]
),
],
Expand Down
9 changes: 5 additions & 4 deletions tests/mocks/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


class MockStep:
drive_to = DriveToPose(pose=MockPose.default_pose)
take_image_in_coordinate_direction = TakeImage(
target=Position(x=1, y=1, z=1, frame=Frame("robot"))
)
def drive_to() -> DriveToPose:
return DriveToPose(pose=MockPose.default_pose)

def take_image_in_coordinate_direction() -> TakeImage:
return TakeImage(target=Position(x=1, y=1, z=1, frame=Frame("robot")))

0 comments on commit 74aae96

Please sign in to comment.