Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for StartMissionDefinition #500

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, line 82 would fail, therefore it is commented out for now. It might be desired behavior, since the .id attribute will be set by the constructor.

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"))