コード例 #1
0
ファイル: debugging_test.py プロジェクト: wpumacay/dm_control
    def test_full_debug_dump(self):
        self.setup_debug_mode(debug_mode_enabled=True, full_dump_enabled=False)
        mjcf_model = test_code.make_valid_model()
        test_code.break_valid_model(mjcf_model)
        # Make sure that we advertise full dump mode if it's currently disabled.
        with self.assertRaisesRegexp(mujoco_wrapper.Error,
                                     '--pymjcf_debug_full_dump_dir'):
            mjcf.Physics.from_mjcf_model(mjcf_model)
        self.setup_debug_mode(debug_mode_enabled=True, full_dump_enabled=True)
        with self.assertRaises(mujoco_wrapper.Error):
            mjcf.Physics.from_mjcf_model(mjcf_model)

        with open(os.path.join(self.dump_dir, 'model.xml')) as f:
            dumped_xml = f.read()
        dumped_xml = [line.strip() for line in dumped_xml.strip().split('\n')]

        xml_line_pattern = re.compile(r'^(.*)<!--pymjcfdebug:(\d+)-->$')
        uninstrumented_pattern = re.compile(r'({})'.format('|'.join([
            r'<mujoco model=".*">', r'</mujoco>', r'<default class=".*/"/?>',
            r'</default>'
        ])))

        for xml_line in dumped_xml:
            print(xml_line)
            xml_line_match = xml_line_pattern.match(xml_line)
            if not xml_line_match:
                # Only uninstrumented lines are allowed to have no metadata.
                self.assertIsNotNone(uninstrumented_pattern.match(xml_line))
            else:
                xml_element = xml_line_match.group(1)
                debug_id = int(xml_line_match.group(2))
                with open(os.path.join(self.dump_dir,
                                       str(debug_id) + '.dump')) as f:
                    element_dump = f.read()
                self.assertIn(xml_element, element_dump)
コード例 #2
0
 def test_physics_error_message_in_debug_mode(self):
   self.setup_debug_mode(debug_mode_enabled=True)
   mjcf_model_1 = test_code.make_broken_model()
   with self.assertRaisesTestCodeRef('make_broken_model.my_actuator'):
     mjcf.Physics.from_mjcf_model(mjcf_model_1)
   mjcf_model_2 = test_code.make_valid_model()
   physics = mjcf.Physics.from_mjcf_model(mjcf_model_2)  # Should not raise.
   test_code.break_valid_model(mjcf_model_2)
   with self.assertRaisesTestCodeRef('break_valid_model.my_actuator.joint'):
     physics.reload_from_mjcf_model(mjcf_model_2)
コード例 #3
0
ファイル: debugging_test.py プロジェクト: wpumacay/dm_control
    def test_disable_debug_mode(self):
        self.setup_debug_mode(debug_mode_enabled=False)
        mjcf_model = test_code.make_valid_model()
        test_code.break_valid_model(mjcf_model)
        self.assertFalse(mjcf_model.get_init_stack())

        my_actuator = mjcf_model.find('actuator', 'my_actuator')
        my_actuator_attrib_stacks = (
            my_actuator.get_last_modified_stacks_for_all_attributes())
        for stack in six.itervalues(my_actuator_attrib_stacks):
            self.assertFalse(stack)
コード例 #4
0
ファイル: debugging_test.py プロジェクト: wpumacay/dm_control
    def test_element_and_attribute_stacks(self):
        self.setup_debug_mode(debug_mode_enabled=True)
        mjcf_model = test_code.make_valid_model()
        test_code.break_valid_model(mjcf_model)

        self.assertStackFromTestCode(mjcf_model.get_init_stack(),
                                     'make_valid_model', 'mjcf_model')

        my_actuator = mjcf_model.find('actuator', 'my_actuator')
        self.assertStackFromTestCode(my_actuator.get_init_stack(),
                                     'make_valid_model', 'my_actuator')

        my_actuator_attrib_stacks = (
            my_actuator.get_last_modified_stacks_for_all_attributes())
        # `name` attribute was assigned at the same time as the element was created.
        self.assertEqual(my_actuator_attrib_stacks['name'],
                         my_actuator.get_init_stack())
        # `joint` attribute was modified later on.
        self.assertStackFromTestCode(my_actuator_attrib_stacks['joint'],
                                     'break_valid_model', 'my_actuator.joint')
コード例 #5
0
ファイル: debugging_test.py プロジェクト: wpumacay/dm_control
 def test_valid_physics(self):
     self.setup_debug_mode(debug_mode_enabled=True)
     mjcf_model = test_code.make_valid_model()
     mjcf.Physics.from_mjcf_model(mjcf_model)  # Should not raise