Ejemplo n.º 1
0
 def testNormalizeAndValidateObbFileNames_ExpandsUserDir(self):
   # Linux shell does not convert "~" to home directory, we need to do it
   obb_files_map = {
       '~/main.12.a.b1.obb': '/home/user/main.12.a.b1.obb',
       '~/spam/main.34.c.d1.obb': '/home/user/spam/main.34.c.d1.obb',
       # Only affects paths starting with "~"
       'spam/~/main.34.c.d1.obb': 'spam/~/main.34.c.d1.obb',
   }
   with mock.patch.dict('os.environ', {'HOME': '/home/user'}):
     for obb_test, obb_test_expect in obb_files_map.items():
       obb_files = [obb_test]
       arg_validate.NormalizeAndValidateObbFileNames(obb_files)
       self.assertEqual([obb_test_expect], obb_files)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def testNormalizeAndValidateObbFileNames_SucceedsWithValidNames(self):
   # Valid OBB file names should not raise an InvalidArgException
   arg_validate.NormalizeAndValidateObbFileNames(
       ['main.1234.com.google.app.obb'])
   arg_validate.NormalizeAndValidateObbFileNames(
       ['patch.4321.com.google.app.obb'])
   arg_validate.NormalizeAndValidateObbFileNames(
       ['gs://bucket/a/object/main.1.com.a.obb'])
   arg_validate.NormalizeAndValidateObbFileNames(
       ['/my/path/to/patch.555.Google.App.obb'])
   # Valid, albeit not useful posix path
   arg_validate.NormalizeAndValidateObbFileNames(
       ['//path/main.999.COM.G00_GL3_.obb'])
   arg_validate.NormalizeAndValidateObbFileNames(
       ['gs://bucket/patch.6.a.B.c.D.e.f_g.obb'])
   arg_validate.NormalizeAndValidateObbFileNames(
       ['C:\\aa\\bb\\patch.1234567.com.app.obb'])
   # Multiple file names
   arg_validate.NormalizeAndValidateObbFileNames(
       ['main.12.a.b1.obb', 'patch.34.c.d2.obb'])
Ejemplo n.º 4
0
 def testObbValidation_WithInvalidNames(self):
   # Invalid OBB file names should raise an InvalidArgException
   # Assume blanks are unintentional user error (e.g. undefined script var)
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames([''])
   # Version # in wrong position
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['main.a.123.b.obb'])
   # Missing package name
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['patch.123.obb'])
   # Doesn't start with main. or patch.
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['Main.123.a.b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(
         ['path/to/mmain.123.a.b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['patch3.456.a.b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['ppatch.456.a.b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['foo.main.789.a.b.obb'])
   # Package name part doesn't start with a letter
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['main.456.a._b_.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['main.456.a.b.8c.obb'])
   # Misplaced or missing periods
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['patch.456.a..b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['patch.456a.b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['patch.456.a.b.obb.'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['main.45.6.a.b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['main.456.a.bobb'])
   # Contains invalid characters
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['main.999:a.b.obb'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['*****@*****.**'])
   with self.assertRaises(exceptions.InvalidArgumentException):
     arg_validate.NormalizeAndValidateObbFileNames(['main.999.a.b$.obb'])
Ejemplo n.º 5
0
 def testNormalizeAndValidateObbFileNames_NoExceptionIfNoObbFilesSpecified(
     self):
   arg_validate.NormalizeAndValidateObbFileNames(None)
   arg_validate.NormalizeAndValidateObbFileNames([])