lerobot/tests/test_available.py

66 lines
2.3 KiB
Python
Raw Normal View History

2024-05-15 18:13:09 +08:00
#!/usr/bin/env python
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2024-04-10 21:06:48 +08:00
import importlib
2024-04-18 20:47:42 +08:00
2024-04-10 21:06:48 +08:00
import gymnasium as gym
2024-04-18 20:47:42 +08:00
import pytest
2024-04-18 20:47:42 +08:00
import lerobot
from lerobot.common.policies.act.modeling_act import ACTPolicy
2024-04-16 02:06:44 +08:00
from lerobot.common.policies.diffusion.modeling_diffusion import DiffusionPolicy
from lerobot.common.policies.tdmpc.modeling_tdmpc import TDMPCPolicy
2024-06-26 15:55:02 +08:00
from lerobot.common.policies.vqbet.modeling_vqbet import VQBeTPolicy
2024-04-18 20:47:42 +08:00
from tests.utils import require_env
@pytest.mark.parametrize("env_name, task_name", lerobot.env_task_pairs)
@require_env
def test_available_env_task(env_name: str, task_name: list):
"""
This test verifies that all environments listed in `lerobot/__init__.py` can
be successfully imported if they're installed — and that their
2024-04-18 20:47:42 +08:00
`available_tasks_per_env` are valid.
"""
package_name = f"gym_{env_name}"
importlib.import_module(package_name)
gym_handle = f"{package_name}/{task_name}"
assert gym_handle in gym.envs.registry, gym_handle
def test_available_policies():
"""
This test verifies that the class attribute `name` for all policies is
consistent with those listed in `lerobot/__init__.py`.
"""
2024-04-10 21:06:48 +08:00
policy_classes = [
ACTPolicy,
2024-04-10 21:06:48 +08:00
DiffusionPolicy,
TDMPCPolicy,
2024-06-26 15:55:02 +08:00
VQBeTPolicy,
2024-04-10 21:06:48 +08:00
]
policies = [pol_cls.name for pol_cls in policy_classes]
assert set(policies) == set(lerobot.available_policies), policies
def test_print():
print(lerobot.available_envs)
print(lerobot.available_tasks_per_env)
print(lerobot.available_datasets)
print(lerobot.available_datasets_per_env)
print(lerobot.available_real_world_datasets)
print(lerobot.available_policies)
print(lerobot.available_policies_per_env)