| |
| |
| |
| |
|
|
| """ |
| This test has a lot of duplication with ``test_build_simulation_context_nonheadless.py``. |
| |
| This is intentional to ensure that the tests are run in both headless and non-headless modes, |
| and we currently can't re-build the simulation app in a script. |
| |
| If you need to make a change to this test, please make sure to also make the same change to |
| ``test_build_simulation_context_nonheadless.py``. |
| """ |
|
|
| """Launch Isaac Sim Simulator first.""" |
|
|
| from isaaclab.app import AppLauncher |
|
|
| |
| simulation_app = AppLauncher(headless=True).app |
|
|
| """Rest everything follows.""" |
|
|
| import pytest |
|
|
| from isaaclab.sim.simulation_cfg import SimulationCfg |
| from isaaclab.sim.simulation_context import build_simulation_context |
|
|
|
|
| @pytest.mark.parametrize("gravity_enabled", [True, False]) |
| @pytest.mark.parametrize("device", ["cuda:0", "cpu"]) |
| @pytest.mark.parametrize("dt", [0.01, 0.1]) |
| @pytest.mark.isaacsim_ci |
| def test_build_simulation_context_no_cfg(gravity_enabled, device, dt): |
| """Test that the simulation context is built when no simulation cfg is passed in.""" |
| with build_simulation_context(gravity_enabled=gravity_enabled, device=device, dt=dt) as sim: |
| if gravity_enabled: |
| assert sim.cfg.gravity == (0.0, 0.0, -9.81) |
| else: |
| assert sim.cfg.gravity == (0.0, 0.0, 0.0) |
|
|
| assert sim.cfg.device == device |
| assert sim.cfg.dt == dt |
|
|
| |
| assert not sim.stage.GetPrimAtPath("/World/defaultDomeLight").IsValid() |
|
|
|
|
| @pytest.mark.parametrize("add_ground_plane", [True, False]) |
| @pytest.mark.isaacsim_ci |
| def test_build_simulation_context_ground_plane(add_ground_plane): |
| """Test that the simulation context is built with the correct ground plane.""" |
| with build_simulation_context(add_ground_plane=add_ground_plane) as sim: |
| |
| if add_ground_plane: |
| assert sim.stage.GetPrimAtPath("/World/defaultGroundPlane").IsValid() |
| else: |
| assert not sim.stage.GetPrimAtPath("/World/defaultGroundPlane").IsValid() |
|
|
|
|
| @pytest.mark.parametrize("add_lighting", [True, False]) |
| @pytest.mark.parametrize("auto_add_lighting", [True, False]) |
| @pytest.mark.isaacsim_ci |
| def test_build_simulation_context_auto_add_lighting(add_lighting, auto_add_lighting): |
| """Test that the simulation context is built with the correct lighting.""" |
| with build_simulation_context(add_lighting=add_lighting, auto_add_lighting=auto_add_lighting) as sim: |
| if add_lighting: |
| |
| assert sim.stage.GetPrimAtPath("/World/defaultDomeLight").IsValid() |
| else: |
| |
| assert not sim.stage.GetPrimAtPath("/World/defaultDomeLight").IsValid() |
|
|
|
|
| @pytest.mark.isaacsim_ci |
| def test_build_simulation_context_cfg(): |
| """Test that the simulation context is built with the correct cfg and values don't get overridden.""" |
| dt = 0.001 |
| |
| gravity = (0.0, 0.0, -1.81) |
| device = "cuda:0" |
|
|
| cfg = SimulationCfg( |
| gravity=gravity, |
| device=device, |
| dt=dt, |
| ) |
|
|
| with build_simulation_context(sim_cfg=cfg, gravity_enabled=False, dt=0.01, device="cpu") as sim: |
| assert sim.cfg.gravity == gravity |
| assert sim.cfg.device == device |
| assert sim.cfg.dt == dt |
|
|