Unverified Commit d6702dfa authored by Kelly Guo's avatar Kelly Guo Committed by GitHub

Updates some more tests to pytest (#543)

# Description

Updates a few missing tests that are still on unittest to pytest.

## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

- Bug fix (non-breaking change which fixes an issue)


## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
parent 7ac5ad53
...@@ -5,16 +5,12 @@ ...@@ -5,16 +5,12 @@
import os import os
import subprocess import subprocess
import unittest
from pathlib import Path from pathlib import Path
import pytest
class TestDocker(unittest.TestCase):
"""Test starting and stopping of the docker container with both currently supported profiles and with and without
a suffix. This assumes that docker is installed and configured correctly so that the user can use the docker
commands from the current shell."""
def start_stop_docker(self, profile, suffix): def start_stop_docker(profile, suffix):
"""Test starting and stopping docker profile with suffix.""" """Test starting and stopping docker profile with suffix."""
environ = os.environ environ = os.environ
context_dir = Path(__file__).resolve().parent.parent context_dir = Path(__file__).resolve().parent.parent
...@@ -37,38 +33,32 @@ class TestDocker(unittest.TestCase): ...@@ -37,38 +33,32 @@ class TestDocker(unittest.TestCase):
# start the container # start the container
docker_start = subprocess.run(["python", "container.py", "start", profile] + suffix_args, **run_kwargs) docker_start = subprocess.run(["python", "container.py", "start", profile] + suffix_args, **run_kwargs)
self.assertEqual(docker_start.returncode, 0) assert docker_start.returncode == 0
# verify that the container is running # verify that the container is running
docker_running_true = subprocess.run(["docker", "ps"], **run_kwargs) docker_running_true = subprocess.run(["docker", "ps"], **run_kwargs)
self.assertEqual(docker_running_true.returncode, 0) assert docker_running_true.returncode == 0
self.assertIn(container_name, docker_running_true.stdout) assert container_name in docker_running_true.stdout
# stop the container # stop the container
docker_stop = subprocess.run(["python", "container.py", "stop", profile] + suffix_args, **run_kwargs) docker_stop = subprocess.run(["python", "container.py", "stop", profile] + suffix_args, **run_kwargs)
self.assertEqual(docker_stop.returncode, 0) assert docker_stop.returncode == 0
# verify that the container has stopped # verify that the container has stopped
docker_running_false = subprocess.run(["docker", "ps"], **run_kwargs) docker_running_false = subprocess.run(["docker", "ps"], **run_kwargs)
self.assertEqual(docker_running_false.returncode, 0) assert docker_running_false.returncode == 0
self.assertNotIn(container_name, docker_running_false.stdout) assert container_name not in docker_running_false.stdout
def test_docker_base(self):
"""Test starting and stopping docker base.""" @pytest.mark.parametrize(
self.start_stop_docker("base", "") "profile,suffix",
[
def test_docker_base_suffix(self): ("base", ""),
"""Test starting and stopping docker base with a test suffix.""" ("base", "test"),
self.start_stop_docker("base", "test") ("ros2", ""),
("ros2", "test"),
def test_docker_ros2(self): ],
"""Test starting and stopping docker ros2.""" )
self.start_stop_docker("ros2", "") def test_docker_profiles(profile, suffix):
"""Test starting and stopping docker profiles with and without suffixes."""
def test_docker_ros2_suffix(self): start_stop_docker(profile, suffix)
"""Test starting and stopping docker ros2 with a test suffix."""
self.start_stop_docker("ros2", "test")
if __name__ == "__main__":
unittest.main(verbosity=2, exit=True)
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# #
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
""" """
This script checks the functionality of scale randomization. This script checks the functionality of scale randomization.
""" """
...@@ -20,9 +21,9 @@ simulation_app = app_launcher.app ...@@ -20,9 +21,9 @@ simulation_app = app_launcher.app
"""Rest everything follows.""" """Rest everything follows."""
import torch import torch
import unittest
import omni.usd import omni.usd
import pytest
from pxr import Sdf from pxr import Sdf
import isaaclab.envs.mdp as mdp import isaaclab.envs.mdp as mdp
...@@ -278,17 +279,9 @@ class CubeEnvCfg(ManagerBasedEnvCfg): ...@@ -278,17 +279,9 @@ class CubeEnvCfg(ManagerBasedEnvCfg):
self.sim.render_interval = self.decimation self.sim.render_interval = self.decimation
class TestScaleRandomization(unittest.TestCase): @pytest.mark.parametrize("device", ["cpu", "cuda"])
"""Test for scale randomization.""" def test_scale_randomization(device):
"""
Tests
"""
def test_scale_randomization(self):
"""Test scale randomization for cube environment.""" """Test scale randomization for cube environment."""
for device in ["cpu", "cuda"]:
with self.subTest(device=device):
# create a new stage # create a new stage
omni.usd.get_context().new_stage() omni.usd.get_context().new_stage()
...@@ -306,7 +299,7 @@ class TestScaleRandomization(unittest.TestCase): ...@@ -306,7 +299,7 @@ class TestScaleRandomization(unittest.TestCase):
# test to make sure all assets in the scene are created # test to make sure all assets in the scene are created
all_prim_paths = sim_utils.find_matching_prim_paths("/World/envs/env_.*/cube.*/.*") all_prim_paths = sim_utils.find_matching_prim_paths("/World/envs/env_.*/cube.*/.*")
self.assertEqual(len(all_prim_paths), (env.num_envs * 2)) assert len(all_prim_paths) == (env.num_envs * 2)
# test to make sure randomized values are truly random # test to make sure randomized values are truly random
applied_scaling_randomization = set() applied_scaling_randomization = set()
...@@ -330,7 +323,7 @@ class TestScaleRandomization(unittest.TestCase): ...@@ -330,7 +323,7 @@ class TestScaleRandomization(unittest.TestCase):
for i in range(3): for i in range(3):
prim_spec = Sdf.CreatePrimInLayer(stage.GetRootLayer(), prim_paths[i]) prim_spec = Sdf.CreatePrimInLayer(stage.GetRootLayer(), prim_paths[i])
scale_spec = prim_spec.GetAttributeAtPath(prim_paths[i] + ".xformOp:scale") scale_spec = prim_spec.GetAttributeAtPath(prim_paths[i] + ".xformOp:scale")
self.assertEqual(tuple(scale_spec.default), (1.0, 1.0, 1.0)) assert tuple(scale_spec.default) == (1.0, 1.0, 1.0)
# simulate physics # simulate physics
with torch.inference_mode(): with torch.inference_mode():
...@@ -343,7 +336,8 @@ class TestScaleRandomization(unittest.TestCase): ...@@ -343,7 +336,8 @@ class TestScaleRandomization(unittest.TestCase):
env.close() env.close()
def test_scale_randomization_failure_replicate_physics(self):
def test_scale_randomization_failure_replicate_physics():
"""Test scale randomization failure when replicate physics is set to True.""" """Test scale randomization failure when replicate physics is set to True."""
# create a new stage # create a new stage
omni.usd.get_context().new_stage() omni.usd.get_context().new_stage()
...@@ -352,6 +346,6 @@ class TestScaleRandomization(unittest.TestCase): ...@@ -352,6 +346,6 @@ class TestScaleRandomization(unittest.TestCase):
cfg_failure.scene.replicate_physics = True cfg_failure.scene.replicate_physics = True
# run the test # run the test
with self.assertRaises(RuntimeError): with pytest.raises(RuntimeError):
env = ManagerBasedEnv(cfg_failure) env = ManagerBasedEnv(cfg_failure)
env.close() env.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment