82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
"""Unit tests for Omniverse Kit extension structure and lifecycle."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
import pytest
|
|
try:
|
|
import tomllib
|
|
except ImportError:
|
|
import tomli as tomllib
|
|
|
|
from omni.warehouse.twin.visualizer.extension import WarehouseVisualizerExtension
|
|
|
|
|
|
def test_extension_toml_metadata():
|
|
"""Verify extension.toml adheres to Omniverse Kit 110.4 schema requirements."""
|
|
toml_path = Path("omniverse/extensions/omni.warehouse.twin.visualizer/config/extension.toml").resolve()
|
|
assert toml_path.exists()
|
|
|
|
with open(toml_path, "rb") as f:
|
|
config = tomllib.load(f)
|
|
|
|
assert "package" in config
|
|
pkg = config["package"]
|
|
assert pkg["title"] == "Warehouse Robot Fleet Digital Twin Visualizer"
|
|
assert pkg["version"] == "0.7.0"
|
|
assert "python.module" in config or "python" in config
|
|
mod_name = config["python"]["module"][0]["name"] if "python" in config else config["python.module"][0]["name"]
|
|
assert mod_name == "omni.warehouse.twin.visualizer"
|
|
|
|
|
|
def test_extension_lifecycle_and_teardown(tmp_path: Path):
|
|
"""Verify extension instantiation, trajectory loading, playback controls, and safe shutdown."""
|
|
ext = WarehouseVisualizerExtension()
|
|
assert not ext.is_active
|
|
|
|
# Create dummy trajectory file
|
|
mock_traj = {
|
|
"metadata": {"simulation_duration": 60.0},
|
|
"robots": {
|
|
"amr_01": [
|
|
{"t": 0.0, "pos": [5.0, 5.0, 0.0], "yaw_deg": 0.0, "state": "IDLE"},
|
|
{"t": 60.0, "pos": [25.0, 5.0, 0.0], "yaw_deg": 0.0, "state": "LOADED_TRANSIT"},
|
|
]
|
|
},
|
|
}
|
|
traj_file = tmp_path / "test_lifecycle_traj.json"
|
|
traj_file.write_text(json.dumps(mock_traj), encoding="utf-8")
|
|
|
|
# Start up extension
|
|
ext.on_startup("omni.warehouse.twin.visualizer-0.7.0")
|
|
assert ext.is_active
|
|
|
|
# Load trajectory
|
|
loaded = ext.load_trajectory(str(traj_file))
|
|
assert loaded
|
|
assert ext._player is not None
|
|
assert ext._player.duration == 60.0
|
|
|
|
# Test playback controls
|
|
ext.play()
|
|
assert ext._player.is_playing
|
|
|
|
ext.pause()
|
|
assert not ext._player.is_playing
|
|
|
|
ext.set_speed(5.0)
|
|
assert ext._player.playback_speed == 5.0
|
|
|
|
ext.seek(30.0)
|
|
assert ext._player.current_time == 30.0
|
|
|
|
ext.reset()
|
|
assert ext._player.current_time == 0.0
|
|
|
|
# Test clean shutdown and resource teardown
|
|
ext.on_shutdown()
|
|
assert not ext.is_active
|
|
assert ext._player is None
|
|
assert ext._update_sub is None
|