Skip to content

Commit

Permalink
Add load model config
Browse files Browse the repository at this point in the history
  • Loading branch information
oysand committed Feb 1, 2022
1 parent a2705a4 commit 8aafadc
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
"Topic :: Software Development :: Libraries",
],
include_package_data=True,
install_requires=["scipy", "numpy"],
install_requires=["scipy", "numpy", "dacite"],
python_requires=">=3.8",
tests_require=["pytest"],
extras_require={
"dev": [
"pytest",
"black",
]
},
)
14 changes: 14 additions & 0 deletions src/alitra/models/map_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import json
from dataclasses import dataclass
from pathlib import Path

from dacite import from_dict

from alitra.frame_dataclasses import PointList

Expand All @@ -8,3 +12,13 @@ class MapConfig:
map_name: str
robot_reference_points: PointList
asset_reference_points: PointList


def load_map_config(map_config_path: Path) -> MapConfig:
with open(map_config_path) as json_file:
map_config_dict = json.load(json_file)

return from_dict(
data_class=MapConfig,
data=map_config_dict,
)
38 changes: 38 additions & 0 deletions tests/models/test_map_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

import pytest

from alitra.frame_dataclasses import Point, PointList
from alitra.models.map_config import MapConfig, load_map_config

expected_map_config = MapConfig(
map_name="test_map",
robot_reference_points=PointList(
points=[
Point(x=10, y=20, z=30, frame="robot"),
Point(x=40, y=50, z=60, frame="robot"),
Point(x=70, y=80, z=90, frame="robot"),
],
frame="robot",
),
asset_reference_points=PointList(
points=[
Point(x=11, y=21, z=31, frame="asset"),
Point(x=41, y=51, z=61, frame="asset"),
Point(x=71, y=81, z=91, frame="asset"),
],
frame="asset",
),
)


def test_load_map_config():
map_config_path = Path("./tests/test_data/test_map_config/test_map_config.json")
map_config: MapConfig = load_map_config(map_config_path)
assert map_config == expected_map_config


def test_invalid_file_path():
map_config_path = Path("./tests/test_data/test_map_config/no_file.json")
with pytest.raises(Exception):
load_map_config(map_config_path)
49 changes: 49 additions & 0 deletions tests/test_data/test_map_config/test_map_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"map_name": "test_map",
"robot_reference_points": {
"points": [
{
"x": 10,
"y": 20,
"z": 30,
"frame": "robot"
},
{
"x": 40,
"y": 50,
"z": 60,
"frame": "robot"
},
{
"x": 70,
"y": 80,
"z": 90,
"frame": "robot"
}
],
"frame": "robot"
},
"asset_reference_points": {
"points": [
{
"x": 11,
"y": 21,
"z": 31,
"frame": "asset"
},
{
"x": 41,
"y": 51,
"z": 61,
"frame": "asset"
},
{
"x": 71,
"y": 81,
"z": 91,
"frame": "asset"
}
],
"frame": "asset"
}
}

0 comments on commit 8aafadc

Please sign in to comment.