def test_unpack_userparams_optional_with_default(self):
     """If an optional param is specified with a default value, and the
     param is not in the config, the value should be the default value.
     """
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     bc.unpack_userparams(optional_thing="whatever")
     self.assertEqual(bc.optional_thing, "whatever")
Example #2
0
 def test_unpack_userparams_required(self):
     """Missing a required param should raise an error."""
     required = ['some_param']
     bc = base_test.BaseTestClass(self.test_run_config)
     bc.unpack_userparams(required)
     expected_value = self.test_run_config.user_params['some_param']
     self.assertEqual(bc.some_param, expected_value)
Example #3
0
 def test_register_controller_builtin_dup_register(self):
     """Same as test_register_controller_third_party_dup_register, except
     this is for a builtin controller module.
     """
     mock_test_config = self.test_run_config.copy()
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     mock_ref_name = 'haha'
     setattr(mock_controller, 'ACTS_CONTROLLER_REFERENCE_NAME',
             mock_ref_name)
     try:
         mock_ctrlr_ref_name = mock_controller.ACTS_CONTROLLER_REFERENCE_NAME
         mock_test_config.controller_configs[mock_ctrlr_config_name] = [
             'magic1', 'magic2'
         ]
         base_cls = base_test.BaseTestClass(mock_test_config)
         base_cls.register_controller(mock_controller, builtin=True)
         self.assertTrue(hasattr(base_cls, mock_ref_name))
         self.assertTrue(mock_controller.__name__ in
                         base_cls._controller_manager._controller_objects)
         mock_ctrlrs = getattr(base_cls, mock_ctrlr_ref_name)
         self.assertEqual(mock_ctrlrs[0].magic, 'magic1')
         self.assertEqual(mock_ctrlrs[1].magic, 'magic2')
         expected_msg = 'Controller module .* has already been registered.'
         with self.assertRaisesRegexp(signals.ControllerError,
                                      expected_msg):
             base_cls.register_controller(mock_controller, builtin=True)
     finally:
         delattr(mock_controller, 'ACTS_CONTROLLER_REFERENCE_NAME')
Example #4
0
 def test_unpack_userparams_required_missing(self):
     """Missing a required param should raise an error."""
     required = ['something']
     bc = base_test.BaseTestClass(self.test_run_config)
     expected_msg = ('Missing required user param "%s" in test '
                     'configuration.') % required[0]
     with self.assertRaises(mobly_base_test.Error, msg=expected_msg):
         bc.unpack_userparams(required)
 def test_unpack_userparams_required_missing(self):
     """Missing a required param should raise an error."""
     required = ["something"]
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     expected_msg = ("Missing required user param '%s' in test "
                     "configuration.") % required[0]
     with self.assertRaises(base_test.Error, msg=expected_msg):
         bc.unpack_userparams(required)
Example #6
0
 def test_unpack_userparams_default_overwrite_by_optional_param_list(self):
     """If an optional param is specified in kwargs, and the param is in the
     config, the value should be the one in the config.
     """
     bc = base_test.BaseTestClass(self.test_run_config)
     bc.unpack_userparams(some_param='whatever')
     expected_value = self.test_run_config.user_params['some_param']
     self.assertEqual(bc.some_param, expected_value)
 def test_unpack_userparams_required(self):
     """Missing a required param should raise an error."""
     required = ["some_param"]
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     bc.unpack_userparams(required)
     expected_value = self.mock_test_cls_configs["user_params"][
         "some_param"]
     self.assertEqual(bc.some_param, expected_value)
Example #8
0
 def test_unpack_userparams_default_overwrite(self):
     default_arg_val = 'haha'
     actual_arg_val = 'wawa'
     arg_name = 'arg1'
     configs = self.test_run_config.copy()
     configs.user_params[arg_name] = actual_arg_val
     bc = base_test.BaseTestClass(configs)
     bc.unpack_userparams(opt_param_names=[arg_name], arg1=default_arg_val)
     self.assertEqual(bc.arg1, actual_arg_val)
 def test_unpack_userparams_default_overwrite_by_optional_param_list(self):
     """If an optional param is specified in kwargs, and the param is in the
     config, the value should be the one in the config.
     """
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     bc.unpack_userparams(some_param="whatever")
     expected_value = self.mock_test_cls_configs["user_params"][
         "some_param"]
     self.assertEqual(bc.some_param, expected_value)
Example #10
0
 def test_unpack_userparams_optional(self):
     """If an optional param is specified, the value should be what's in the
     config.
     """
     opt = ['some_param']
     bc = base_test.BaseTestClass(self.test_run_config)
     bc.unpack_userparams(opt_param_names=opt)
     expected_value = self.test_run_config.user_params['some_param']
     self.assertEqual(bc.some_param, expected_value)
 def test_unpack_userparams_default_overwrite(self):
     default_arg_val = "haha"
     actual_arg_val = "wawa"
     arg_name = "arg1"
     configs = dict(self.mock_test_cls_configs)
     configs["user_params"][arg_name] = actual_arg_val
     bc = base_test.BaseTestClass(configs)
     bc.unpack_userparams(opt_param_names=[arg_name], arg1=default_arg_val)
     self.assertEqual(bc.arg1, actual_arg_val)
 def test_unpack_userparams_default_overwrite_by_required_param_list(self):
     """If an optional param is specified in kwargs, the param is in the
     required param list, and the param is not specified in the config, the
     param's alue should be the default value and there should be no error
     thrown.
     """
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     bc.unpack_userparams(
         req_param_names=['a_kwarg_param'], a_kwarg_param="whatever")
     self.assertEqual(bc.a_kwarg_param, "whatever")
 def test_unpack_userparams_optional(self):
     """If an optional param is specified, the value should be what's in the
     config.
     """
     opt = ["some_param"]
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     bc.unpack_userparams(opt_param_names=opt)
     expected_value = self.mock_test_cls_configs["user_params"][
         "some_param"]
     self.assertEqual(bc.some_param, expected_value)
Example #14
0
 def test_register_controller_return_value(self):
     mock_test_config = self.test_run_config.copy()
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     mock_test_config.controller_configs[mock_ctrlr_config_name] = [
         'magic1', 'magic2'
     ]
     base_cls = base_test.BaseTestClass(mock_test_config)
     magic_devices = base_cls.register_controller(mock_controller)
     self.assertEqual(magic_devices[0].magic, 'magic1')
     self.assertEqual(magic_devices[1].magic, 'magic2')
Example #15
0
    def test_handle_file_user_params_does_not_overwrite_existing_params(self):
        test_run_config = self.test_run_config.copy()
        test_run_config.user_params = {
            'foo': ['good_value'],
            'local_files': {
                'foo': ['bad_value']
            }
        }
        test = base_test.BaseTestClass(test_run_config)

        self.assertEqual(test.user_params['foo'], ['good_value'])
Example #16
0
 def test_unpack_userparams_basic(self):
     """Required and optional params are unpacked properly."""
     required = ['something']
     optional = ['something_else']
     configs = self.test_run_config.copy()
     configs.user_params['something'] = 42
     configs.user_params['something_else'] = 53
     bc = base_test.BaseTestClass(configs)
     bc.unpack_userparams(req_param_names=required,
                          opt_param_names=optional)
     self.assertEqual(bc.something, 42)
     self.assertEqual(bc.something_else, 53)
 def test_unpack_userparams_basic(self):
     """Required and optional params are unpacked properly."""
     required = ["something"]
     optional = ["something_else"]
     configs = dict(self.mock_test_cls_configs)
     configs["user_params"]["something"] = 42
     configs["user_params"]["something_else"] = 53
     bc = base_test.BaseTestClass(configs)
     bc.unpack_userparams(
         req_param_names=required, opt_param_names=optional)
     self.assertEqual(bc.something, 42)
     self.assertEqual(bc.something_else, 53)
Example #18
0
 def test_register_controller_no_get_info(self):
     mock_test_config = self.test_run_config.copy()
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     mock_ref_name = 'haha'
     get_info = getattr(mock_controller, 'get_info')
     delattr(mock_controller, 'get_info')
     try:
         mock_test_config.controller_configs[mock_ctrlr_config_name] = [
             'magic1', 'magic2'
         ]
         base_cls = base_test.BaseTestClass(mock_test_config)
         base_cls.register_controller(mock_controller)
         self.assertEqual(base_cls.results.controller_info, [])
     finally:
         setattr(mock_controller, 'get_info', get_info)
Example #19
0
 def test_register_optional_controller_third_party_dup_register(self):
     """Verifies correctness of registration, internal tally of controllers
     objects, and the right error happen when an optional controller module
     is registered twice.
     """
     mock_test_config = self.test_run_config.copy()
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     mock_test_config.controller_configs[mock_ctrlr_config_name] = [
         'magic1', 'magic2'
     ]
     base_cls = base_test.BaseTestClass(mock_test_config)
     base_cls.register_controller(mock_controller, required=False)
     expected_msg = 'Controller module .* has already been registered.'
     with self.assertRaisesRegexp(signals.ControllerError, expected_msg):
         base_cls.register_controller(mock_controller, required=False)
Example #20
0
 def test_register_controller_third_party_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_test_config = self.test_run_config.copy()
     mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME
     mock_test_config.controller_configs[mock_ctrlr_config_name] = [
         'magic1', 'magic2'
     ]
     base_cls = base_test.BaseTestClass(mock_test_config)
     base_cls.register_controller(mock_controller)
     registered_name = 'mock_controller'
     controller_objects = base_cls._controller_manager._controller_objects
     self.assertTrue(registered_name in controller_objects)
     mock_ctrlrs = controller_objects[registered_name]
     self.assertEqual(mock_ctrlrs[0].magic, 'magic1')
     self.assertEqual(mock_ctrlrs[1].magic, 'magic2')
     expected_msg = 'Controller module .* has already been registered.'
     with self.assertRaisesRegexp(signals.ControllerError, expected_msg):
         base_cls.register_controller(mock_controller)
Example #21
0
    def test_handle_file_user_params_dumps_files_dict(self):
        test_run_config = self.test_run_config.copy()
        test_run_config.user_params = {'my_files': {'foo': ['good_value']}}
        test = base_test.BaseTestClass(test_run_config)

        self.assertEqual(test.user_params['foo'], ['good_value'])
 def test_unpack_userparams_default_None(self):
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     bc.unpack_userparams(arg1="haha")
     self.assertEqual(bc.arg1, "haha")
Example #23
0
    def test_handle_file_user_params_is_called_in_init(self):
        test_run_config = self.test_run_config.copy()
        test_run_config.user_params['files'] = {'file_a': ['/some/path']}
        test = base_test.BaseTestClass(test_run_config)

        self.assertEqual(test.user_params['file_a'], ['/some/path'])
 def test_unpack_userparams_optional_missing(self):
     """Missing an optional param should not raise an error."""
     opt = ["something"]
     bc = base_test.BaseTestClass(self.mock_test_cls_configs)
     bc.unpack_userparams(opt_param_names=opt)
Example #25
0
 def test_unpack_userparams_default_None(self):
     bc = base_test.BaseTestClass(self.test_run_config)
     bc.unpack_userparams(arg1='haha')
     self.assertEqual(bc.arg1, 'haha')
Example #26
0
 def test_register_controller_no_config(self):
     base_cls = base_test.BaseTestClass(self.test_run_config)
     with self.assertRaisesRegexp(signals.ControllerError,
                                  'No corresponding config found for'):
         base_cls.register_controller(mock_controller)
Example #27
0
 def test_register_optional_controller_no_config(self):
     base_cls = base_test.BaseTestClass(self.test_run_config)
     self.assertIsNone(
         base_cls.register_controller(mock_controller, required=False))