コード例 #1
0
  def TearDownClass(cls):
    """Cleans up buckets and directories created by SetUpClass"""

    if not hasattr(cls, 'created_test_data'):
      return
    # Call cls.tearDown() in case the tests got interrupted, to ensure
    # dst objects and files get deleted.
    cls.tearDown()
    # Now delete src objects and files, and all buckets and dirs.
    try:
      for key_uri in test_util.test_wildcard_iterator('%s*' %
                                                      cls.src_bucket_uri):
        key_uri.delete_key()
    except wildcard_iterator.WildcardException:
      # Ignore cleanup failures.
      pass
    try:
      for key_uri in test_util.test_wildcard_iterator('%s**' %
                                                      cls.src_dir_root):
        key_uri.delete_key()
    except wildcard_iterator.WildcardException:
      # Ignore cleanup failures.
      pass
    cls.src_bucket_uri.delete_bucket()
    cls.dst_bucket_uri.delete_bucket()
    shutil.rmtree(cls.src_dir_root)
    shutil.rmtree(cls.dst_dir_root)
コード例 #2
0
  def TestWildcardedInvalidResultType(self):
    """Tests that we raise an exception for wildcard with invalid ResultType"""

    try:
      test_util.test_wildcard_iterator('gs://asdf/*', 'invalid')
      self.fail('Expected WildcardException not raised.')
    except wildcard_iterator.WildcardException, e:
      # Expected behavior.
      self.assertTrue(str(e).find('Invalid ResultType') != -1)
コード例 #3
0
  def TestWildcardedObjectUriWithVsWithoutPrefix(self):
    """Tests that wildcarding w/ and w/o server prefix get same result"""

    with_prefix_uri_strs = set(
        str(u) for u in test_util.test_wildcard_iterator(
            self.test_bucket0_uri.clone_replace_name('abcd'), ResultType.URIS))
    # By including a wildcard at the start of the string no prefix can be
    # used in server request.
    no_prefix_uri_strs = set(
        str(u) for u in test_util.test_wildcard_iterator(
            self.test_bucket0_uri.clone_replace_name('?bcd'), ResultType.URIS))
    self.assertEqual(with_prefix_uri_strs, no_prefix_uri_strs)
コード例 #4
0
 def TestWildcardedObjectUriWithVsWithoutPrefix(self):
   """Tests that wildcarding w/ and w/o server prefix get same result"""
   # (It's just more efficient to query w/o a prefix; wildcard
   # iterator will filter the matches either way.)
   with_prefix_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           self.test_bucket0_uri.clone_replace_name('abcd')).IterUris())
   # By including a wildcard at the start of the string no prefix can be
   # used in server request.
   no_prefix_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           self.test_bucket0_uri.clone_replace_name('?bcd')).IterUris())
   self.assertEqual(with_prefix_uri_strs, no_prefix_uri_strs)
コード例 #5
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestMovingBucketSubDirToBucketSubDir(self):
   """Tests moving a bucket subdir to another bucket subdir"""
   # Test with and without final slash on dest subdir.
   for (final_src_char, final_dst_char) in (
       ('', ''), ('', '/'), ('/', ''), ('/', '/') ):
     # Set up existing bucket subdir by creating an object in the subdir.
     self.RunCommand(
         'cp', ['%sf0' % self.src_dir_root,
                '%sdst_subdir/existing_obj' % self.dst_bucket_uri.uri])
     self.RunCommand(
         'mv', ['%s%s' % (self.src_bucket_subdir_uri, final_src_char),
                '%s%s' % (self.dst_bucket_subdir_uri.uri, final_dst_char)])
     actual = set(str(u) for u in test_util.test_wildcard_iterator(
         '%s**' % self.dst_bucket_subdir_uri.uri).IterUris())
     expected = set(['%sdst_subdir/existing_obj' % self.dst_bucket_uri.uri])
     for uri in self.all_src_subdir_and_below_obj_uris:
       # Unlike the case with copying, with mv we expect renaming to occur
       # at the level of the src subdir, vs appending that subdir beneath the
       # dst subdir like is done for copying.
       expected_name = uri.object_name.replace('src_', 'dst_')
       expected.add('%s%s' % (self.dst_bucket_uri.uri, expected_name))
     self.assertEqual(expected, actual)
     # Clean up/re-set up for next variant iteration.
     self.TearDownClass()
     self.SetUpClass()
コード例 #6
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestRecursiveCopyObjsAndFilesToExistingBucketSubDir(self):
   """Tests recursive copy of objects and files to existing bucket subdir"""
   # Test with and without final slash on dest subdir.
   for final_char in ('/', ''):
     # Set up existing bucket subdir by creating an object in the subdir.
     self.RunCommand(
         'cp', ['%sf0' % self.src_dir_root,
                '%sdst_subdir/existing_obj' % self.dst_bucket_uri.uri])
     self.RunCommand(
         'cp', ['-R', '%s' % self.src_bucket_uri.uri,
                '%s' % self.src_dir_root,
                '%sdst_subdir%s' % (self.dst_bucket_uri.uri, final_char)])
     actual = set(str(u) for u in test_util.test_wildcard_iterator(
         '%s**' % self.dst_bucket_uri.uri).IterUris())
     expected = set(['%sdst_subdir/existing_obj' % self.dst_bucket_uri.uri])
     for uri in self.all_src_obj_uris:
       expected.add('%sdst_subdir/%s/%s' %
                   (self.dst_bucket_uri.uri, uri.bucket_name, uri.object_name))
     for file_path in self.all_src_file_paths:
       start_tmp_pos = file_path.find(self.tmpdir_prefix)
       file_path_sans_base_dir = file_path[start_tmp_pos:]
       expected.add('%sdst_subdir/%s' %
                    (self.dst_bucket_uri.uri, file_path_sans_base_dir))
     self.assertEqual(expected, actual)
     # Clean up/re-set up for next variant iteration.
     self.TearDownClass()
     self.SetUpClass()
コード例 #7
0
  def TestNoOpDirectoryIterator(self):
    """Tests that directory-only URI iterates just that one URI"""

    results = list(test_util.test_wildcard_iterator('file:///tmp/',
                                                    ResultType.URIS))
    self.assertEqual(1, len(results))
    self.assertEqual('file:///tmp/', str(results[0]))
コード例 #8
0
 def TestSingleMatchWildcardedBucketUri(self):
   """Tests matching a single bucket based on a wildcarded bucket URI"""
   exp_obj_uri_strs = set(['%s_1/' % self.base_uri_str])
   actual_obj_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           '%s*1' % self.base_uri_str).IterUris())
   self.assertEqual(exp_obj_uri_strs, actual_obj_uri_strs)
コード例 #9
0
 def TestMatchingNonWildcardedUri(self):
   """Tests matching a single named file"""
   exp_uri_strs = set(['file://%s/abcd' % self.test_dir])
   uri = test_util.test_storage_uri('file://%s/abcd' % self.test_dir)
   actual_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(uri).IterUris())
   self.assertEqual(exp_uri_strs, actual_uri_strs)
コード例 #10
0
 def TestMatchingAllFiles(self):
   """Tests matching all files, based on wildcard"""
   uri = test_util.test_storage_uri('file://%s/*' % self.test_dir)
   actual_uri_strs = set(str(u) for u in
                         test_util.test_wildcard_iterator(uri).IterUris()
                        )
   self.assertEqual(self.immed_child_uri_strs, actual_uri_strs)
コード例 #11
0
  def TestMatchingAllObjects(self):
    """Tests matching all objects, based on wildcard"""

    actual_obj_uri_strs = set(
        str(u) for u in test_util.test_wildcard_iterator(
            self.test_bucket0_uri.clone_replace_name('*'), ResultType.URIS))
    self.assertEqual(self.test_bucket0_obj_uri_strs, actual_obj_uri_strs)
コード例 #12
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestFlatCopyingObjsAndFilesToBucketSubDir(self):
   """Tests copying flatly listed objects and files to bucket subdir"""
   # Test with and without final slash on dest subdir.
   for final_char in ('/', ''):
     # Set up existing bucket subdir by creating an object in the subdir.
     self.RunCommand(
         'cp', ['%sf0' % self.src_dir_root,
                '%sdst_subdir/existing_obj' % self.dst_bucket_uri.uri])
     self.RunCommand(
         'cp', ['-R', '%s**' % self.src_bucket_uri.uri,
                '%s**' % self.src_dir_root,
                '%sdst_subdir%s' % (self.dst_bucket_uri.uri, final_char)])
     actual = set(str(u) for u in test_util.test_wildcard_iterator(
         '%s**' % self.dst_bucket_uri.uri).IterUris())
     expected = set(['%sdst_subdir/existing_obj' % self.dst_bucket_uri.uri])
     for uri in self.all_src_obj_uris:
       # Use FinalObjNameComponent here because we expect names to be flattened
       # when using wildcard copy semantics.
       expected.add('%sdst_subdir/%s' % (self.dst_bucket_uri.uri,
                                        self.FinalObjNameComponent(uri)))
     for file_path in self.nested_child_file_paths:
       # Use os.path.basename here because we expect names to be flattened when
       # using wildcard copy semantics.
       expected.add('%sdst_subdir/%s' % (self.dst_bucket_uri.uri,
                                        os.path.basename(file_path)))
     self.assertEqual(expected, actual)
     # Clean up/re-set up for next variant iteration.
     self.TearDownClass()
     self.SetUpClass()
コード例 #13
0
  def TestNoOpObjectIterator(self):
    """Tests that bucket-only URI iterates just that one URI"""

    results = list(test_util.test_wildcard_iterator(self.test_bucket0_uri,
                                                    ResultType.URIS))
    self.assertEqual(1, len(results))
    self.assertEqual(str(self.test_bucket0_uri), str(results[0]))
コード例 #14
0
 def TestWildcardBucketAndObjectUri(self):
   """Tests matching with both bucket and object wildcards"""
   exp_obj_uri_strs = set([str(self.test_bucket0_uri.clone_replace_name(
       'abcd'))])
   actual_obj_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           '%s_0*/abc*' % self.base_uri_str).IterUris())
   self.assertEqual(exp_obj_uri_strs, actual_obj_uri_strs)
コード例 #15
0
 def TestWildcardUpToFinalCharSubdirPlusObjectName(self):
   """Tests wildcard subd*r/obj name"""
   exp_obj_uri_strs = set([str(self.test_bucket0_uri.clone_replace_name(
       'nested1/nested2/xyz1'))])
   actual_obj_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           '%snested1/nest*2/xyz1' % self.test_bucket0_uri.uri).IterUris())
   self.assertEqual(exp_obj_uri_strs, actual_obj_uri_strs)
コード例 #16
0
 def TestPostRecursiveWildcard(self):
   """Tests that wildcard containing ** followed by an additional wildcard works"""
   exp_obj_uri_strs = set([str(self.test_bucket0_uri.clone_replace_name(
       'nested1/nested2/xyz2'))])
   actual_obj_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           '%s**/*y*2' % self.test_bucket0_uri.uri).IterUris())
   self.assertEqual(exp_obj_uri_strs, actual_obj_uri_strs)
コード例 #17
0
  def TestMatchingFilesIgnoringOtherRegexChars(self):
    """Tests ignoring non-wildcard regex chars (e.g., ^ and $)"""

    exp_uri_strs = set(['file://%s/ade$' % self.test_dir])
    uri = test_util.test_storage_uri('file://%s/ad*$' % self.test_dir)
    actual_uri_strs = set(
        str(u) for u in test_util.test_wildcard_iterator(uri).IterUris())
    self.assertEqual(exp_uri_strs, actual_uri_strs)
コード例 #18
0
 def TestCopyingFileToDir(self):
   """Tests copying one file to a directory"""
   src_file = self.SrcFile('nested')
   command_inst.CopyObjsCommand([src_file, self.dst_dir_root], headers={})
   actual = list(test_util.test_wildcard_iterator('%s*' % self.dst_dir_root))
   self.assertEqual(1, len(actual))
   self.assertEqual('file://%s%s' % (self.dst_dir_root, 'nested'),
                    actual[0].uri)
コード例 #19
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestCopyingFilesAndDirNonRecursive(self):
   """Tests copying containing files and a directory without -R"""
   self.RunCommand('cp', ['%s*' % self.src_dir_root, self.dst_dir_root])
   actual = set(str(u) for u in test_util.test_wildcard_iterator(
       '%s**' % self.dst_dir_root).IterUris())
   expected = set(['file://%s%s' % (self.dst_dir_root, f)
                   for f in self.non_nested_file_names])
   self.assertEqual(expected, actual)
コード例 #20
0
 def TestMatchingNonWildcardedUri(self):
   """Tests matching a single named object"""
   exp_obj_uri_strs = set([str(self.test_bucket0_uri.clone_replace_name('abcd')
                              )])
   actual_obj_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           self.test_bucket0_uri.clone_replace_name('abcd')).IterUris())
   self.assertEqual(exp_obj_uri_strs, actual_obj_uri_strs)
コード例 #21
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestCopyingFileToObjectWithConsecutiveSlashes(self):
   """Tests copying a file to an object containing consecutive slashes"""
   src_file = self.SrcFile('f0')
   self.RunCommand('cp', [src_file, '%s/obj' % self.dst_bucket_uri.uri])
   actual = list(test_util.test_wildcard_iterator(
       '%s**' % self.dst_bucket_uri.uri).IterUris())
   self.assertEqual(1, len(actual))
   self.assertEqual('/obj', actual[0].object_name)
コード例 #22
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestCopyingObjectToObject(self):
   """Tests copying an object to an object"""
   self.RunCommand('cp', ['%sobj1' % self.src_bucket_uri.uri,
                          self.dst_bucket_uri.uri])
   actual = list(test_util.test_wildcard_iterator(
       '%s*' % self.dst_bucket_uri.uri).IterUris())
   self.assertEqual(1, len(actual))
   self.assertEqual('obj1', actual[0].object_name)
コード例 #23
0
ファイル: test_commands.py プロジェクト: viswansh/gamme-2.7
 def TestCopyingFileToDir(self):
   """Tests copying one file to a directory"""
   src_file = self.SrcFile('nested')
   self.command_runner.RunNamedCommand('cp', [src_file, self.dst_dir_root])
   actual = list(test_util.test_wildcard_iterator('%s*' % self.dst_dir_root))
   self.assertEqual(1, len(actual))
   self.assertEqual('file://%s%s' % (self.dst_dir_root, 'nested'),
                    actual[0].uri)
コード例 #24
0
 def TestMultiMatchWildcardedBucketUri(self):
   """Tests matching a multiple buckets based on a wildcarded bucket URI"""
   exp_obj_uri_strs = set(['%s_%s/' %
                           (self.base_uri_str, i) for i in range(2)])
   actual_obj_uri_strs = set(
       str(u) for u in test_util.test_wildcard_iterator(
           '%s*' % self.base_uri_str).IterUris())
   self.assertEqual(exp_obj_uri_strs, actual_obj_uri_strs)
コード例 #25
0
  def TestRecursiveDirectoryPlusFileWildcarding(self):
    """Tests recusive expansion of '**' directory plus '*' wildcard"""

    uri = test_util.test_storage_uri('file://%s/**/*' % self.test_dir)
    actual_uri_strs = set(str(u) for u in
                          test_util.test_wildcard_iterator(uri, ResultType.KEYS)
                         )
    self.assertEqual(self.all_file_uri_strs, actual_uri_strs)
コード例 #26
0
 def TestCopyingObjectToObject(self):
   """Tests copying an object to an object"""
   command_inst.CopyObjsCommand(['%sobj1' % self.src_bucket_uri.uri,
                                 self.dst_bucket_uri.uri], headers={})
   actual = list(test_util.test_wildcard_iterator('%s*' %
                                                  self.dst_bucket_uri.uri))
   self.assertEqual(1, len(actual))
   self.assertEqual('obj1', actual[0].object_name)
コード例 #27
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestCopyingTopLevelFileToBucket(self):
   """Tests copying one top-level file to a bucket"""
   src_file = self.SrcFile('f0')
   self.RunCommand('cp', [src_file, self.dst_bucket_uri.uri])
   actual = list(test_util.test_wildcard_iterator(
       '%s**' % self.dst_bucket_uri.uri).IterUris())
   self.assertEqual(1, len(actual))
   self.assertEqual('f0', actual[0].object_name)
コード例 #28
0
ファイル: test_commands.py プロジェクト: SjB/Dart
 def TestMinusDOptionWorks(self):
   """Tests using gsutil -D option"""
   src_file = self.SrcFile('f0')
   self.RunCommand('cp', [src_file, self.dst_bucket_uri.uri], debug=3)
   actual = list(test_util.test_wildcard_iterator(
       '%s*' % self.dst_bucket_uri.uri).IterUris())
   self.assertEqual(1, len(actual))
   self.assertEqual('f0', actual[0].object_name)
コード例 #29
0
 def TestMinusDOptionWorks(self):
   """Tests using gsutil -D option"""
   src_file = self.SrcFile('f0')
   command_inst.CopyObjsCommand([src_file, self.dst_bucket_uri.uri],
                                headers={}, debug=3)
   actual = list(test_util.test_wildcard_iterator('%s*' %
                                                  self.dst_bucket_uri.uri))
   self.assertEqual(1, len(actual))
   self.assertEqual('f0', actual[0].object_name)
コード例 #30
0
 def TestCopyingTopLevelFileToBucket(self):
   """Tests copying one top-level file to a bucket"""
   src_file = self.SrcFile('f0')
   command_inst.CopyObjsCommand([src_file, self.dst_bucket_uri.uri],
                                headers={})
   actual = list(test_util.test_wildcard_iterator('%s*' %
                                                  self.dst_bucket_uri.uri))
   self.assertEqual(1, len(actual))
   self.assertEqual('f0', actual[0].object_name)
コード例 #31
0
 def TestWildcardUpToFinalCharSubdirPlusObjectName(self):
     """Tests wildcard subd*r/obj name"""
     exp_obj_uri_strs = set([
         str(
             self.test_bucket0_uri.clone_replace_name(
                 'nested1/nested2/xyz1'))
     ])
     actual_obj_uri_strs = set(
         str(u) for u in test_util.test_wildcard_iterator(
             '%snested1/nest*2/xyz1' %
             self.test_bucket0_uri.uri).IterUris())
     self.assertEqual(exp_obj_uri_strs, actual_obj_uri_strs)
コード例 #32
0
 def TestCopyingBucketToBucket(self):
     """Tests copying from a bucket-only URI to a bucket"""
     command_inst.CopyObjsCommand(
         [self.src_bucket_uri.uri, self.dst_bucket_uri.uri], RECURSIVE)
     actual = set(
         str(u)
         for u in test_util.test_wildcard_iterator('%s*' %
                                                   self.dst_bucket_uri.uri))
     expected = set()
     for uri in self.all_src_obj_uris:
         expected.add('%s%s' % (self.dst_bucket_uri.uri, uri.object_name))
     self.assertEqual(expected, actual)
コード例 #33
0
 def TestCopyingFilesAndDirNonRecursive(self):
     """Tests copying containing files and a directory without -r"""
     command_inst.CopyObjsCommand(
         ['%s*' % self.src_dir_root, self.dst_dir_root])
     actual = set(
         str(u)
         for u in test_util.test_wildcard_iterator('%s**' %
                                                   self.dst_dir_root))
     expected = set([
         'file://%s%s' % (self.dst_dir_root, f)
         for f in self.non_nested_file_names
     ])
     self.assertEqual(expected, actual)
コード例 #34
0
 def TestCopyingBucketToDir(self):
     """Tests copying from a bucket to a directory"""
     command_inst.CopyObjsCommand(
         [self.src_bucket_uri.uri, self.dst_dir_root], RECURSIVE)
     actual = set(
         str(u)
         for u in test_util.test_wildcard_iterator('%s**' %
                                                   self.dst_dir_root))
     expected = set()
     for uri in self.all_src_obj_uris:
         expected.add('file://%s%s/%s' %
                      (self.dst_dir_root, uri.bucket_name, uri.object_name))
     self.assertEqual(expected, actual)
コード例 #35
0
 def TestWildcardPlusSubdirMatch(self):
     """Tests gs://bucket/*/subdir matching"""
     actual_uri_strs = set()
     actual_prefixes = set()
     for blr in test_util.test_wildcard_iterator(
             self.test_bucket0_uri.clone_replace_name('*/nested1')):
         if blr.HasPrefix():
             actual_prefixes.add(blr.GetPrefix().name)
         else:
             actual_uri_strs.add(blr.GetUri().uri)
     expected_uri_strs = set()
     expected_prefixes = set(['nested1/'])
     self.assertEqual(expected_prefixes, actual_prefixes)
     self.assertEqual(expected_uri_strs, actual_uri_strs)
コード例 #36
0
 def TestWildcardedObjectUriNestedSubSubdirMatch(self):
     """Tests wildcarding with a nested sub-subdir"""
     for final_char in ('', '/'):
         uri_strs = set()
         prefixes = set()
         for blr in test_util.test_wildcard_iterator(
                 self.test_bucket0_uri.clone_replace_name('nested1/*%s' %
                                                          final_char)):
             if blr.HasPrefix():
                 prefixes.add(blr.GetPrefix().name)
             else:
                 uri_strs.add(blr.GetUri().uri)
         self.assertEqual(0, len(uri_strs))
         self.assertEqual(1, len(prefixes))
         self.assertTrue('nested1/nested2/' in prefixes)
コード例 #37
0
 def TestCopyingDirToDir(self):
     """Tests copying from a directory to a directory"""
     command_inst.CopyObjsCommand([self.src_dir_root, self.dst_dir_root],
                                  RECURSIVE)
     actual = set(
         str(u)
         for u in test_util.test_wildcard_iterator('%s**' %
                                                   self.dst_dir_root))
     expected = set()
     for file_path in self.all_src_file_paths:
         start_tmp_pos = file_path.find(self.tmpdir_prefix)
         file_path_sans_top_tmp_dir = file_path[start_tmp_pos:]
         expected.add('file://%s%s' %
                      (self.dst_dir_root, file_path_sans_top_tmp_dir))
     self.assertEqual(expected, actual)
コード例 #38
0
 def tearDown(cls):
     """Deletes any objects or files created by last test run"""
     try:
         for key_uri in test_util.test_wildcard_iterator(
                 '%s*' % cls.dst_bucket_uri):
             key_uri.delete_key()
     # For some reason trying to catch except
     # wildcard_iterator.WildcardException doesn't work here.
     except Exception:
         # Ignore cleanup failures.
         pass
     # Recursively delete dst dir and then re-create it, so in effect we
     # remove all dirs and files under that directory.
     shutil.rmtree(cls.dst_dir_root)
     os.mkdir(cls.dst_dir_root)
コード例 #39
0
 def TestCopyingCompressedFileToBucket(self):
     """Tests copying one file with compression to a bucket"""
     src_file = self.SrcFile('f2.txt')
     command_inst.CopyObjsCommand([src_file, self.dst_bucket_uri.uri],
                                  sub_opts=[('-z', 'txt')])
     actual = list(
         str(u)
         for u in test_util.test_wildcard_iterator('%s*' %
                                                   self.dst_bucket_uri.uri))
     self.assertEqual(1, len(actual))
     expected_dst_uri = self.dst_bucket_uri.clone_replace_name('f2.txt')
     self.assertEqual(expected_dst_uri.uri, actual[0])
     dst_key = expected_dst_uri.get_key()
     dst_key.open_read()
     self.assertEqual('gzip', dst_key.content_encoding)
コード例 #40
0
 def TestCopyingObjsAndFilesToBucket(self):
     """Tests copying objects and files to a bucket"""
     command_inst.CopyObjsCommand([
         '%s*' % self.src_bucket_uri.uri,
         '%s*' % self.src_dir_root, self.dst_bucket_uri.uri
     ], RECURSIVE)
     actual = set(
         str(u)
         for u in test_util.test_wildcard_iterator('%s*' %
                                                   self.dst_bucket_uri.uri))
     expected = set()
     for uri in self.all_src_obj_uris:
         expected.add('%s%s' % (self.dst_bucket_uri.uri, uri.object_name))
     for file_path in self.nested_child_file_paths:
         expected.add('%s%s' % (self.dst_bucket_uri.uri, file_path))
     self.assertEqual(expected, actual)
コード例 #41
0
 def TestCopyingDirToBucket(self):
     """Tests copying top-level directory to a bucket"""
     command_inst.CopyObjsCommand(
         [self.src_dir_root, self.dst_bucket_uri.uri],
         RECURSIVE,
         headers={})
     actual = set(
         str(u)
         for u in test_util.test_wildcard_iterator('%s*' %
                                                   self.dst_bucket_uri.uri))
     expected = set()
     for file_path in self.all_src_file_paths:
         start_tmp_pos = file_path.find(self.tmpdir_prefix)
         file_path_sans_top_tmp_dir = file_path[start_tmp_pos:]
         expected.add('%s%s' %
                      (self.dst_bucket_uri.uri, file_path_sans_top_tmp_dir))
     self.assertEqual(expected, actual)
コード例 #42
0
 def TestWildcardedObjectUriNestedSubdirMatch(self):
     """Tests wildcarding with a nested subdir"""
     uri_strs = set()
     prefixes = set()
     for blr in test_util.test_wildcard_iterator(
             self.test_bucket0_uri.clone_replace_name('*')):
         if blr.HasPrefix():
             prefixes.add(blr.GetPrefix().name)
         else:
             uri_strs.add(blr.GetUri().uri)
     exp_obj_uri_strs = set([
         '%s_0/%s' % (self.base_uri_str, x)
         for x in self.immed_child_obj_names
     ])
     self.assertEqual(exp_obj_uri_strs, uri_strs)
     self.assertEqual(1, len(prefixes))
     self.assertTrue('nested1/' in prefixes)
コード例 #43
0
    def TestCopyingDirContainingOneFileToBucket(self):
        """Tests copying a directory containing 1 file to a bucket

    We test this case to ensure that correct bucket handling isn't dependent
    on the copy being treated as a multi-source copy.
    """
        command_inst.CopyObjsCommand([
            '%sdir0%sdir1' %
            (self.src_dir_root, os.sep), self.dst_bucket_uri.uri
        ], RECURSIVE)
        actual = list(
            (str(u)
             for u in test_util.test_wildcard_iterator('%s*' %
                                                       self.dst_bucket_uri.uri)
             ))
        self.assertEqual(1, len(actual))
        self.assertEqual('%sdir1%snested' % (self.dst_bucket_uri.uri, os.sep),
                         actual[0])
コード例 #44
0
    def TestWildcardMoveWithinBucket(self):
        """Attempts to move using src wildcard that overlaps dest object.

    We want to ensure that this doesn't stomp the result data. See the
    comment starting with "Expand wildcards before" in MoveObjsCommand
    for details.
    """
        # Create a single object; use 'dst' bucket because it gets cleared after
        # each test.
        self.CreateEmptyObject(
            test_util.test_storage_uri('%sold' % self.dst_bucket_uri))
        command_inst.MoveObjsCommand([
            '%s*' % self.dst_bucket_uri.uri,
            '%snew' % self.dst_bucket_uri.uri
        ])
        actual = list(
            test_util.test_wildcard_iterator('%s*' % self.dst_bucket_uri.uri))
        self.assertEqual(1, len(actual))
        self.assertEqual('new', actual[0].object_name)
コード例 #45
0
 def TestMatchingAllFiles(self):
     """Tests matching all files, based on wildcard"""
     uri = test_util.test_storage_uri('file://%s/*' % self.test_dir)
     actual_uri_strs = set(
         str(u) for u in test_util.test_wildcard_iterator(uri).IterUris())
     self.assertEqual(self.immed_child_uri_strs, actual_uri_strs)
コード例 #46
0
 def TestRecursiveDirectoryPlusFileWildcarding(self):
     """Tests recusive expansion of '**' directory plus '*' wildcard"""
     uri = test_util.test_storage_uri('file://%s/**/*' % self.test_dir)
     actual_uri_strs = set(
         str(u) for u in test_util.test_wildcard_iterator(uri).IterUris())
     self.assertEqual(self.all_file_uri_strs, actual_uri_strs)
コード例 #47
0
 def TestNoMatchingWildcardedObjectUri(self):
     """Tests that get back an empty iterator for non-matching wildcarded URI"""
     res = list(
         test_util.test_wildcard_iterator(
             self.test_bucket0_uri.clone_replace_name('*x0')).IterUris())
     self.assertEqual(0, len(res))
コード例 #48
0
 def TestNoOpDirectoryIterator(self):
     """Tests that directory-only URI iterates just that one URI"""
     results = list(
         test_util.test_wildcard_iterator('file:///tmp/').IterUris())
     self.assertEqual(1, len(results))
     self.assertEqual('file:///tmp/', str(results[0]))
コード例 #49
0
 def TestMissingDir(self):
     """Tests that wildcard gets empty iterator when directory doesn't exist"""
     res = list(
         test_util.test_wildcard_iterator(
             'file://no_such_dir/*').IterUris())
     self.assertEqual(0, len(res))
コード例 #50
0
 def TestMatchingAllObjects(self):
     """Tests matching all objects, based on wildcard"""
     actual_obj_uri_strs = set(
         str(u) for u in test_util.test_wildcard_iterator(
             self.test_bucket0_uri.clone_replace_name('**')).IterUris())
     self.assertEqual(self.test_bucket0_obj_uri_strs, actual_obj_uri_strs)
コード例 #51
0
 def TestExistingDirNoFileMatch(self):
     """Tests that wildcard returns empty iterator when there's no match"""
     uri = test_util.test_storage_uri('file://%s/non_existent*' %
                                      self.test_dir)
     res = list(test_util.test_wildcard_iterator(uri).IterUris())
     self.assertEqual(0, len(res))
コード例 #52
0
 def TestNoOpObjectIterator(self):
     """Tests that bucket-only URI iterates just that one URI"""
     results = list(
         test_util.test_wildcard_iterator(self.test_bucket0_uri).IterUris())
     self.assertEqual(1, len(results))
     self.assertEqual(str(self.test_bucket0_uri), str(results[0]))