Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
distutils.tests.test_archive_util.ArchiveUtilTestCase Class Reference
Inheritance diagram for distutils.tests.test_archive_util.ArchiveUtilTestCase:
Inheritance graph
[legend]
Collaboration diagram for distutils.tests.test_archive_util.ArchiveUtilTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_make_tarball
def test_tarfile_vs_tar
def test_compress_deprecated
def test_make_zipfile
def test_make_zipfile_no_zlib
def test_check_archive_formats
def test_make_archive
def test_make_archive_cwd
def setUp
def tearDown
def mkdtemp
def write_file
def create_dist
def setUp
def tearDown
def get_logs
def clear_logs

Public Attributes

 old_cwd
 tempdirs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type
 threshold
 logs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _tarinfo
def _create_files

Detailed Description

Definition at line 31 of file test_archive_util.py.


Member Function Documentation

Definition at line 80 of file test_archive_util.py.

00080 
00081     def _create_files(self):
00082         # creating something to tar
00083         tmpdir = self.mkdtemp()
00084         dist = os.path.join(tmpdir, 'dist')
00085         os.mkdir(dist)
00086         self.write_file([dist, 'file1'], 'xxx')
00087         self.write_file([dist, 'file2'], 'xxx')
00088         os.mkdir(os.path.join(dist, 'sub'))
00089         self.write_file([dist, 'sub', 'file3'], 'xxx')
00090         os.mkdir(os.path.join(dist, 'sub2'))
00091         tmpdir2 = self.mkdtemp()
00092         base_name = os.path.join(tmpdir2, 'archive')
00093         return tmpdir, tmpdir2, base_name

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 71 of file test_archive_util.py.

00071 
00072     def _tarinfo(self, path):
00073         tar = tarfile.open(path)
00074         try:
00075             names = tar.getnames()
00076             names.sort()
00077             return tuple(names)
00078         finally:
00079             tar.close()

Here is the caller graph for this function:

Definition at line 45 of file support.py.

00045 
00046     def clear_logs(self):
00047         self.logs = []
00048 

Here is the caller graph for this function:

def distutils.tests.support.TempdirManager.create_dist (   self,
  pkg_name = 'foo',
  kw 
) [inherited]
Will generate a test environment.

This function creates:
 - a Distribution instance using keywords
 - a temporary directory with a package structure

It returns the package directory and the distribution
instance.

Definition at line 92 of file support.py.

00092 
00093     def create_dist(self, pkg_name='foo', **kw):
00094         """Will generate a test environment.
00095 
00096         This function creates:
00097          - a Distribution instance using keywords
00098          - a temporary directory with a package structure
00099 
00100         It returns the package directory and the distribution
00101         instance.
00102         """
00103         tmp_dir = self.mkdtemp()
00104         pkg_dir = os.path.join(tmp_dir, pkg_name)
00105         os.mkdir(pkg_dir)
00106         dist = Distribution(attrs=kw)
00107 
00108         return pkg_dir, dist
00109 

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.tests.support.LoggingSilencer.get_logs (   self,
  levels 
) [inherited]

Definition at line 37 of file support.py.

00037 
00038     def get_logs(self, *levels):
00039         def _format(msg, args):
00040             if len(args) == 0:
00041                 return msg
00042             return msg % args
00043         return [_format(msg, args) for level, msg, args
00044                 in self.logs if level in levels]

Here is the call graph for this function:

Here is the caller graph for this function:

Create a temporary directory that will be cleaned up.

Returns the path of the directory.

Definition at line 69 of file support.py.

00069 
00070     def mkdtemp(self):
00071         """Create a temporary directory that will be cleaned up.
00072 
00073         Returns the path of the directory.
00074         """
00075         d = tempfile.mkdtemp()
00076         self.tempdirs.append(d)
00077         return d

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in distutils.tests.test_upload.uploadTestCase, distutils.tests.test_register.RegisterTestCase, distutils.tests.test_config.PyPIRCCommandTestCase, distutils.tests.test_sdist.SDistTestCase, distutils.tests.test_dist.DistributionTestCase, distutils.tests.test_bdist_dumb.BuildDumbTestCase, distutils.tests.test_bdist_rpm.BuildRpmTestCase, and distutils.tests.test_config_cmd.ConfigTestCase.

Definition at line 17 of file support.py.

00017 
00018     def setUp(self):
00019         super().setUp()
00020         self.threshold = log.set_threshold(log.FATAL)
00021         # catching warnings
00022         # when log will be replaced by logging
00023         # we won't need such monkey-patch anymore
00024         self._old_log = log.Log._log
00025         log.Log._log = self._log
00026         self.logs = []

Here is the caller graph for this function:

Reimplemented in distutils.tests.test_dist.MetadataTestCase, distutils.tests.test_register.RegisterTestCase, distutils.tests.test_upload.uploadTestCase, distutils.tests.test_config.PyPIRCCommandTestCase, distutils.tests.test_sdist.SDistTestCase, distutils.tests.test_cygwinccompiler.CygwinCCompilerTestCase, distutils.tests.test_bdist_dumb.BuildDumbTestCase, distutils.tests.test_bdist_rpm.BuildRpmTestCase, distutils.tests.test_dir_util.DirUtilTestCase, distutils.tests.test_file_util.FileUtilTestCase, and distutils.tests.test_config_cmd.ConfigTestCase.

Definition at line 60 of file support.py.

00060 
00061     def tearDown(self):
00062         # Restore working dir, for Solaris and derivatives, where rmdir()
00063         # on the current directory fails.
00064         os.chdir(self.old_cwd)
00065         super().tearDown()
00066         while self.tempdirs:
00067             d = self.tempdirs.pop()
00068             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 218 of file test_archive_util.py.

00218 
00219     def test_check_archive_formats(self):
00220         self.assertEqual(check_archive_formats(['gztar', 'xxx', 'zip']),
00221                          'xxx')
00222         self.assertEqual(check_archive_formats(['gztar', 'zip']), None)

Here is the call graph for this function:

Definition at line 150 of file test_archive_util.py.

00150 
00151     def test_compress_deprecated(self):
00152         tmpdir, tmpdir2, base_name =  self._create_files()
00153 
00154         # using compress and testing the PendingDeprecationWarning
00155         old_dir = os.getcwd()
00156         os.chdir(tmpdir)
00157         try:
00158             with check_warnings() as w:
00159                 warnings.simplefilter("always")
00160                 make_tarball(base_name, 'dist', compress='compress')
00161         finally:
00162             os.chdir(old_dir)
00163         tarball = base_name + '.tar.Z'
00164         self.assertTrue(os.path.exists(tarball))
00165         self.assertEqual(len(w.warnings), 1)
00166 
00167         # same test with dry_run
00168         os.remove(tarball)
00169         old_dir = os.getcwd()
00170         os.chdir(tmpdir)
00171         try:
00172             with check_warnings() as w:
00173                 warnings.simplefilter("always")
00174                 make_tarball(base_name, 'dist', compress='compress',
00175                              dry_run=True)
00176         finally:
00177             os.chdir(old_dir)
00178         self.assertTrue(not os.path.exists(tarball))
00179         self.assertEqual(len(w.warnings), 1)

Here is the call graph for this function:

Definition at line 223 of file test_archive_util.py.

00223 
00224     def test_make_archive(self):
00225         tmpdir = self.mkdtemp()
00226         base_name = os.path.join(tmpdir, 'archive')
00227         self.assertRaises(ValueError, make_archive, base_name, 'xxx')

Here is the call graph for this function:

Definition at line 228 of file test_archive_util.py.

00228 
00229     def test_make_archive_cwd(self):
00230         current_dir = os.getcwd()
00231         def _breaks(*args, **kw):
00232             raise RuntimeError()
00233         ARCHIVE_FORMATS['xxx'] = (_breaks, [], 'xxx file')
00234         try:
00235             try:
00236                 make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
00237             except:
00238                 pass
00239             self.assertEqual(os.getcwd(), current_dir)
00240         finally:
00241             del ARCHIVE_FORMATS['xxx']

Here is the call graph for this function:

Definition at line 34 of file test_archive_util.py.

00034 
00035     def test_make_tarball(self):
00036         # creating something to tar
00037         tmpdir = self.mkdtemp()
00038         self.write_file([tmpdir, 'file1'], 'xxx')
00039         self.write_file([tmpdir, 'file2'], 'xxx')
00040         os.mkdir(os.path.join(tmpdir, 'sub'))
00041         self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
00042 
00043         tmpdir2 = self.mkdtemp()
00044         unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
00045                             "Source and target should be on same drive")
00046 
00047         base_name = os.path.join(tmpdir2, 'archive')
00048 
00049         # working with relative paths to avoid tar warnings
00050         old_dir = os.getcwd()
00051         os.chdir(tmpdir)
00052         try:
00053             make_tarball(splitdrive(base_name)[1], '.')
00054         finally:
00055             os.chdir(old_dir)
00056 
00057         # check if the compressed tarball was created
00058         tarball = base_name + '.tar.gz'
00059         self.assertTrue(os.path.exists(tarball))
00060 
00061         # trying an uncompressed one
00062         base_name = os.path.join(tmpdir2, 'archive')
00063         old_dir = os.getcwd()
00064         os.chdir(tmpdir)
00065         try:
00066             make_tarball(splitdrive(base_name)[1], '.', compress=None)
00067         finally:
00068             os.chdir(old_dir)
00069         tarball = base_name + '.tar'
00070         self.assertTrue(os.path.exists(tarball))

Here is the call graph for this function:

Definition at line 182 of file test_archive_util.py.

00182 
00183     def test_make_zipfile(self):
00184         # creating something to tar
00185         tmpdir = self.mkdtemp()
00186         self.write_file([tmpdir, 'file1'], 'xxx')
00187         self.write_file([tmpdir, 'file2'], 'xxx')
00188 
00189         tmpdir2 = self.mkdtemp()
00190         base_name = os.path.join(tmpdir2, 'archive')
00191         make_zipfile(base_name, tmpdir)
00192 
00193         # check if the compressed tarball was created
00194         tarball = base_name + '.zip'
00195         self.assertTrue(os.path.exists(tarball))

Here is the call graph for this function:

Definition at line 197 of file test_archive_util.py.

00197 
00198     def test_make_zipfile_no_zlib(self):
00199         patch(self, archive_util.zipfile, 'zlib', None)  # force zlib ImportError
00200 
00201         called = []
00202         zipfile_class = zipfile.ZipFile
00203         def fake_zipfile(*a, **kw):
00204             if kw.get('compression', None) == zipfile.ZIP_STORED:
00205                 called.append((a, kw))
00206             return zipfile_class(*a, **kw)
00207 
00208         patch(self, archive_util.zipfile, 'ZipFile', fake_zipfile)
00209 
00210         # create something to tar and compress
00211         tmpdir, tmpdir2, base_name = self._create_files()
00212         make_zipfile(base_name, tmpdir)
00213 
00214         tarball = base_name + '.zip'
00215         self.assertEqual(called,
00216                          [((tarball, "w"), {'compression': zipfile.ZIP_STORED})])
00217         self.assertTrue(os.path.exists(tarball))

Here is the call graph for this function:

Definition at line 97 of file test_archive_util.py.

00097 
00098     def test_tarfile_vs_tar(self):
00099         tmpdir, tmpdir2, base_name =  self._create_files()
00100         old_dir = os.getcwd()
00101         os.chdir(tmpdir)
00102         try:
00103             make_tarball(base_name, 'dist')
00104         finally:
00105             os.chdir(old_dir)
00106 
00107         # check if the compressed tarball was created
00108         tarball = base_name + '.tar.gz'
00109         self.assertTrue(os.path.exists(tarball))
00110 
00111         # now create another tarball using `tar`
00112         tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
00113         tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
00114         gzip_cmd = ['gzip', '-f9', 'archive2.tar']
00115         old_dir = os.getcwd()
00116         os.chdir(tmpdir)
00117         try:
00118             spawn(tar_cmd)
00119             spawn(gzip_cmd)
00120         finally:
00121             os.chdir(old_dir)
00122 
00123         self.assertTrue(os.path.exists(tarball2))
00124         # let's compare both tarballs
00125         self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
00126 
00127         # trying an uncompressed one
00128         base_name = os.path.join(tmpdir2, 'archive')
00129         old_dir = os.getcwd()
00130         os.chdir(tmpdir)
00131         try:
00132             make_tarball(base_name, 'dist', compress=None)
00133         finally:
00134             os.chdir(old_dir)
00135         tarball = base_name + '.tar'
00136         self.assertTrue(os.path.exists(tarball))
00137 
00138         # now for a dry_run
00139         base_name = os.path.join(tmpdir2, 'archive')
00140         old_dir = os.getcwd()
00141         os.chdir(tmpdir)
00142         try:
00143             make_tarball(base_name, 'dist', compress=None, dry_run=True)
00144         finally:
00145             os.chdir(old_dir)
00146         tarball = base_name + '.tar'
00147         self.assertTrue(os.path.exists(tarball))

Here is the call graph for this function:

def distutils.tests.support.TempdirManager.write_file (   self,
  path,
  content = 'xxx' 
) [inherited]
Writes a file in the given path.


path can be a string or a sequence.

Definition at line 78 of file support.py.

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

Here is the caller graph for this function:


Member Data Documentation

Definition at line 25 of file support.py.

Definition at line 107 of file object.h.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 57 of file support.py.

Definition at line 58 of file support.py.

Definition at line 19 of file support.py.


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