def validate()

in mujoco_worldgen/parser/parser.py [0:0]


def validate(xml_dict):
    '''
    If we make assumptions elsewhere in XML processing, then they should be
        enforced here.
    '''
    # Assumption: radians for angles, "xyz" euler angle sequence, etc.

    values = {'@coordinate': 'local',
              '@angle': 'radian',
              '@eulerseq': 'xyz'}
    for key, value in values.items():
        if key in xml_dict:
            assert value == xml_dict[key], 'Invalid value for \"%s\". We support only \"%s\"' % (key, value)

    # Assumption: all meshes have name
    if "asset" in xml_dict and "mesh" in xml_dict["asset"]:
        for mesh in xml_dict["asset"]["mesh"]:
            assert "@name" in mesh, "%s is missing name" % mesh

    # Assumption: none all the default classes is global.
    if "default" in xml_dict:
        for key, value in xml_dict["default"].items():
            assert key == "default", "Dont use global variables in default %s %s" % (key, value)

    # Assumption: all joints have name.
    def assert_joint_names(node):
        if "joint" in node:
            for joint in node["joint"]:
                assert "@name" in joint, "Missing name for %s" % joint

    if "worldbody" in xml_dict:
        closure_transform(assert_joint_names)(xml_dict["worldbody"])