Store asset keys relative to the MJCF. This CL fixes cases when loading a spec with "from_zip" that fails on zipped folders that contain a root directory.
PiperOrigin-RevId: 825484553 Change-Id: I79c6f542edbd3ffd167d0b5cecc704c32c8d6824
This commit is contained in:
committed by
Copybara-Service
parent
010d919244
commit
d769440924
@@ -1615,5 +1615,25 @@ class SpecsTest(absltest.TestCase):
|
||||
self.assertEqual(wrap_joint2.type, mujoco.mjtWrap.mjWRAP_JOINT)
|
||||
self.assertEqual(wrap_joint2.coef, 2.0)
|
||||
|
||||
def test_from_zip(self):
|
||||
"""Tests that the assets are correctly parsed from a zip file."""
|
||||
model_path_root = (
|
||||
epath.resource_path("mujoco") / "testdata" / "MJCF_Root.zip"
|
||||
)
|
||||
model_path_no_root = (
|
||||
epath.resource_path("mujoco") / "testdata" / "MJCF_NoRoot.zip"
|
||||
)
|
||||
filenames = [model_path_root.as_posix(), model_path_no_root.as_posix()]
|
||||
|
||||
for filename in filenames:
|
||||
with self.subTest(filename):
|
||||
spec = mujoco.MjSpec.from_zip(filename)
|
||||
spec.compile()
|
||||
assets = spec.assets
|
||||
xml_string = spec.to_xml()
|
||||
string_spec = mujoco.MjSpec.from_string(xml_string, assets=assets)
|
||||
string_spec.compile()
|
||||
self.assertEqual(spec.to_xml(), string_spec.to_xml())
|
||||
|
||||
if __name__ == '__main__':
|
||||
absltest.main()
|
||||
|
||||
Reference in New Issue
Block a user