Skip to content

Commit

Permalink
Add test for StartMissionDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
tsundvoll committed Nov 8, 2023
1 parent e03f14b commit 5dad445
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
40 changes: 40 additions & 0 deletions tests/isar/models/example_mission_definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"tasks": [
{
"pose": {
"position": {
"x": 0,
"y": 0,
"z": 0,
"frame_name": "robot"
},
"orientation": {
"x": 0,
"y": 0,
"z": 0,
"w": 0,
"frame_name": "robot"
},
"frame_name": "robot"
},
"inspections": [
{
"type": "Image",
"inspection_target": {
"x": 0,
"y": 0,
"z": 0,
"frame_name": "robot"
},
"duration": 0,
"metadata": {},
"id": "generated_inspection_id"
}
],
"tag": "MY-TAG-123",
"id": "generated_task_id"
}
],
"id": "generated_mission_id",
"name": "my-mission"
}
43 changes: 42 additions & 1 deletion tests/isar/models/test_start_mission_definition.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import json
import os
from typing import List, Union

import pytest
from alitra import Frame, Orientation, Pose, Position

from isar.apis.models.start_mission_definition import get_duplicate_ids
from isar.apis.models.start_mission_definition import (
StartMissionDefinition,
get_duplicate_ids,
to_isar_mission,
)
from robot_interface.models.mission.mission import Mission
from robot_interface.models.mission.step import STEPS, Step
from robot_interface.models.mission.task import Task

Expand Down Expand Up @@ -51,3 +59,36 @@ def test_duplicate_id_check(
duplicates: List[str] = get_duplicate_ids(item_list)
has_duplicates: bool = len(duplicates) > 0
assert has_duplicates == expected_boolean


def test_mission_definition_to_isar_mission():
dirname = os.path.dirname(__file__)
filepath = os.path.join(dirname, "example_mission_definition.json")

with open(filepath) as f:
datax = json.load(f)
mission_definition = StartMissionDefinition(**datax)

generated_mission: Mission = to_isar_mission(mission_definition)
assert generated_mission.id == "generated_mission_id"
assert generated_mission.name == "my-mission"
assert len(generated_mission.tasks) == 1

task = generated_mission.tasks[0]
assert task.id == "generated_task_id"
assert task.tag_id == "MY-TAG-123"

first_step = task.steps[0]
# assert first_step.id == "generated_inspection_id"
assert first_step.type == "drive_to_pose"
assert first_step.pose == Pose(
position=Position(0.0, 0.0, 0.0, frame=Frame("robot")),
orientation=Orientation(0.0, 0.0, 0.0, 0.0, frame=Frame("robot")),
frame=Frame("robot"),
)

second_step = task.steps[1]
# assert second_step.id == "generated_inspection_id"
assert second_step.type == "take_image"
assert second_step.tag_id == "MY-TAG-123"
assert second_step.target == Position(0.0, 0.0, 0.0, frame=Frame("robot"))

0 comments on commit 5dad445

Please sign in to comment.