108 lines
3.3 KiB
Python
108 lines
3.3 KiB
Python
"""Installed origin, bootstrap and explicit override regression checks."""
|
|
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from universal_humanoid import backend
|
|
from universal_humanoid.inspection import asset_inventory
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def test_backend_shadowing_is_rejected(monkeypatch):
|
|
monkeypatch.setattr(
|
|
backend.importlib.util,
|
|
"find_spec",
|
|
lambda name: SimpleNamespace(origin=f"/tmp/wrong/{name}/__init__.py"),
|
|
)
|
|
with pytest.raises(RuntimeError, match="shadowing"):
|
|
backend.require_vendored()
|
|
|
|
|
|
def test_installed_imports_work_outside_repository(tmp_path):
|
|
env = os.environ.copy()
|
|
env.pop("PYTHONPATH", None)
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-c",
|
|
"import json; from universal_humanoid.backend import require_vendored; "
|
|
"print(json.dumps(require_vendored()))",
|
|
],
|
|
cwd=tmp_path,
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
origins = json.loads(result.stdout)
|
|
assert all(row["matches"] for row in origins.values())
|
|
|
|
|
|
def test_external_assets_have_no_default_home_scan(tmp_path, monkeypatch):
|
|
for name in ("BOOSTER_ASSETS_ROOT", "UNITREE_ROBOTS_ROOT"):
|
|
monkeypatch.delenv(name, raising=False)
|
|
assert asset_inventory() == []
|
|
model = tmp_path / "g1_description/g1_29dof.xml"
|
|
model.parent.mkdir()
|
|
model.write_text("<mujoco/>")
|
|
monkeypatch.setenv("UNITREE_ROBOTS_ROOT", str(tmp_path))
|
|
assert asset_inventory()[0]["path"] == str(model)
|
|
|
|
|
|
def test_bootstrap_detector_needs_only_stdlib(tmp_path):
|
|
output = tmp_path / "host.json"
|
|
subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-I",
|
|
str(ROOT / ".agents/skills/setup-env/scripts/detect.py"),
|
|
"--output",
|
|
str(output),
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
assert json.loads(output.read_text())["python"]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"variable,value,fragment",
|
|
[
|
|
("UH_PYTHON", "/nonexistent/python", "Invalid Python"),
|
|
("MJLAB_ROOT", "/not/a/backend", "no longer supported"),
|
|
],
|
|
)
|
|
def test_launcher_rejects_bad_explicit_overrides(variable, value, fragment):
|
|
env = os.environ.copy()
|
|
for key in ("UH_PYTHON", "MJLAB_ROOT", "UH_EXTRA_PYTHONPATH"):
|
|
env.pop(key, None)
|
|
env[variable] = value
|
|
result = subprocess.run(
|
|
[str(ROOT / "scripts/uh"), "list"], env=env, capture_output=True, text=True
|
|
)
|
|
assert result.returncode != 0 and fragment in result.stderr
|
|
|
|
|
|
def test_t1_bundled_asset_and_bad_override(monkeypatch, tmp_path):
|
|
pytest.importorskip("mujoco")
|
|
pytest.importorskip("mjlab")
|
|
from mjlab.asset_zoo.robots.booster_t1.t1_constants import get_spec, get_t1_xml
|
|
|
|
monkeypatch.delenv("BOOSTER_ASSETS_ROOT", raising=False)
|
|
assert get_t1_xml().is_relative_to(ROOT / "rl")
|
|
model = get_spec().compile()
|
|
assert model.nv == 29 # free root + 23 joints
|
|
assert model.site("left_foot").id >= 0
|
|
assert model.sensor("imu_ang_vel").id >= 0
|
|
monkeypatch.setenv("BOOSTER_ASSETS_ROOT", str(tmp_path))
|
|
with pytest.raises(FileNotFoundError, match="T1 asset not found"):
|
|
get_spec()
|