Ejemplo n.º 1
0
  def testGetAssetsFromDict(self):
    with open(_MODEL_WITH_INVALID_FILENAMES, 'rb') as f:
      xml_string = f.read()
    with open(_TEXTURE_PATH, 'rb') as f:
      texture_contents = f.read()
    with open(_MESH_PATH, 'rb') as f:
      mesh_contents = f.read()
    with open(_INCLUDED_WITH_INVALID_FILENAMES, 'rb') as f:
      included_xml_contents = f.read()
    assets = {
        'invalid_texture_name.png': texture_contents,
        'invalid_mesh_name.stl': mesh_contents,
        'invalid_included_name.xml': included_xml_contents,
    }
    # The paths specified in the main and included XML files are deliberately
    # invalid, so the parser should fail unless the pre-loaded assets are passed
    # in as a dict.
    with self.assertRaises(IOError):
      parser.from_xml_string(xml_string=xml_string)

    mujoco = parser.from_xml_string(xml_string=xml_string, assets=assets)
    expected_assets = {}
    for path, contents in six.iteritems(assets):
      _, filename = os.path.split(path)
      prefix, extension = os.path.splitext(filename)
      if extension != '.xml':
        vfs_filename = ''.join(
            [prefix, '-', hashlib.sha1(contents).hexdigest(), extension])
        expected_assets[vfs_filename] = contents
    self.assertDictEqual(expected_assets, mujoco.get_assets())
Ejemplo n.º 2
0
 def testParseFromString(self, model_path):
   with open(model_path) as xml_file:
     xml_string = xml_file.read()
   model_dir, _ = os.path.split(model_path)
   parser.from_xml_string(xml_string, model_dir=model_dir)