コード例 #1
0
    def __init__(self, configs):
        """Constructor of BaseTestClass.

        The constructor takes a config_parser.TestRunConfig object and which has
        all the information needed to execute this test class, like log_path
        and controller configurations. For details, see the definition of class
        config_parser.TestRunConfig.

        Args:
            configs: A config_parser.TestRunConfig object.
        """
        self.tests = []
        self._class_name = self.__class__.__name__
        if configs.test_class_name_suffix and self.TAG is None:
            self.TAG = '%s_%s' % (self._class_name,
                                  configs.test_class_name_suffix)
        elif self.TAG is None:
            self.TAG = self._class_name
        # Set params.
        self.log_path = configs.log_path
        self.test_bed_name = configs.test_bed_name
        self.user_params = configs.user_params
        self.results = records.TestResult()
        self.summary_writer = configs.summary_writer
        # Deprecated, use `self.current_test_info.name`.
        self.current_test_name = None
        self._generated_test_table = collections.OrderedDict()
        self._controller_manager = controller_manager.ControllerManager(
            class_name=self.TAG, controller_configs=configs.controller_configs)
        self.controller_configs = self._controller_manager.controller_configs
コード例 #2
0
    def __init__(self, configs):
        """Constructor of BaseTestClass.

    The constructor takes a config_parser.TestRunConfig object and which has
    all the information needed to execute this test class, like log_path
    and controller configurations. For details, see the definition of class
    config_parser.TestRunConfig.

    Args:
      configs: A config_parser.TestRunConfig object.
    """
        self.tests = []
        class_identifier = self.__class__.__name__
        if configs.test_class_name_suffix:
            class_identifier = '%s_%s' % (class_identifier,
                                          configs.test_class_name_suffix)
        if self.TAG is None:
            self.TAG = class_identifier
        # Set params.
        self.root_output_path = configs.log_path
        self.log_path = os.path.join(self.root_output_path, class_identifier)
        utils.create_dir(self.log_path)
        # Deprecated, use 'testbed_name'
        self.test_bed_name = configs.test_bed_name
        self.testbed_name = configs.testbed_name
        self.user_params = configs.user_params
        self.results = records.TestResult()
        self.summary_writer = configs.summary_writer
        self._generated_test_table = collections.OrderedDict()
        self._controller_manager = controller_manager.ControllerManager(
            class_name=self.TAG, controller_configs=configs.controller_configs)
        self.controller_configs = self._controller_manager.controller_configs
コード例 #3
0
 def test_register_controller_less_than_min_number(self):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     expected_msg = 'Expected to get at least 3 controller objects, got 2.'
     with self.assertRaisesRegex(signals.ControllerError, expected_msg):
         c_manager.register_controller(mock_controller, min_number=3)
コード例 #4
0
 def test_register_controller_return_value(self):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     magic_devices = c_manager.register_controller(mock_controller)
     self.assertEqual(magic_devices[0].magic, 'magic1')
     self.assertEqual(magic_devices[1].magic, 'magic2')
コード例 #5
0
 def test_unregister_controller_without_registration(
         self, mock_destroy_func):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     c_manager.unregister_controllers()
     mock_destroy_func.assert_not_called()
     self.assertFalse(c_manager._controller_objects)
     self.assertFalse(c_manager._controller_modules)
コード例 #6
0
 def test_get_controller_info_record_not_serializable(self, _):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     c_manager.register_controller(mock_controller)
     record = c_manager.get_controller_info_records()[0]
     actual_controller_info = record.controller_info
     self.assertEqual(actual_controller_info,
                      "[{'MyMagic': 'magic1'}, {'MyMagic': 'magic2'}]")
コード例 #7
0
 def test_register_controller_change_return_value(self):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     magic_devices = c_manager.register_controller(mock_controller)
     magic1 = magic_devices.pop(0)
     self.assertIs(magic1,
                   c_manager._controller_objects['mock_controller'][0])
     self.assertEqual(len(c_manager._controller_objects['mock_controller']),
                      2)
コード例 #8
0
 def test_get_controller_info_records_empty(self, mock_get_info_func):
     mock_get_info_func.return_value = None
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     c_manager.register_controller(mock_controller)
     record = c_manager.get_controller_info_records()[0]
     self.assertIsNone(record.controller_info)
     self.assertEqual(record.test_class, 'SomeClass')
     self.assertEqual(record.controller_name, 'MagicDevice')
コード例 #9
0
 def test_get_controller_info_records_error(self, mock_get_info_func,
                                            mock_add_error):
     mock_get_info_func.side_effect = Exception('Record info failed.')
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     c_manager.register_controller(mock_controller)
     self.assertFalse(c_manager.get_controller_info_records())
     mock_add_error.assert_called_once()
     error_record = mock_add_error.call_args[0][0]
     self.assertIn('Record info failed.', error_record.stacktrace)
コード例 #10
0
 def test_unregister_controller_error(self, mock_destroy_func,
                                      mock_add_error):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     c_manager.register_controller(mock_controller)
     mock_destroy_func.side_effect = Exception('Failed in destroy.')
     c_manager.unregister_controllers()
     mock_add_error.assert_called_once()
     error_record = mock_add_error.call_args[0][0]
     self.assertIn('Failed in destroy.', error_record.stacktrace)
     self.assertFalse(c_manager._controller_objects)
     self.assertFalse(c_manager._controller_modules)
コード例 #11
0
 def test_controller_record_exists_without_get_info(self):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     get_info = getattr(mock_controller, 'get_info')
     delattr(mock_controller, 'get_info')
     try:
         c_manager.register_controller(mock_controller)
         record = c_manager.get_controller_info_records()[0]
         self.assertIsNone(record.controller_info)
         self.assertEqual(record.test_class, 'SomeClass')
         self.assertEqual(record.controller_name, 'MagicDevice')
     finally:
         setattr(mock_controller, 'get_info', get_info)
コード例 #12
0
 def test_register_controller_dup_register(self):
     """Verifies correctness of registration, internal tally of controllers
 objects, and the right error happen when a controller module is
 registered twice.
 """
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     c_manager.register_controller(mock_controller)
     registered_name = 'mock_controller'
     self.assertTrue(registered_name in c_manager._controller_objects)
     mock_ctrlrs = c_manager._controller_objects[registered_name]
     self.assertEqual(mock_ctrlrs[0].magic, 'magic1')
     self.assertEqual(mock_ctrlrs[1].magic, 'magic2')
     self.assertTrue(c_manager._controller_modules[registered_name])
     expected_msg = 'Controller module .* has already been registered.'
     with self.assertRaisesRegex(signals.ControllerError, expected_msg):
         c_manager.register_controller(mock_controller)
コード例 #13
0
 def test_get_controller_info_records(self):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     c_manager.register_controller(mock_controller)
     record = c_manager.get_controller_info_records()[0]
     record_dict = record.to_dict()
     record_dict.pop('Timestamp')
     self.assertEqual(
         record_dict, {
             'Controller Info': [{
                 'MyMagic': 'magic1'
             }, {
                 'MyMagic': 'magic2'
             }],
             'Controller Name': 'MagicDevice',
             'Test Class': 'SomeClass'
         })
コード例 #14
0
 def test_register_controller_no_config_for_not_required(self):
     c_manager = controller_manager.ControllerManager('SomeClass', {})
     self.assertIsNone(
         c_manager.register_controller(mock_controller, required=False))
コード例 #15
0
 def test_register_controller_no_config(self):
     c_manager = controller_manager.ControllerManager('SomeClass', {})
     with self.assertRaisesRegex(signals.ControllerError,
                                 'No corresponding config found for'):
         c_manager.register_controller(mock_controller)
コード例 #16
0
 def test_get_controller_info_without_registration(self):
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     controller_configs = {mock_ctrlr_config_name: ['magic1', 'magic2']}
     c_manager = controller_manager.ControllerManager(
         'SomeClass', controller_configs)
     self.assertFalse(c_manager.get_controller_info_records())