|
1 | 1 | import os |
2 | 2 | import sys |
3 | 3 | import unittest |
| 4 | +import warnings |
4 | 5 |
|
5 | 6 | from skrobot.data import fetch_urdfpath |
| 7 | +from skrobot.data import panda_urdfpath |
| 8 | +from skrobot.model import RobotModel |
| 9 | +from skrobot.models import Fetch |
| 10 | +from skrobot.models import Panda |
6 | 11 | from skrobot.models.urdf import RobotModelFromURDF |
7 | 12 | from skrobot.utils.urdf import mesh_simplify_factor |
8 | 13 |
|
@@ -32,3 +37,62 @@ def test_load_urdfmodel_with_simplification(self): |
32 | 37 | # load using existing cache |
33 | 38 | with mesh_simplify_factor(0.1): |
34 | 39 | RobotModelFromURDF(urdf_file=fetch_urdfpath()) |
| 40 | + |
| 41 | + |
| 42 | +class TestRobotModelFromURDFDeprecation(unittest.TestCase): |
| 43 | + |
| 44 | + def test_deprecation_warning(self): |
| 45 | + """Test that RobotModelFromURDF raises DeprecationWarning.""" |
| 46 | + with warnings.catch_warnings(record=True) as w: |
| 47 | + warnings.simplefilter("always") |
| 48 | + RobotModelFromURDF(urdf_file=panda_urdfpath()) |
| 49 | + self.assertEqual(len(w), 1) |
| 50 | + self.assertTrue(issubclass(w[0].category, DeprecationWarning)) |
| 51 | + self.assertIn("deprecated", str(w[0].message).lower()) |
| 52 | + |
| 53 | + |
| 54 | +class TestRobotModelURDFParameters(unittest.TestCase): |
| 55 | + |
| 56 | + def test_robot_model_with_urdf_file_path(self): |
| 57 | + """Test RobotModel initialization with urdf file path.""" |
| 58 | + robot = RobotModel(urdf=panda_urdfpath()) |
| 59 | + self.assertEqual(robot.name, "panda") |
| 60 | + |
| 61 | + def test_robot_model_with_urdf_string(self): |
| 62 | + """Test RobotModel initialization with urdf string.""" |
| 63 | + with open(panda_urdfpath(), 'r') as f: |
| 64 | + urdf_string = f.read() |
| 65 | + robot = RobotModel(urdf=urdf_string) |
| 66 | + self.assertEqual(robot.name, "panda") |
| 67 | + |
| 68 | + def test_robot_model_from_urdf_static_method(self): |
| 69 | + """Test RobotModel.from_urdf static method.""" |
| 70 | + robot = RobotModel.from_urdf(panda_urdfpath()) |
| 71 | + self.assertEqual(robot.name, "panda") |
| 72 | + |
| 73 | + def test_panda_with_custom_urdf(self): |
| 74 | + """Test Panda with custom urdf parameter.""" |
| 75 | + panda = Panda(urdf=panda_urdfpath()) |
| 76 | + self.assertEqual(panda.name, "panda") |
| 77 | + |
| 78 | + def test_panda_with_custom_urdf_file(self): |
| 79 | + """Test Panda with custom urdf_file parameter.""" |
| 80 | + panda = Panda(urdf_file=panda_urdfpath()) |
| 81 | + self.assertEqual(panda.name, "panda") |
| 82 | + |
| 83 | + def test_fetch_with_custom_urdf(self): |
| 84 | + """Test Fetch with custom urdf parameter.""" |
| 85 | + fetch = Fetch(urdf=fetch_urdfpath()) |
| 86 | + self.assertEqual(fetch.name, "fetch") |
| 87 | + |
| 88 | + def test_panda_raises_error_with_both_urdf_params(self): |
| 89 | + """Test that providing both urdf and urdf_file raises ValueError.""" |
| 90 | + with self.assertRaises(ValueError) as context: |
| 91 | + Panda(urdf="test", urdf_file="test2") |
| 92 | + self.assertIn("cannot be given at the same time", str(context.exception)) |
| 93 | + |
| 94 | + def test_fetch_raises_error_with_both_urdf_params(self): |
| 95 | + """Test that providing both urdf and urdf_file raises ValueError.""" |
| 96 | + with self.assertRaises(ValueError) as context: |
| 97 | + Fetch(urdf="test", urdf_file="test2") |
| 98 | + self.assertIn("cannot be given at the same time", str(context.exception)) |
0 commit comments