|
13 | 13 | # limitations under the License. |
14 | 14 | """Test for envpool.make.""" |
15 | 15 |
|
| 16 | +import configparser |
16 | 17 | import gc |
17 | 18 | import os |
18 | 19 | import pprint |
|
22 | 23 | from contextlib import contextmanager |
23 | 24 | from pathlib import Path |
24 | 25 | from typing import Callable, get_type_hints |
| 26 | +from unittest import mock |
25 | 27 |
|
26 | 28 | import dm_env |
27 | 29 | import gymnasium |
|
60 | 62 | "img_height": 240, |
61 | 63 | } |
62 | 64 |
|
| 65 | +_FAMILY_SMOKE_TASKS: dict[str, tuple[str, ...]] = { |
| 66 | + "envpool.atari": ("Defender-v5",), |
| 67 | + "envpool.box2d": ("LunarLander-v3",), |
| 68 | + "envpool.classic_control": ("CartPole-v1",), |
| 69 | + "envpool.gfootball": ("gfootball/academy_empty_goal_close-v1",), |
| 70 | + "envpool.highway": ("HighwayFast-v0",), |
| 71 | + "envpool.jumanji": ("Game2048-v1",), |
| 72 | + "envpool.minigrid": ("MiniGrid-DoorKey-8x8-v0",), |
| 73 | + "envpool.mujoco.dmc": ("WalkerWalk-v1",), |
| 74 | + "envpool.mujoco.gym": ("Ant-v5",), |
| 75 | + "envpool.mujoco.metaworld": ("MetaWorld/Reach-v3",), |
| 76 | + "envpool.mujoco.playground": ( |
| 77 | + "Go1JoystickFlatTerrain-v1", |
| 78 | + "G1JoystickFlatTerrain-v1", |
| 79 | + ), |
| 80 | + "envpool.mujoco.robotics": ("FetchReach-v4",), |
| 81 | + "envpool.pgx": ("TicTacToe-v1",), |
| 82 | + "envpool.procgen": ("CoinrunEasy-v0",), |
| 83 | + "envpool.toy_text": ("Catch-v0",), |
| 84 | + "envpool.vizdoom": ("MyWayHome-v1",), |
| 85 | +} |
| 86 | + |
| 87 | +_DYNAMIC_FAMILY_SMOKE_PREFIXES: dict[str, str] = { |
| 88 | + "envpool.mujoco.myosuite": "MyoSuite/", |
| 89 | +} |
| 90 | + |
63 | 91 |
|
64 | 92 | @contextmanager |
65 | 93 | def _temporary_workdir(prefix: str) -> Iterator[str]: |
@@ -89,6 +117,23 @@ def _stable_render_kwargs(task_id: str, **kwargs: object) -> dict[str, object]: |
89 | 117 |
|
90 | 118 |
|
91 | 119 | class _MakeTest(absltest.TestCase): |
| 120 | + def _family_smoke_tasks(self) -> dict[str, tuple[str, ...]]: |
| 121 | + from envpool.registration import registry |
| 122 | + |
| 123 | + tasks = dict(_FAMILY_SMOKE_TASKS) |
| 124 | + for import_path, prefix in _DYNAMIC_FAMILY_SMOKE_PREFIXES.items(): |
| 125 | + candidates = sorted( |
| 126 | + task_id |
| 127 | + for task_id, (registered_import_path, _, _) in ( |
| 128 | + registry.specs.items() |
| 129 | + ) |
| 130 | + if registered_import_path == import_path |
| 131 | + and task_id.startswith(prefix) |
| 132 | + ) |
| 133 | + self.assertNotEmpty(candidates, import_path) |
| 134 | + tasks[import_path] = (candidates[0],) |
| 135 | + return tasks |
| 136 | + |
92 | 137 | def check_render_unsupported(self, task_id: str, **kwargs: object) -> None: |
93 | 138 | for factory in (envpool.make_gym, envpool.make_gymnasium): |
94 | 139 | with self.assertRaisesRegex(RuntimeError, "render not implemented"): |
@@ -131,7 +176,19 @@ def render_once(factory: _RenderFactory) -> None: |
131 | 176 | raise |
132 | 177 |
|
133 | 178 | def test_version(self) -> None: |
134 | | - print(envpool.__version__) |
| 179 | + config = configparser.ConfigParser() |
| 180 | + self.assertTrue(config.read(Path(__file__).parents[1] / "setup.cfg")) |
| 181 | + self.assertEqual(config["metadata"]["version"], envpool.__version__) |
| 182 | + |
| 183 | + def test_asset_base_path_env_override(self) -> None: |
| 184 | + from envpool.registration import asset_base_path |
| 185 | + |
| 186 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 187 | + with mock.patch.dict(os.environ, {"ENVPOOL_ASSETS_PATH": tmpdir}): |
| 188 | + self.assertEqual( |
| 189 | + asset_base_path("envpool_assets", "atari/roms"), |
| 190 | + os.path.abspath(tmpdir), |
| 191 | + ) |
135 | 192 |
|
136 | 193 | def test_public_typing_interface(self) -> None: |
137 | 194 | self.assertTrue(Path(envpool.__file__).with_name("py.typed").is_file()) |
@@ -162,6 +219,26 @@ def test_public_typing_interface(self) -> None: |
162 | 219 | def test_list_all_envs(self) -> None: |
163 | 220 | pprint.pprint(envpool.list_all_envs()) |
164 | 221 |
|
| 222 | + def test_make_registered_env_families(self) -> None: |
| 223 | + from envpool.registration import registry |
| 224 | + |
| 225 | + registered_import_paths = { |
| 226 | + import_path for import_path, _, _ in registry.specs.values() |
| 227 | + } |
| 228 | + smoke_tasks = self._family_smoke_tasks() |
| 229 | + self.assertEmpty(registered_import_paths - smoke_tasks.keys()) |
| 230 | + self.assertEmpty(smoke_tasks.keys() - registered_import_paths) |
| 231 | + missing_task_ids = [ |
| 232 | + task_id |
| 233 | + for task_ids in smoke_tasks.values() |
| 234 | + for task_id in task_ids |
| 235 | + if task_id not in registry.specs |
| 236 | + ] |
| 237 | + self.assertEmpty(missing_task_ids) |
| 238 | + for import_path, task_ids in smoke_tasks.items(): |
| 239 | + with self.subTest(import_path=import_path): |
| 240 | + self.check_step(list(task_ids)) |
| 241 | + |
165 | 242 | def test_make_atari(self) -> None: |
166 | 243 | self.assertRaises(TypeError, envpool.make, "Pong-v5") |
167 | 244 | spec = envpool.make_spec("Defender-v5") |
@@ -419,6 +496,11 @@ def test_make_mujoco_dmc(self) -> None: |
419 | 496 | "WalkerWalk-v1", |
420 | 497 | ]) |
421 | 498 |
|
| 499 | + def test_make_mujoco_playground(self) -> None: |
| 500 | + self.check_step([ |
| 501 | + "Go1JoystickFlatTerrain-v1", |
| 502 | + ]) |
| 503 | + |
422 | 504 | def test_render_smoke(self) -> None: |
423 | 505 | self.check_render("CartPole-v1") |
424 | 506 | self.check_render("LunarLander-v3") |
|
0 commit comments