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) 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) arg_validate.ValidateArgsForTestType(args, test_type, self._typed_arg_rules, self._shared_arg_rules, all_test_args_set) arg_validate.ValidateIosDeviceList(args, self._catalog_mgr) arg_validate.ValidateResultsBucket(args) arg_validate.ValidateResultsDir(args)
def testArgValidation_ResultsDirContainsNewline(self): args = argparse.Namespace(results_dir='no_\n_allowed_in_value') with self.assertRaises(exceptions.InvalidArgumentException) as e: arg_validate.ValidateResultsDir(args) self.assertIn('results-dir', six.text_type(e.exception)) self.assertIn('may not contain newline or linefeed', six.text_type(e.exception))
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 testArgValidation_ResultsDirLongerThan512Chars(self): args = argparse.Namespace(results_dir='x' * 513) with self.assertRaises(exceptions.InvalidArgumentException) as e: arg_validate.ValidateResultsDir(args) self.assertIn('results-dir', six.text_type(e.exception)) self.assertIn('too long', six.text_type(e.exception))
def testArgValidation_ResultsDirHasTrailingSlashesStripped(self): args = argparse.Namespace(results_dir='my/results/dir//') arg_validate.ValidateResultsDir(args) self.assertEqual(args.results_dir, 'my/results/dir')
def testArgValidation_ResultsDirWellFormed(self): args = argparse.Namespace(results_dir='well-formed-GCS-object-name') arg_validate.ValidateResultsDir(args) self.assertEqual(args.results_dir, 'well-formed-GCS-object-name')