Check for duplicated names when setting element names.
PiperOrigin-RevId: 778827590 Change-Id: I77a208c1571cf735cae80840ea830aa347681f71
This commit is contained in:
committed by
Copybara-Service
parent
594e17074a
commit
564c51ddb9
@@ -677,7 +677,9 @@ def generate_name() -> None:
|
||||
return mjs_getName(self.element);
|
||||
}},
|
||||
[](raw::{titlecase}& self, std::string& name) -> void {{
|
||||
mjs_setName(self.element, name.c_str());
|
||||
if (mjs_setName(self.element, name.c_str())) {{
|
||||
throw pybind11::value_error(mjs_getError(mjs_getSpec(self.element)));
|
||||
}}
|
||||
}}, py::return_value_policy::reference_internal);
|
||||
"""
|
||||
print(code)
|
||||
|
||||
@@ -10194,7 +10194,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
('mjs_setName',
|
||||
FunctionDecl(
|
||||
name='mjs_setName',
|
||||
return_type=ValueType(name='void'),
|
||||
return_type=ValueType(name='int'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='element',
|
||||
@@ -10209,7 +10209,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
),
|
||||
),
|
||||
),
|
||||
doc="Set element's name.",
|
||||
doc="Set element's name, return 0 on success.",
|
||||
)),
|
||||
('mjs_setBuffer',
|
||||
FunctionDecl(
|
||||
|
||||
@@ -887,7 +887,7 @@ class SpecsTest(absltest.TestCase):
|
||||
):
|
||||
s.compile()
|
||||
|
||||
def test_recompile_error(self):
|
||||
def test_duplicate_name_error(self):
|
||||
main_xml = """
|
||||
<mujoco>
|
||||
<worldbody>
|
||||
@@ -899,16 +899,11 @@ class SpecsTest(absltest.TestCase):
|
||||
"""
|
||||
|
||||
spec = mujoco.MjSpec.from_string(main_xml)
|
||||
model = spec.compile()
|
||||
data = mujoco.MjData(model)
|
||||
|
||||
spec.add_material().name = 'yellow'
|
||||
spec.add_material().name = 'yellow'
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "Error: repeated name 'yellow' in material"
|
||||
):
|
||||
spec.recompile(model, data)
|
||||
spec.add_material().name = 'yellow'
|
||||
|
||||
def test_delete_unused_plugin(self):
|
||||
spec = mujoco.MjSpec.from_string("""
|
||||
|
||||
Reference in New Issue
Block a user