def testValidateRoboDirectivesList_WithInvalidActionType(self):
   args = argparse.Namespace(robo_directives={'badtype:resource': 'value'})
   with self.assertRaises(exceptions.InvalidArgumentException) as e:
     arg_validate.ValidateRoboDirectivesList(args)
   self.assertIn('robo-directives', six.text_type(e.exception))
   self.assertIn('Unsupported action type [badtype]',
                 six.text_type(e.exception))
 def testValidateRoboDirectivesList_WithIgnoreActionAndInputText(self):
   args = argparse.Namespace(robo_directives={'ignore:resource': 'value'})
   with self.assertRaises(exceptions.InvalidArgumentException) as e:
     arg_validate.ValidateRoboDirectivesList(args)
   self.assertIn('robo-directives', six.text_type(e.exception))
   self.assertIn(
       'Input value not allowed for click or ignore actions: [ignore:resource=value]',
       six.text_type(e.exception))
 def testValidateRoboDirectivesList_WithValidRoboDirectives(self):
   args = argparse.Namespace(robo_directives={
       'resource1': 'value1',
       'text:resource2': 2,
       'click:resource3': '',
       'ignore:resource4': ''
   })
   arg_validate.ValidateRoboDirectivesList(args)
 def testValidateRoboDirectivesList_WithInvalidResourceName(self):
   args = argparse.Namespace(robo_directives={'text:resource:name': 'value'})
   with self.assertRaises(exceptions.InvalidArgumentException) as e:
     arg_validate.ValidateRoboDirectivesList(args)
   self.assertIn('robo-directives', six.text_type(e.exception))
   self.assertIn(
       'Invalid format for key [text:resource:name]. '
       'Use a colon only to separate action type and resource name.',
       six.text_type(e.exception))
 def testValidateRoboDirectivesList_WithDuplicateResourceNames(self):
   # Default duplicate validation for maps won't catch when a directive is
   # specified for the same resource_name but for different types.
   args = argparse.Namespace(
       robo_directives={'click:resource': '',
                        'text:resource': 'value'})
   with self.assertRaises(exceptions.InvalidArgumentException) as e:
     arg_validate.ValidateRoboDirectivesList(args)
   self.assertIn('robo-directives', six.text_type(e.exception))
   self.assertIn('Duplicate resource names are not allowed: [resource]',
                 six.text_type(e.exception))
Пример #6
0
    def Prepare(self, args):
        """Load, apply defaults, and perform validation on test arguments.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        gcloud command invocation (i.e. group and command arguments combined).
        Arg values from an optional arg-file and/or arg default values may be
        added to this argparse namespace.

    Raises:
      InvalidArgumentException: If an argument name is unknown, an argument does
        not contain a valid value, or an argument is not valid when used with
        the given type of test.
      RequiredArgumentException: If a required arg is missing.
    """
        all_test_args_set = arg_util.GetSetOfAllTestArgs(
            self._typed_arg_rules, self._shared_arg_rules)
        args_from_file = arg_file.GetArgsFromArgFile(args.argspec,
                                                     all_test_args_set)
        arg_util.ApplyLowerPriorityArgs(args, args_from_file, True)

        test_type = self.GetTestTypeOrRaise(args)
        self._CheckForConflictingArgs(args)

        typed_arg_defaults = self._typed_arg_rules[test_type]['defaults']
        shared_arg_defaults = self._shared_arg_rules['defaults']
        arg_util.ApplyLowerPriorityArgs(args, typed_arg_defaults)
        arg_util.ApplyLowerPriorityArgs(args, shared_arg_defaults)
        self._ApplyLegacyMatrixDimensionDefaults(args)

        arg_validate.ValidateArgsForTestType(args, test_type,
                                             self._typed_arg_rules,
                                             self._shared_arg_rules,
                                             all_test_args_set)
        arg_validate.ValidateOsVersions(args, self._catalog_mgr)
        arg_validate.ValidateDeviceList(args, self._catalog_mgr)
        arg_validate.ValidateResultsBucket(args)
        arg_validate.ValidateResultsDir(args)
        arg_validate.NormalizeAndValidateObbFileNames(args.obb_files)
        arg_validate.ValidateRoboDirectivesList(args)
        arg_validate.ValidateEnvironmentVariablesList(args)
        arg_validate.ValidateTestTargetsForShard(args)
        arg_validate.NormalizeAndValidateDirectoriesToPullList(
            args.directories_to_pull)
        arg_validate.ValidateScenarioNumbers(args)
 def testValidateRoboDirectivesList_WithEmptyResourceName(self):
   args = argparse.Namespace(robo_directives={'text:': 'value'})
   with self.assertRaises(exceptions.InvalidArgumentException) as e:
     arg_validate.ValidateRoboDirectivesList(args)
   self.assertIn('robo-directives', six.text_type(e.exception))
   self.assertIn('Missing resource_name for key', six.text_type(e.exception))
 def testValidateRoboDirectivesList_NoExceptionIfNoneSpecified(self):
   arg_validate.ValidateRoboDirectivesList(
       argparse.Namespace(robo_directives=None))
   arg_validate.ValidateRoboDirectivesList(
       argparse.Namespace(robo_directives=[]))