"""Headless smoke test for the canonical master MuJoCo model.

This file used to launch an interactive viewer at import time, which made test
discovery block or fail depending on the current working directory.
"""

from __future__ import annotations

import unittest
from pathlib import Path

import mujoco


CONFIG_ROOT = Path(__file__).resolve().parents[1] / "config"
MASTER_MJCF = CONFIG_ROOT / "master_7dof.mjcf"
MASTER_JOINT_NAMES = (
    "master_shoulder_pitch_joint",
    "master_shoulder_yaw_joint",
    "master_shoulder_roll_joint",
    "master_elbow_flex_joint",
    "master_wrist_roll_joint",
    "master_wrist_yaw_joint",
    "master_wrist_pitch_joint",
)


class MasterMujocoModelTest(unittest.TestCase):
    def test_canonical_model_loads_headlessly(self) -> None:
        model = mujoco.MjModel.from_xml_path(str(MASTER_MJCF))
        self.assertEqual(model.nq, 7)
        self.assertEqual(model.nv, 7)
        for name in MASTER_JOINT_NAMES:
            joint_id = mujoco.mj_name2id(
                model,
                mujoco.mjtObj.mjOBJ_JOINT,
                name,
            )
            self.assertGreaterEqual(joint_id, 0, name)


if __name__ == "__main__":
    unittest.main()
