Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
test.test_shutil.TestShutil Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def write_file
def mkdtemp
def test_rmtree_errors
def test_on_error
def check_args_to_onerror
def test_rmtree_dont_delete_file
def test_copytree_simple
def test_copytree_with_exclude
def test_dont_copy_file_onto_link_to_itself
def test_dont_copy_file_onto_symlink_to_itself
def test_rmtree_on_symlink
def test_copyfile_named_pipe
def test_copytree_named_pipe
def test_copytree_special_func
def test_copytree_dangling_symlinks
def test_copy
def test_copy2
def test_make_tarball
def test_tarfile_vs_tar
def test_make_zipfile
def test_make_archive
def test_make_archive_owner_group
def test_tarfile_root_owner
def test_make_archive_cwd
def test_register_archive_format
def test_unpack_archive
def test_unpack_registery

Public Attributes

 tempdirs
 errorState
 childpath

Private Member Functions

def _write_data
def _copy_file
def _tarinfo
def _create_files
def _compare_dirs

Detailed Description

Definition at line 67 of file test_shutil.py.


Member Function Documentation

def test.test_shutil.TestShutil._compare_dirs (   self,
  dir1,
  dir2 
) [private]

Definition at line 674 of file test_shutil.py.

00674 
00675     def _compare_dirs(self, dir1, dir2):
00676         # check that dir1 and dir2 are equivalent,
00677         # return the diff
00678         diff = []
00679         for root, dirs, files in os.walk(dir1):
00680             for file_ in files:
00681                 path = os.path.join(root, file_)
00682                 target_path = os.path.join(dir2, os.path.split(path)[-1])
00683                 if not os.path.exists(target_path):
00684                     diff.append(file_)
00685         return diff

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_shutil.TestShutil._copy_file (   self,
  method 
) [private]

Definition at line 412 of file test_shutil.py.

00412 
00413     def _copy_file(self, method):
00414         fname = 'test.txt'
00415         tmpdir = self.mkdtemp()
00416         self.write_file([tmpdir, fname])
00417         file1 = os.path.join(tmpdir, fname)
00418         tmpdir2 = self.mkdtemp()
00419         method(file1, tmpdir2)
00420         file2 = os.path.join(tmpdir2, fname)
00421         return (file1, file2)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 496 of file test_shutil.py.

00496 
00497     def _create_files(self):
00498         # creating something to tar
00499         tmpdir = self.mkdtemp()
00500         dist = os.path.join(tmpdir, 'dist')
00501         os.mkdir(dist)
00502         self.write_file([dist, 'file1'], 'xxx')
00503         self.write_file([dist, 'file2'], 'xxx')
00504         os.mkdir(os.path.join(dist, 'sub'))
00505         self.write_file([dist, 'sub', 'file3'], 'xxx')
00506         os.mkdir(os.path.join(dist, 'sub2'))
00507         tmpdir2 = self.mkdtemp()
00508         base_name = os.path.join(tmpdir2, 'archive')
00509         return tmpdir, tmpdir2, base_name

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_shutil.TestShutil._tarinfo (   self,
  path 
) [private]

Definition at line 487 of file test_shutil.py.

00487 
00488     def _tarinfo(self, path):
00489         tar = tarfile.open(path)
00490         try:
00491             names = tar.getnames()
00492             names.sort()
00493             return tuple(names)
00494         finally:
00495             tar.close()

Here is the caller graph for this function:

def test.test_shutil.TestShutil._write_data (   self,
  path,
  data 
) [private]

Definition at line 168 of file test_shutil.py.

00168 
00169     def _write_data(self, path, data):
00170         f = open(path, "w")
00171         f.write(data)
00172         f.close()

Here is the caller graph for this function:

def test.test_shutil.TestShutil.check_args_to_onerror (   self,
  func,
  arg,
  exc 
)

Definition at line 135 of file test_shutil.py.

00135 
00136     def check_args_to_onerror(self, func, arg, exc):
00137         # test_rmtree_errors deliberately runs rmtree
00138         # on a directory that is chmod 400, which will fail.
00139         # This function is run when shutil.rmtree fails.
00140         # 99.9% of the time it initially fails to remove
00141         # a file in the directory, so the first time through
00142         # func is os.remove.
00143         # However, some Linux machines running ZFS on
00144         # FUSE experienced a failure earlier in the process
00145         # at os.listdir.  The first failure may legally
00146         # be either.
00147         if self.errorState == 0:
00148             if func is os.remove:
00149                 self.assertEqual(arg, self.childpath)
00150             else:
00151                 self.assertIs(func, os.listdir,
00152                               "func must be either os.remove or os.listdir")
00153                 self.assertEqual(arg, TESTFN)
00154             self.assertTrue(issubclass(exc[0], OSError))
00155             self.errorState = 1
00156         else:
00157             self.assertEqual(func, os.rmdir)
00158             self.assertEqual(arg, TESTFN)
00159             self.assertTrue(issubclass(exc[0], OSError))
00160             self.errorState = 2

Here is the call graph for this function:

Create a temporary directory that will be cleaned up.

Returns the path of the directory.

Definition at line 93 of file test_shutil.py.

00093 
00094     def mkdtemp(self):
00095         """Create a temporary directory that will be cleaned up.
00096 
00097         Returns the path of the directory.
00098         """
00099         d = tempfile.mkdtemp()
00100         self.tempdirs.append(d)
00101         return d

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 69 of file test_shutil.py.

00069 
00070     def setUp(self):
00071         super(TestShutil, self).setUp()
00072         self.tempdirs = []

Here is the caller graph for this function:

Definition at line 73 of file test_shutil.py.

00073 
00074     def tearDown(self):
00075         super(TestShutil, self).tearDown()
00076         while self.tempdirs:
00077             d = self.tempdirs.pop()
00078             shutil.rmtree(d, os.name in ('nt', 'cygwin'))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 423 of file test_shutil.py.

00423 
00424     def test_copy(self):
00425         # Ensure that the copied file exists and has the same mode bits.
00426         file1, file2 = self._copy_file(shutil.copy)
00427         self.assertTrue(os.path.exists(file2))
00428         self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode)

Here is the call graph for this function:

Definition at line 431 of file test_shutil.py.

00431 
00432     def test_copy2(self):
00433         # Ensure that the copied file exists and has the same mode and
00434         # modification time bits.
00435         file1, file2 = self._copy_file(shutil.copy2)
00436         self.assertTrue(os.path.exists(file2))
00437         file1_stat = os.stat(file1)
00438         file2_stat = os.stat(file2)
00439         self.assertEqual(file1_stat.st_mode, file2_stat.st_mode)
00440         for attr in 'st_atime', 'st_mtime':
00441             # The modification times may be truncated in the new file.
00442             self.assertLessEqual(getattr(file1_stat, attr),
00443                                  getattr(file2_stat, attr) + 1)
00444         if hasattr(os, 'chflags') and hasattr(file1_stat, 'st_flags'):
00445             self.assertEqual(getattr(file1_stat, 'st_flags'),
00446                              getattr(file2_stat, 'st_flags'))

Here is the call graph for this function:

Definition at line 345 of file test_shutil.py.

00345 
00346         def test_copyfile_named_pipe(self):
00347             os.mkfifo(TESTFN)
00348             try:
00349                 self.assertRaises(shutil.SpecialFileError,
00350                                   shutil.copyfile, TESTFN, TESTFN2)
00351                 self.assertRaises(shutil.SpecialFileError,
00352                                   shutil.copyfile, __file__, TESTFN)
00353             finally:
00354                 os.remove(TESTFN)

Here is the call graph for this function:

Definition at line 392 of file test_shutil.py.

00392 
00393     def test_copytree_dangling_symlinks(self):
00394 
00395         # a dangling symlink raises an error at the end
00396         src_dir = self.mkdtemp()
00397         dst_dir = os.path.join(self.mkdtemp(), 'destination')
00398         os.symlink('IDONTEXIST', os.path.join(src_dir, 'test.txt'))
00399         os.mkdir(os.path.join(src_dir, 'test_dir'))
00400         self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
00401         self.assertRaises(Error, shutil.copytree, src_dir, dst_dir)
00402 
00403         # a dangling symlink is ignored with the proper flag
00404         dst_dir = os.path.join(self.mkdtemp(), 'destination2')
00405         shutil.copytree(src_dir, dst_dir, ignore_dangling_symlinks=True)
00406         self.assertNotIn('test.txt', os.listdir(dst_dir))
00407 
00408         # a dangling symlink is copied if symlinks=True
00409         dst_dir = os.path.join(self.mkdtemp(), 'destination3')
00410         shutil.copytree(src_dir, dst_dir, symlinks=True)
00411         self.assertIn('test.txt', os.listdir(dst_dir))

Here is the call graph for this function:

Definition at line 356 of file test_shutil.py.

00356 
00357         def test_copytree_named_pipe(self):
00358             os.mkdir(TESTFN)
00359             try:
00360                 subdir = os.path.join(TESTFN, "subdir")
00361                 os.mkdir(subdir)
00362                 pipe = os.path.join(subdir, "mypipe")
00363                 os.mkfifo(pipe)
00364                 try:
00365                     shutil.copytree(TESTFN, TESTFN2)
00366                 except shutil.Error as e:
00367                     errors = e.args[0]
00368                     self.assertEqual(len(errors), 1)
00369                     src, dst, error_msg = errors[0]
00370                     self.assertEqual("`%s` is a named pipe" % pipe, error_msg)
00371                 else:
00372                     self.fail("shutil.Error should have been raised")
00373             finally:
00374                 shutil.rmtree(TESTFN, ignore_errors=True)
00375                 shutil.rmtree(TESTFN2, ignore_errors=True)

Here is the call graph for this function:

Definition at line 173 of file test_shutil.py.

00173 
00174     def test_copytree_simple(self):
00175 
00176         def read_data(path):
00177             f = open(path)
00178             data = f.read()
00179             f.close()
00180             return data
00181 
00182         src_dir = tempfile.mkdtemp()
00183         dst_dir = os.path.join(tempfile.mkdtemp(), 'destination')
00184         self._write_data(os.path.join(src_dir, 'test.txt'), '123')
00185         os.mkdir(os.path.join(src_dir, 'test_dir'))
00186         self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
00187 
00188         try:
00189             shutil.copytree(src_dir, dst_dir)
00190             self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test.txt')))
00191             self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'test_dir')))
00192             self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test_dir',
00193                                                         'test.txt')))
00194             actual = read_data(os.path.join(dst_dir, 'test.txt'))
00195             self.assertEqual(actual, '123')
00196             actual = read_data(os.path.join(dst_dir, 'test_dir', 'test.txt'))
00197             self.assertEqual(actual, '456')
00198         finally:
00199             for path in (
00200                     os.path.join(src_dir, 'test.txt'),
00201                     os.path.join(dst_dir, 'test.txt'),
00202                     os.path.join(src_dir, 'test_dir', 'test.txt'),
00203                     os.path.join(dst_dir, 'test_dir', 'test.txt'),
00204                 ):
00205                 if os.path.exists(path):
00206                     os.remove(path)
00207             for path in (src_dir,
00208                     os.path.dirname(dst_dir)
00209                 ):
00210                 if os.path.exists(path):
00211                     shutil.rmtree(path)

Here is the call graph for this function:

Definition at line 376 of file test_shutil.py.

00376 
00377     def test_copytree_special_func(self):
00378 
00379         src_dir = self.mkdtemp()
00380         dst_dir = os.path.join(self.mkdtemp(), 'destination')
00381         self._write_data(os.path.join(src_dir, 'test.txt'), '123')
00382         os.mkdir(os.path.join(src_dir, 'test_dir'))
00383         self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
00384 
00385         copied = []
00386         def _copy(src, dst):
00387             copied.append((src, dst))
00388 
00389         shutil.copytree(src_dir, dst_dir, copy_function=_copy)
00390         self.assertEqual(len(copied), 2)

Here is the call graph for this function:

Definition at line 212 of file test_shutil.py.

00212 
00213     def test_copytree_with_exclude(self):
00214 
00215         def read_data(path):
00216             f = open(path)
00217             data = f.read()
00218             f.close()
00219             return data
00220 
00221         # creating data
00222         join = os.path.join
00223         exists = os.path.exists
00224         src_dir = tempfile.mkdtemp()
00225         try:
00226             dst_dir = join(tempfile.mkdtemp(), 'destination')
00227             self._write_data(join(src_dir, 'test.txt'), '123')
00228             self._write_data(join(src_dir, 'test.tmp'), '123')
00229             os.mkdir(join(src_dir, 'test_dir'))
00230             self._write_data(join(src_dir, 'test_dir', 'test.txt'), '456')
00231             os.mkdir(join(src_dir, 'test_dir2'))
00232             self._write_data(join(src_dir, 'test_dir2', 'test.txt'), '456')
00233             os.mkdir(join(src_dir, 'test_dir2', 'subdir'))
00234             os.mkdir(join(src_dir, 'test_dir2', 'subdir2'))
00235             self._write_data(join(src_dir, 'test_dir2', 'subdir', 'test.txt'),
00236                              '456')
00237             self._write_data(join(src_dir, 'test_dir2', 'subdir2', 'test.py'),
00238                              '456')
00239 
00240 
00241             # testing glob-like patterns
00242             try:
00243                 patterns = shutil.ignore_patterns('*.tmp', 'test_dir2')
00244                 shutil.copytree(src_dir, dst_dir, ignore=patterns)
00245                 # checking the result: some elements should not be copied
00246                 self.assertTrue(exists(join(dst_dir, 'test.txt')))
00247                 self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
00248                 self.assertTrue(not exists(join(dst_dir, 'test_dir2')))
00249             finally:
00250                 if os.path.exists(dst_dir):
00251                     shutil.rmtree(dst_dir)
00252             try:
00253                 patterns = shutil.ignore_patterns('*.tmp', 'subdir*')
00254                 shutil.copytree(src_dir, dst_dir, ignore=patterns)
00255                 # checking the result: some elements should not be copied
00256                 self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
00257                 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2')))
00258                 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
00259             finally:
00260                 if os.path.exists(dst_dir):
00261                     shutil.rmtree(dst_dir)
00262 
00263             # testing callable-style
00264             try:
00265                 def _filter(src, names):
00266                     res = []
00267                     for name in names:
00268                         path = os.path.join(src, name)
00269 
00270                         if (os.path.isdir(path) and
00271                             path.split()[-1] == 'subdir'):
00272                             res.append(name)
00273                         elif os.path.splitext(path)[-1] in ('.py'):
00274                             res.append(name)
00275                     return res
00276 
00277                 shutil.copytree(src_dir, dst_dir, ignore=_filter)
00278 
00279                 # checking the result: some elements should not be copied
00280                 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2',
00281                                         'test.py')))
00282                 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
00283 
00284             finally:
00285                 if os.path.exists(dst_dir):
00286                     shutil.rmtree(dst_dir)
00287         finally:
00288             shutil.rmtree(src_dir)
00289             shutil.rmtree(os.path.dirname(dst_dir))

Here is the call graph for this function:

Definition at line 291 of file test_shutil.py.

00291 
00292     def test_dont_copy_file_onto_link_to_itself(self):
00293         # Temporarily disable test on Windows.
00294         if os.name == 'nt':
00295             return
00296         # bug 851123.
00297         os.mkdir(TESTFN)
00298         src = os.path.join(TESTFN, 'cheese')
00299         dst = os.path.join(TESTFN, 'shop')
00300         try:
00301             with open(src, 'w') as f:
00302                 f.write('cheddar')
00303             os.link(src, dst)
00304             self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
00305             with open(src, 'r') as f:
00306                 self.assertEqual(f.read(), 'cheddar')
00307             os.remove(dst)
00308         finally:
00309             shutil.rmtree(TESTFN, ignore_errors=True)

Here is the call graph for this function:

Definition at line 311 of file test_shutil.py.

00311 
00312     def test_dont_copy_file_onto_symlink_to_itself(self):
00313         # bug 851123.
00314         os.mkdir(TESTFN)
00315         src = os.path.join(TESTFN, 'cheese')
00316         dst = os.path.join(TESTFN, 'shop')
00317         try:
00318             with open(src, 'w') as f:
00319                 f.write('cheddar')
00320             # Using `src` here would mean we end up with a symlink pointing
00321             # to TESTFN/TESTFN/cheese, while it should point at
00322             # TESTFN/cheese.
00323             os.symlink('cheese', dst)
00324             self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
00325             with open(src, 'r') as f:
00326                 self.assertEqual(f.read(), 'cheddar')
00327             os.remove(dst)
00328         finally:
00329             shutil.rmtree(TESTFN, ignore_errors=True)

Here is the call graph for this function:

Definition at line 584 of file test_shutil.py.

00584 
00585     def test_make_archive(self):
00586         tmpdir = self.mkdtemp()
00587         base_name = os.path.join(tmpdir, 'archive')
00588         self.assertRaises(ValueError, make_archive, base_name, 'xxx')

Here is the call graph for this function:

Definition at line 643 of file test_shutil.py.

00643 
00644     def test_make_archive_cwd(self):
00645         current_dir = os.getcwd()
00646         def _breaks(*args, **kw):
00647             raise RuntimeError()
00648 
00649         register_archive_format('xxx', _breaks, [], 'xxx file')
00650         try:
00651             try:
00652                 make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
00653             except Exception:
00654                 pass
00655             self.assertEqual(os.getcwd(), current_dir)
00656         finally:
00657             unregister_archive_format('xxx')

Here is the call graph for this function:

Definition at line 590 of file test_shutil.py.

00590 
00591     def test_make_archive_owner_group(self):
00592         # testing make_archive with owner and group, with various combinations
00593         # this works even if there's not gid/uid support
00594         if UID_GID_SUPPORT:
00595             group = grp.getgrgid(0)[0]
00596             owner = pwd.getpwuid(0)[0]
00597         else:
00598             group = owner = 'root'
00599 
00600         base_dir, root_dir, base_name =  self._create_files()
00601         base_name = os.path.join(self.mkdtemp() , 'archive')
00602         res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
00603                            group=group)
00604         self.assertTrue(os.path.exists(res))
00605 
00606         res = make_archive(base_name, 'zip', root_dir, base_dir)
00607         self.assertTrue(os.path.exists(res))
00608 
00609         res = make_archive(base_name, 'tar', root_dir, base_dir,
00610                            owner=owner, group=group)
00611         self.assertTrue(os.path.exists(res))
00612 
00613         res = make_archive(base_name, 'tar', root_dir, base_dir,
00614                            owner='kjhkjhkjg', group='oihohoh')
00615         self.assertTrue(os.path.exists(res))
00616 

Here is the call graph for this function:

Definition at line 448 of file test_shutil.py.

00448 
00449     def test_make_tarball(self):
00450         # creating something to tar
00451         tmpdir = self.mkdtemp()
00452         self.write_file([tmpdir, 'file1'], 'xxx')
00453         self.write_file([tmpdir, 'file2'], 'xxx')
00454         os.mkdir(os.path.join(tmpdir, 'sub'))
00455         self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
00456 
00457         tmpdir2 = self.mkdtemp()
00458         # force shutil to create the directory
00459         os.rmdir(tmpdir2)
00460         unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
00461                             "source and target should be on same drive")
00462 
00463         base_name = os.path.join(tmpdir2, 'archive')
00464 
00465         # working with relative paths to avoid tar warnings
00466         old_dir = os.getcwd()
00467         os.chdir(tmpdir)
00468         try:
00469             _make_tarball(splitdrive(base_name)[1], '.')
00470         finally:
00471             os.chdir(old_dir)
00472 
00473         # check if the compressed tarball was created
00474         tarball = base_name + '.tar.gz'
00475         self.assertTrue(os.path.exists(tarball))
00476 
00477         # trying an uncompressed one
00478         base_name = os.path.join(tmpdir2, 'archive')
00479         old_dir = os.getcwd()
00480         os.chdir(tmpdir)
00481         try:
00482             _make_tarball(splitdrive(base_name)[1], '.', compress=None)
00483         finally:
00484             os.chdir(old_dir)
00485         tarball = base_name + '.tar'
00486         self.assertTrue(os.path.exists(tarball))

Here is the call graph for this function:

Definition at line 567 of file test_shutil.py.

00567 
00568     def test_make_zipfile(self):
00569         # creating something to tar
00570         tmpdir = self.mkdtemp()
00571         self.write_file([tmpdir, 'file1'], 'xxx')
00572         self.write_file([tmpdir, 'file2'], 'xxx')
00573 
00574         tmpdir2 = self.mkdtemp()
00575         # force shutil to create the directory
00576         os.rmdir(tmpdir2)
00577         base_name = os.path.join(tmpdir2, 'archive')
00578         _make_zipfile(base_name, tmpdir)
00579 
00580         # check if the compressed tarball was created
00581         tarball = base_name + '.zip'
00582         self.assertTrue(os.path.exists(tarball))
00583 

Here is the call graph for this function:

Definition at line 111 of file test_shutil.py.

00111 
00112         def test_on_error(self):
00113             self.errorState = 0
00114             os.mkdir(TESTFN)
00115             self.childpath = os.path.join(TESTFN, 'a')
00116             f = open(self.childpath, 'w')
00117             f.close()
00118             old_dir_mode = os.stat(TESTFN).st_mode
00119             old_child_mode = os.stat(self.childpath).st_mode
00120             # Make unwritable.
00121             os.chmod(self.childpath, stat.S_IREAD)
00122             os.chmod(TESTFN, stat.S_IREAD)
00123 
00124             shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
00125             # Test whether onerror has actually been called.
00126             self.assertEqual(self.errorState, 2,
00127                              "Expected call to onerror function did not happen.")
00128 
00129             # Make writable again.
00130             os.chmod(TESTFN, old_dir_mode)
00131             os.chmod(self.childpath, old_child_mode)
00132 
00133             # Clean up.
00134             shutil.rmtree(TESTFN)

Definition at line 658 of file test_shutil.py.

00658 
00659     def test_register_archive_format(self):
00660 
00661         self.assertRaises(TypeError, register_archive_format, 'xxx', 1)
00662         self.assertRaises(TypeError, register_archive_format, 'xxx', lambda: x,
00663                           1)
00664         self.assertRaises(TypeError, register_archive_format, 'xxx', lambda: x,
00665                           [(1, 2), (1, 2, 3)])
00666 
00667         register_archive_format('xxx', lambda: x, [(1, 2)], 'xxx file')
00668         formats = [name for name, params in get_archive_formats()]
00669         self.assertIn('xxx', formats)
00670 
00671         unregister_archive_format('xxx')
00672         formats = [name for name, params in get_archive_formats()]
00673         self.assertNotIn('xxx', formats)

Here is the call graph for this function:

Definition at line 161 of file test_shutil.py.

00161 
00162     def test_rmtree_dont_delete_file(self):
00163         # When called on a file instead of a directory, don't delete it.
00164         handle, path = tempfile.mkstemp()
00165         os.fdopen(handle).close()
00166         self.assertRaises(OSError, shutil.rmtree, path)
00167         os.remove(path)

Here is the call graph for this function:

Definition at line 102 of file test_shutil.py.

00102 
00103     def test_rmtree_errors(self):
00104         # filename is guaranteed not to exist
00105         filename = tempfile.mktemp()
00106         self.assertRaises(OSError, shutil.rmtree, filename)

Here is the call graph for this function:

Definition at line 331 of file test_shutil.py.

00331 
00332     def test_rmtree_on_symlink(self):
00333         # bug 1669.
00334         os.mkdir(TESTFN)
00335         try:
00336             src = os.path.join(TESTFN, 'cheese')
00337             dst = os.path.join(TESTFN, 'shop')
00338             os.mkdir(src)
00339             os.symlink(src, dst)
00340             self.assertRaises(OSError, shutil.rmtree, dst)
00341         finally:
00342             shutil.rmtree(TESTFN, ignore_errors=True)

Here is the call graph for this function:

Definition at line 619 of file test_shutil.py.

00619 
00620     def test_tarfile_root_owner(self):
00621         tmpdir, tmpdir2, base_name =  self._create_files()
00622         old_dir = os.getcwd()
00623         os.chdir(tmpdir)
00624         group = grp.getgrgid(0)[0]
00625         owner = pwd.getpwuid(0)[0]
00626         try:
00627             archive_name = _make_tarball(base_name, 'dist', compress=None,
00628                                          owner=owner, group=group)
00629         finally:
00630             os.chdir(old_dir)
00631 
00632         # check if the compressed tarball was created
00633         self.assertTrue(os.path.exists(archive_name))
00634 
00635         # now checks the rights
00636         archive = tarfile.open(archive_name)
00637         try:
00638             for member in archive.getmembers():
00639                 self.assertEqual(member.uid, 0)
00640                 self.assertEqual(member.gid, 0)
00641         finally:
00642             archive.close()

Here is the call graph for this function:

Definition at line 513 of file test_shutil.py.

00513 
00514     def test_tarfile_vs_tar(self):
00515         tmpdir, tmpdir2, base_name =  self._create_files()
00516         old_dir = os.getcwd()
00517         os.chdir(tmpdir)
00518         try:
00519             _make_tarball(base_name, 'dist')
00520         finally:
00521             os.chdir(old_dir)
00522 
00523         # check if the compressed tarball was created
00524         tarball = base_name + '.tar.gz'
00525         self.assertTrue(os.path.exists(tarball))
00526 
00527         # now create another tarball using `tar`
00528         tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
00529         tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
00530         gzip_cmd = ['gzip', '-f9', 'archive2.tar']
00531         old_dir = os.getcwd()
00532         os.chdir(tmpdir)
00533         try:
00534             with captured_stdout() as s:
00535                 spawn(tar_cmd)
00536                 spawn(gzip_cmd)
00537         finally:
00538             os.chdir(old_dir)
00539 
00540         self.assertTrue(os.path.exists(tarball2))
00541         # let's compare both tarballs
00542         self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
00543 
00544         # trying an uncompressed one
00545         base_name = os.path.join(tmpdir2, 'archive')
00546         old_dir = os.getcwd()
00547         os.chdir(tmpdir)
00548         try:
00549             _make_tarball(base_name, 'dist', compress=None)
00550         finally:
00551             os.chdir(old_dir)
00552         tarball = base_name + '.tar'
00553         self.assertTrue(os.path.exists(tarball))
00554 
00555         # now for a dry_run
00556         base_name = os.path.join(tmpdir2, 'archive')
00557         old_dir = os.getcwd()
00558         os.chdir(tmpdir)
00559         try:
00560             _make_tarball(base_name, 'dist', compress=None, dry_run=True)
00561         finally:
00562             os.chdir(old_dir)
00563         tarball = base_name + '.tar'
00564         self.assertTrue(os.path.exists(tarball))

Here is the call graph for this function:

Definition at line 687 of file test_shutil.py.

00687 
00688     def test_unpack_archive(self):
00689         formats = ['tar', 'gztar', 'zip']
00690         if BZ2_SUPPORTED:
00691             formats.append('bztar')
00692 
00693         for format in formats:
00694             tmpdir = self.mkdtemp()
00695             base_dir, root_dir, base_name =  self._create_files()
00696             tmpdir2 = self.mkdtemp()
00697             filename = make_archive(base_name, format, root_dir, base_dir)
00698 
00699             # let's try to unpack it now
00700             unpack_archive(filename, tmpdir2)
00701             diff = self._compare_dirs(tmpdir, tmpdir2)
00702             self.assertEqual(diff, [])
00703 
00704             # and again, this time with the format specified
00705             tmpdir3 = self.mkdtemp()
00706             unpack_archive(filename, tmpdir3, format=format)
00707             diff = self._compare_dirs(tmpdir, tmpdir3)
00708             self.assertEqual(diff, [])
00709         self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
00710         self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')

Here is the call graph for this function:

Definition at line 711 of file test_shutil.py.

00711 
00712     def test_unpack_registery(self):
00713 
00714         formats = get_unpack_formats()
00715 
00716         def _boo(filename, extract_dir, extra):
00717             self.assertEqual(extra, 1)
00718             self.assertEqual(filename, 'stuff.boo')
00719             self.assertEqual(extract_dir, 'xx')
00720 
00721         register_unpack_format('Boo', ['.boo', '.b2'], _boo, [('extra', 1)])
00722         unpack_archive('stuff.boo', 'xx')
00723 
00724         # trying to register a .boo unpacker again
00725         self.assertRaises(RegistryError, register_unpack_format, 'Boo2',
00726                           ['.boo'], _boo)
00727 
00728         # should work now
00729         unregister_unpack_format('Boo')
00730         register_unpack_format('Boo2', ['.boo'], _boo)
00731         self.assertIn(('Boo2', ['.boo'], ''), get_unpack_formats())
00732         self.assertNotIn(('Boo', ['.boo'], ''), get_unpack_formats())
00733 
00734         # let's leave a clean state
00735         unregister_unpack_format('Boo2')
00736         self.assertEqual(get_unpack_formats(), formats)
00737 

Here is the call graph for this function:

def test.test_shutil.TestShutil.write_file (   self,
  path,
  content = 'xxx' 
)
Writes a file in the given path.


path can be a string or a sequence.

Definition at line 79 of file test_shutil.py.

00079 
00080     def write_file(self, path, content='xxx'):
00081         """Writes a file in the given path.
00082 
00083 
00084         path can be a string or a sequence.
00085         """
00086         if isinstance(path, (list, tuple)):
00087             path = os.path.join(*path)
00088         f = open(path, 'w')
00089         try:
00090             f.write(content)
00091         finally:
00092             f.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 114 of file test_shutil.py.

Definition at line 112 of file test_shutil.py.

Definition at line 71 of file test_shutil.py.


The documentation for this class was generated from the following file: