|
| 1 | +# Copyright (c) 2022-2024, The ORBIT Project Developers. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: BSD-3-Clause |
| 5 | + |
| 6 | +# ignore private usage of variables warning |
| 7 | +# pyright: reportPrivateUsage=none |
| 8 | + |
| 9 | +"""Launch Isaac Sim Simulator first.""" |
| 10 | + |
| 11 | +from omni.isaac.orbit.app import AppLauncher, run_tests |
| 12 | + |
| 13 | +# launch the simulator |
| 14 | +app_launcher = AppLauncher(headless=True) |
| 15 | +simulation_app = app_launcher.app |
| 16 | + |
| 17 | + |
| 18 | +"""Rest everything follows.""" |
| 19 | + |
| 20 | +import unittest |
| 21 | + |
| 22 | +import omni.isaac.orbit_assets as orbit_assets # noqa: F401 |
| 23 | + |
| 24 | +from omni.isaac.orbit.assets import AssetBase, AssetBaseCfg |
| 25 | +from omni.isaac.orbit.sensors import SensorBase, SensorBaseCfg |
| 26 | +from omni.isaac.orbit.sim import build_simulation_context |
| 27 | + |
| 28 | + |
| 29 | +class TestValidEntitiesConfigs(unittest.TestCase): |
| 30 | + """Test cases for all registered entities configurations.""" |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def setUpClass(cls): |
| 34 | + # load all registered entities configurations from the module |
| 35 | + cls.registered_entities: dict[str, AssetBaseCfg | SensorBaseCfg] = {} |
| 36 | + # inspect all classes from the module |
| 37 | + for obj_name in dir(orbit_assets): |
| 38 | + obj = getattr(orbit_assets, obj_name) |
| 39 | + # store all registered entities configurations |
| 40 | + if isinstance(obj, (AssetBaseCfg, SensorBaseCfg)): |
| 41 | + cls.registered_entities[obj_name] = obj |
| 42 | + # print all existing entities names |
| 43 | + print(">>> All registered entities:", list(cls.registered_entities.keys())) |
| 44 | + |
| 45 | + """ |
| 46 | + Test fixtures. |
| 47 | + """ |
| 48 | + |
| 49 | + def test_asset_configs(self): |
| 50 | + """Check all registered asset configurations.""" |
| 51 | + # iterate over all registered assets |
| 52 | + for asset_name, entity_cfg in self.registered_entities.items(): |
| 53 | + for device in ("cuda:0", "cpu"): |
| 54 | + with self.subTest(asset_name=asset_name, device=device): |
| 55 | + with build_simulation_context(device=device, auto_add_lighting=True) as sim: |
| 56 | + # print the asset name |
| 57 | + print(">>> Testing entities:", asset_name) |
| 58 | + # name the prim path |
| 59 | + entity_cfg.prim_path = "/World/asset" |
| 60 | + # create the asset / sensors |
| 61 | + entity: AssetBase | SensorBase = entity_cfg.class_type(entity_cfg) # type: ignore |
| 62 | + |
| 63 | + # play the sim |
| 64 | + sim.reset() |
| 65 | + |
| 66 | + # check asset is initialized successfully |
| 67 | + self.assertTrue(entity._is_initialized) |
| 68 | + |
| 69 | + |
| 70 | +if __name__ == "__main__": |
| 71 | + run_tests() |
0 commit comments