mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-20 11:09:59 +00:00
feat(dependencies): minimal default tag install (#3362)
This commit is contained in:
+37
-35
@@ -13,48 +13,50 @@
|
||||
# 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.
|
||||
import importlib
|
||||
|
||||
import gymnasium as gym
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import lerobot
|
||||
from lerobot.policies.act.modeling_act import ACTPolicy
|
||||
from lerobot.policies.diffusion.modeling_diffusion import DiffusionPolicy
|
||||
from lerobot.policies.tdmpc.modeling_tdmpc import TDMPCPolicy
|
||||
from lerobot.policies.vqbet.modeling_vqbet import VQBeTPolicy
|
||||
from tests.utils import require_env
|
||||
from lerobot.utils.import_utils import _require_package_cache, require_package
|
||||
|
||||
|
||||
@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
|
||||
`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_version():
|
||||
"""Verify the package exposes a version string."""
|
||||
assert isinstance(lerobot.__version__, str)
|
||||
assert len(lerobot.__version__) > 0
|
||||
|
||||
|
||||
def test_available_policies():
|
||||
"""
|
||||
This test verifies that the class attribute `name` for all policies is
|
||||
consistent with those listed in `lerobot/__init__.py`.
|
||||
"""
|
||||
policy_classes = [ACTPolicy, DiffusionPolicy, TDMPCPolicy, VQBeTPolicy]
|
||||
policies = [pol_cls.name for pol_cls in policy_classes]
|
||||
assert set(policies) == set(lerobot.available_policies), policies
|
||||
def test_require_package_raises_when_missing():
|
||||
"""require_package raises ImportError with install instructions when a package is missing."""
|
||||
with patch("lerobot.utils.import_utils.is_package_available", return_value=False):
|
||||
# Clear the cache so the mock takes effect
|
||||
_require_package_cache.clear()
|
||||
try:
|
||||
with pytest.raises(ImportError, match=r"pip install 'lerobot\[dataset\]'"):
|
||||
require_package("datasets", extra="dataset")
|
||||
finally:
|
||||
_require_package_cache.clear()
|
||||
|
||||
|
||||
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)
|
||||
def test_require_package_passes_when_available():
|
||||
"""require_package does not raise when the package is installed."""
|
||||
with patch("lerobot.utils.import_utils.is_package_available", return_value=True):
|
||||
_require_package_cache.clear()
|
||||
try:
|
||||
# Should not raise
|
||||
require_package("datasets", extra="dataset")
|
||||
finally:
|
||||
_require_package_cache.clear()
|
||||
|
||||
|
||||
def test_require_package_error_message_includes_uv():
|
||||
"""Error message includes both pip and uv install commands."""
|
||||
with patch("lerobot.utils.import_utils.is_package_available", return_value=False):
|
||||
_require_package_cache.clear()
|
||||
try:
|
||||
with pytest.raises(ImportError, match=r"uv pip install"):
|
||||
require_package("grpcio", extra="async", import_name="grpc")
|
||||
finally:
|
||||
_require_package_cache.clear()
|
||||
|
||||
Reference in New Issue
Block a user