def _create_controller_info_record(self, controller_module_name): """Creates controller info record for a particular controller type. Info is retrieved from all the controller objects spawned from the specified module, using the controller module's `get_info` function. Args: controller_module_name: string, the name of the controller module to retrieve info from. Returns: A records.ControllerInfoRecord object. """ module = self._controller_modules[controller_module_name] controller_info = None try: controller_info = module.get_info( copy.copy(self._controller_objects[controller_module_name])) except AttributeError: logging.warning( 'No optional debug info found for controller ' '%s. To provide it, implement `get_info`.', controller_module_name) try: yaml.dump(controller_info) except TypeError: logging.warning( 'The info of controller %s in class "%s" is not ' 'YAML serializable! Coercing it to string.', controller_module_name, self._class_name) controller_info = str(controller_info) return records.ControllerInfoRecord( self._class_name, module.MOBLY_CONTROLLER_CONFIG_NAME, controller_info)
def test_add_controller_info_record(self): tr = records.TestResult() self.assertFalse(tr.controller_info) controller_info = records.ControllerInfoRecord( 'SomeClass', 'MockDevice', ['magicA', 'magicB']) tr.add_controller_info_record(controller_info) self.assertTrue(tr.controller_info[0]) self.assertEqual(tr.controller_info[0].controller_name, 'MockDevice') self.assertEqual(tr.controller_info[0].controller_info, ['magicA', 'magicB'])
def test_result_add_operator_success(self): record1 = records.TestResultRecord(self.tn) record1.test_begin() s = signals.TestPass(self.details, self.float_extra) record1.test_pass(s) tr1 = records.TestResult() tr1.add_record(record1) controller_info = records.ControllerInfoRecord( 'SomeClass', 'MockDevice', ['magicA', 'magicB']) tr1.add_controller_info_record(controller_info) record2 = records.TestResultRecord(self.tn) record2.test_begin() s = signals.TestPass(self.details, self.json_extra) record2.test_pass(s) tr2 = records.TestResult() tr2.add_record(record2) controller_info = records.ControllerInfoRecord( 'SomeClass', 'MockDevice', ['magicC']) tr2.add_controller_info_record(controller_info) tr2 += tr1 self.assertTrue(tr2.passed, [tr1, tr2]) self.assertTrue(tr2.controller_info, {'MockDevice': ['magicC']})