def testValidateEnvironmentVariablesList_WithValidEnvironmentVariables(self): environment_vars = { 'coverage': 'true', 'coverageFile': '/sdcard/tempDir', 'not_a_real_env_var': 'true', 'androidx.benchmark.output.enable': 'true' } args = argparse.Namespace(environment_variables=environment_vars) arg_validate.ValidateEnvironmentVariablesList(args)
def testValidateEnvironmentVariablesList_WithInvalidVariables(self): args = argparse.Namespace(environment_variables={'bad:key': 'value'}) with self.assertRaises(exceptions.InvalidArgumentException): arg_validate.ValidateEnvironmentVariablesList(args) args = argparse.Namespace(environment_variables={'bad-key': 'value'}) with self.assertRaises(exceptions.InvalidArgumentException): arg_validate.ValidateEnvironmentVariablesList(args) args = argparse.Namespace(environment_variables={'bad key': 'value'}) with self.assertRaises(exceptions.InvalidArgumentException): arg_validate.ValidateEnvironmentVariablesList(args) args = argparse.Namespace(environment_variables={'bad~key': 'value'}) with self.assertRaises(exceptions.InvalidArgumentException): arg_validate.ValidateEnvironmentVariablesList(args) args = argparse.Namespace(environment_variables={'0badkey': 'value'}) with self.assertRaises(exceptions.InvalidArgumentException): arg_validate.ValidateEnvironmentVariablesList(args)
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 testValidateEnvironmentVariablesList_NoExceptionIfNoneSpecified(self): arg_validate.ValidateEnvironmentVariablesList( argparse.Namespace(environment_variables=None)) arg_validate.ValidateEnvironmentVariablesList( argparse.Namespace(environment_variables=[]))