forked from isaac-sim/IsaacLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_installed_workflow_entrypoints.py
More file actions
89 lines (66 loc) · 3.16 KB
/
Copy pathtest_installed_workflow_entrypoints.py
File metadata and controls
89 lines (66 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
"""Tests for workflow commands exposed by an installed ``isaaclab`` package."""
from __future__ import annotations
import sys
from unittest import mock
import pytest
import isaaclab
import isaaclab.__main__ as package_main
import isaaclab.cli as cli
import isaaclab.paths as paths
pytestmark = pytest.mark.unit
def test_resolves_partial_source_checkout_root(tmp_path):
"""Source root resolution must not require resources copied by later Docker layers."""
package_root = tmp_path / "source" / "isaaclab" / "isaaclab"
package_root.mkdir(parents=True)
with mock.patch.object(paths, "__file__", str(package_root / "paths.py")):
assert paths._resolve_isaaclab_root() == tmp_path
def test_top_level_compatibility_api_is_preserved():
"""The flattened package must retain the aggregate wheel's public shims."""
assert callable(isaaclab.bootstrap_kernel)
with mock.patch.object(package_main, "main", return_value=0) as main, pytest.raises(SystemExit, match="0"):
isaaclab.main()
main.assert_called_once_with()
def test_legacy_vscode_option_uses_compatibility_dispatcher():
"""The installed entry point must continue to recognize the legacy VS Code option."""
with (
mock.patch.object(sys, "argv", ["isaaclab", "--generate-vscode-settings"]),
mock.patch.object(package_main, "generate_vscode_settings") as generate,
):
package_main.main()
generate.assert_called_once_with()
@pytest.mark.parametrize(
("command", "runner"),
[
(cli.train, "run_train_cli"),
(cli.play, "run_play_cli"),
(cli.train_multigpu, "run_train_multigpu_cli"),
(cli.zero_agent, "run_zero_agent_cli"),
(cli.random_agent, "run_random_agent_cli"),
],
)
def test_workflow_commands_dispatch_to_installed_entrypoints(command, runner):
"""Workflow commands must not depend on scripts from a source checkout."""
args = ["--task", "Example"]
with mock.patch(f"isaaclab_rl.entrypoints.{runner}", return_value=0) as run:
command(args)
run.assert_called_once_with(args)
def test_workflow_command_propagates_failure_status():
"""A nonzero in-process result must remain the console command's exit status."""
with mock.patch("isaaclab_rl.entrypoints.run_train_cli", return_value=2), pytest.raises(SystemExit, match="2"):
cli.train([])
def test_cli_loads_downstream_tasks_before_benchmark():
"""Benchmarking must discover tasks from installed projects."""
task_entry_point = mock.Mock()
with (
mock.patch.object(cli.importlib.metadata, "entry_points", return_value=[task_entry_point]) as entry_points,
mock.patch.object(cli, "benchmark") as benchmark,
mock.patch.object(sys, "argv", ["isaaclab", "benchmark", "runtime", "--task", "Example"]),
):
cli.cli()
entry_points.assert_called_once_with(group="isaaclab.tasks")
task_entry_point.load.assert_called_once_with()
benchmark.assert_called_once_with(["runtime", "--task", "Example"])