Diff of /test_sims.py [000000] .. [20044c]

Switch to unified view

a b/test_sims.py
1
import unittest
2
import os
3
import mujoco
4
5
model_paths = [
6
            # Basic models
7
            "basic/myomuscle.xml",
8
9
            # finger models
10
            "finger/finger_v0.xml",
11
            "finger/myofinger_v0.xml",
12
            "finger/motorfinger_v0.xml",
13
14
            # elbow models
15
            "elbow/myoelbow_1dof6muscles_1dofexo.xml",
16
            "elbow/myoelbow_1dof6muscles.xml",
17
            "elbow/myoelbow_2dof6muscles.xml",
18
            "elbow/myoelbow_1dof6muscles_1dofSoftexo_Ideal.xml",
19
            "elbow/myoelbow_1dof6muscles_1dofSoftexo_sim2.xml",
20
21
            # arms
22
            "arm/myoarm.xml",
23
24
            # hand models
25
            "hand/myohand.xml",
26
27
            # leg models
28
            "leg/myolegs.xml",
29
            "leg/myolegs_abdomen.xml",
30
            "osl/myolegs_osl.xml",
31
32
            # torso
33
            "torso/myotorso_rigid.xml",
34
35
            # scene
36
            "scene/myosuite_scene_noPedestal.xml",
37
            "scene/myosuite_scene.xml",
38
            "scene/myosuite_quad.xml",
39
            "scene/myosuite_logo.xml",
40
        ]
41
42
class TestSims(unittest.TestCase):
43
44
    def get_sim(self, model_path:str=None, model_xmlstr=None):
45
        """
46
        Get sim using model_path or model_xmlstr.
47
        """
48
49
        # load from path
50
        if model_path:
51
52
            # resolve full path
53
            if model_path.startswith("/"):
54
                fullpath = model_path
55
            else:
56
                fullpath = os.path.join(os.path.dirname(__file__), model_path)
57
            if not os.path.exists(fullpath):
58
                raise IOError("File %s does not exist" % fullpath)
59
60
            # load model
61
            if model_path.endswith(".mjb"):
62
                model = mujoco.MjModel.from_binary_path(fullpath)
63
            elif  model_path.endswith(".xml"):
64
                model = mujoco.MjModel.from_xml_path(fullpath)
65
66
        # load from xml string
67
        elif model_xmlstr:
68
            model = mujoco.MjModel.from_xml_path(model_xmlstr)
69
        else:
70
            raise TypeError("Both model_path and model_xmlstr can't be None")
71
72
        return model
73
74
75
    def test_sims(self):
76
77
        for model_path in model_paths:
78
            print("Testing: {}".format(model_path))
79
            self.get_sim(model_path)
80
81
82
if __name__ == '__main__':
83
    unittest.main()