Back to index

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

List of all members.

Public Member Functions

def setUp
def tearDown
def get_cmd
def test_prune_file_list
def test_make_distribution
def test_add_defaults
def test_metadata_check_option
def test_check_metadata_deprecated
def test_show_formats
def test_finalize_options
def test_get_file_list
def test_manifest_marker
def test_manifest_comments
def test_manual_manifest
def test_server_registration
def test_server_empty_registration
def mkdtemp
def write_file
def create_dist
def get_logs
def clear_logs

Public Attributes

 old_path
 tmp_dir
 rc
 dist
 old_threshold
 old_cwd
 tempdirs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type
struct _typeobjectob_type
struct _typeobjectob_type
 threshold
 logs
 old_environ

Detailed Description

Definition at line 48 of file test_sdist.py.


Member Function Documentation

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.test_sdist.SDistTestCase.get_cmd (   self,
  metadata = None 
)
Returns a cmd

Definition at line 69 of file test_sdist.py.

00069 
00070     def get_cmd(self, metadata=None):
00071         """Returns a cmd"""
00072         if metadata is None:
00073             metadata = {'name': 'fake', 'version': '1.0',
00074                         'url': 'xxx', 'author': 'xxx',
00075                         'author_email': 'xxx'}
00076         dist = Distribution(metadata)
00077         dist.script_name = 'setup.py'
00078         dist.packages = ['somecode']
00079         dist.include_package_data = True
00080         cmd = sdist(dist)
00081         cmd.dist_dir = 'dist'
00082         def _warn(*args):
00083             pass
00084         cmd.warn = _warn
00085         return dist, cmd

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:

Patches the environment.

Reimplemented from distutils.tests.test_config.PyPIRCCommandTestCase.

Definition at line 50 of file test_sdist.py.

00050 
00051     def setUp(self):
00052         # PyPIRCCommandTestCase creates a temp dir already
00053         # and put it in self.tmp_dir
00054         super(SDistTestCase, self).setUp()
00055         # setting up an environment
00056         self.old_path = os.getcwd()
00057         os.mkdir(join(self.tmp_dir, 'somecode'))
00058         os.mkdir(join(self.tmp_dir, 'dist'))
00059         # a package, and a README
00060         self.write_file((self.tmp_dir, 'README'), 'xxx')
00061         self.write_file((self.tmp_dir, 'somecode', '__init__.py'), '#')
00062         self.write_file((self.tmp_dir, 'setup.py'), SETUP_PY)
00063         os.chdir(self.tmp_dir)

Here is the caller graph for this function:

Removes the patch.

Reimplemented from distutils.tests.test_config.PyPIRCCommandTestCase.

Definition at line 64 of file test_sdist.py.

00064 
00065     def tearDown(self):
00066         # back to normal
00067         os.chdir(self.old_path)
00068         super(SDistTestCase, self).tearDown()

Here is the caller graph for this function:

Definition at line 164 of file test_sdist.py.

00164 
00165     def test_add_defaults(self):
00166 
00167         # http://bugs.python.org/issue2279
00168 
00169         # add_default should also include
00170         # data_files and package_data
00171         dist, cmd = self.get_cmd()
00172 
00173         # filling data_files by pointing files
00174         # in package_data
00175         dist.package_data = {'': ['*.cfg', '*.dat'],
00176                              'somecode': ['*.txt']}
00177         self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
00178         self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#')
00179 
00180         # adding some data in data_files
00181         data_dir = join(self.tmp_dir, 'data')
00182         os.mkdir(data_dir)
00183         self.write_file((data_dir, 'data.dt'), '#')
00184         some_dir = join(self.tmp_dir, 'some')
00185         os.mkdir(some_dir)
00186         self.write_file((self.tmp_dir, 'inroot.txt'), '#')
00187         self.write_file((some_dir, 'file.txt'), '#')
00188         self.write_file((some_dir, 'other_file.txt'), '#')
00189 
00190         dist.data_files = [('data', ['data/data.dt',
00191                                      'inroot.txt',
00192                                      'notexisting']),
00193                            'some/file.txt',
00194                            'some/other_file.txt']
00195 
00196         # adding a script
00197         script_dir = join(self.tmp_dir, 'scripts')
00198         os.mkdir(script_dir)
00199         self.write_file((script_dir, 'script.py'), '#')
00200         dist.scripts = [join('scripts', 'script.py')]
00201 
00202         cmd.formats = ['zip']
00203         cmd.use_defaults = True
00204 
00205         cmd.ensure_finalized()
00206         cmd.run()
00207 
00208         # now let's check what we have
00209         dist_folder = join(self.tmp_dir, 'dist')
00210         files = os.listdir(dist_folder)
00211         self.assertEqual(files, ['fake-1.0.zip'])
00212 
00213         zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
00214         try:
00215             content = zip_file.namelist()
00216         finally:
00217             zip_file.close()
00218 
00219         # making sure everything was added
00220         self.assertEqual(len(content), 11)
00221 
00222         # checking the MANIFEST
00223         f = open(join(self.tmp_dir, 'MANIFEST'))
00224         try:
00225             manifest = f.read()
00226             self.assertEqual(manifest, MANIFEST % {'sep': os.sep})
00227         finally:
00228             f.close()

Here is the call graph for this function:

Definition at line 250 of file test_sdist.py.

00250 
00251     def test_check_metadata_deprecated(self):
00252         # makes sure make_metadata is deprecated
00253         dist, cmd = self.get_cmd()
00254         with check_warnings() as w:
00255             warnings.simplefilter("always")
00256             cmd.check_metadata()
00257             self.assertEqual(len(w.warnings), 1)

Here is the call graph for this function:

Definition at line 268 of file test_sdist.py.

00268 
00269     def test_finalize_options(self):
00270 
00271         dist, cmd = self.get_cmd()
00272         cmd.finalize_options()
00273 
00274         # default options set by finalize
00275         self.assertEqual(cmd.manifest, 'MANIFEST')
00276         self.assertEqual(cmd.template, 'MANIFEST.in')
00277         self.assertEqual(cmd.dist_dir, 'dist')
00278 
00279         # formats has to be a string splitable on (' ', ',') or
00280         # a stringlist
00281         cmd.formats = 1
00282         self.assertRaises(DistutilsOptionError, cmd.finalize_options)
00283         cmd.formats = ['zip']
00284         cmd.finalize_options()
00285 
00286         # formats has to be known
00287         cmd.formats = 'supazipa'
00288         self.assertRaises(DistutilsOptionError, cmd.finalize_options)

Here is the call graph for this function:

Definition at line 290 of file test_sdist.py.

00290 
00291     def test_get_file_list(self):
00292         # make sure MANIFEST is recalculated
00293         dist, cmd = self.get_cmd()
00294 
00295         # filling data_files by pointing files in package_data
00296         dist.package_data = {'somecode': ['*.txt']}
00297         self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
00298         cmd.ensure_finalized()
00299         cmd.run()
00300 
00301         f = open(cmd.manifest)
00302         try:
00303             manifest = [line.strip() for line in f.read().split('\n')
00304                         if line.strip() != '']
00305         finally:
00306             f.close()
00307 
00308         self.assertEqual(len(manifest), 5)
00309 
00310         # adding a file
00311         self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
00312 
00313         # make sure build_py is reinitialized, like a fresh run
00314         build_py = dist.get_command_obj('build_py')
00315         build_py.finalized = False
00316         build_py.ensure_finalized()
00317 
00318         cmd.run()
00319 
00320         f = open(cmd.manifest)
00321         try:
00322             manifest2 = [line.strip() for line in f.read().split('\n')
00323                          if line.strip() != '']
00324         finally:
00325             f.close()
00326 
00327         # do we have the new file in MANIFEST ?
00328         self.assertEqual(len(manifest2), 6)
00329         self.assertIn('doc2.txt', manifest2[-1])

Here is the call graph for this function:

Definition at line 129 of file test_sdist.py.

00129 
00130     def test_make_distribution(self):
00131 
00132         # check if tar and gzip are installed
00133         if (find_executable('tar') is None or
00134             find_executable('gzip') is None):
00135             return
00136 
00137         # now building a sdist
00138         dist, cmd = self.get_cmd()
00139 
00140         # creating a gztar then a tar
00141         cmd.formats = ['gztar', 'tar']
00142         cmd.ensure_finalized()
00143         cmd.run()
00144 
00145         # making sure we have two files
00146         dist_folder = join(self.tmp_dir, 'dist')
00147         result = os.listdir(dist_folder)
00148         result.sort()
00149         self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'] )
00150 
00151         os.remove(join(dist_folder, 'fake-1.0.tar'))
00152         os.remove(join(dist_folder, 'fake-1.0.tar.gz'))
00153 
00154         # now trying a tar then a gztar
00155         cmd.formats = ['tar', 'gztar']
00156 
00157         cmd.ensure_finalized()
00158         cmd.run()
00159 
00160         result = os.listdir(dist_folder)
00161         result.sort()
00162         self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])

Here is the call graph for this function:

Definition at line 348 of file test_sdist.py.

00348 
00349     def test_manifest_comments(self):
00350         # make sure comments don't cause exceptions or wrong includes
00351         contents = dedent("""\
00352             # bad.py
00353             #bad.py
00354             good.py
00355             """)
00356         dist, cmd = self.get_cmd()
00357         cmd.ensure_finalized()
00358         self.write_file((self.tmp_dir, cmd.manifest), contents)
00359         self.write_file((self.tmp_dir, 'good.py'), '# pick me!')
00360         self.write_file((self.tmp_dir, 'bad.py'), "# don't pick me!")
00361         self.write_file((self.tmp_dir, '#bad.py'), "# don't pick me!")
00362         cmd.run()
00363         self.assertEqual(cmd.filelist.files, ['good.py'])

Here is the call graph for this function:

Definition at line 331 of file test_sdist.py.

00331 
00332     def test_manifest_marker(self):
00333         # check that autogenerated MANIFESTs have a marker
00334         dist, cmd = self.get_cmd()
00335         cmd.ensure_finalized()
00336         cmd.run()
00337 
00338         f = open(cmd.manifest)
00339         try:
00340             manifest = [line.strip() for line in f.read().split('\n')
00341                         if line.strip() != '']
00342         finally:
00343             f.close()
00344 
00345         self.assertEqual(manifest[0],
00346                          '# file GENERATED by distutils, do NOT edit')

Here is the call graph for this function:

Definition at line 365 of file test_sdist.py.

00365 
00366     def test_manual_manifest(self):
00367         # check that a MANIFEST without a marker is left alone
00368         dist, cmd = self.get_cmd()
00369         cmd.formats = ['gztar']
00370         cmd.ensure_finalized()
00371         self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
00372         self.write_file((self.tmp_dir, 'README.manual'),
00373                          'This project maintains its MANIFEST file itself.')
00374         cmd.run()
00375         self.assertEqual(cmd.filelist.files, ['README.manual'])
00376 
00377         f = open(cmd.manifest)
00378         try:
00379             manifest = [line.strip() for line in f.read().split('\n')
00380                         if line.strip() != '']
00381         finally:
00382             f.close()
00383 
00384         self.assertEqual(manifest, ['README.manual'])
00385 
00386         archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
00387         archive = tarfile.open(archive_name)
00388         try:
00389             filenames = [tarinfo.name for tarinfo in archive]
00390         finally:
00391             archive.close()
00392         self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO',
00393                                              'fake-1.0/README.manual'])

Here is the call graph for this function:

Definition at line 230 of file test_sdist.py.

00230 
00231     def test_metadata_check_option(self):
00232         # testing the `medata-check` option
00233         dist, cmd = self.get_cmd(metadata={})
00234 
00235         # this should raise some warnings !
00236         # with the `check` subcommand
00237         cmd.ensure_finalized()
00238         cmd.run()
00239         warnings = self.get_logs(WARN)
00240         self.assertEqual(len(warnings), 2)
00241 
00242         # trying with a complete set of metadata
00243         self.clear_logs()
00244         dist, cmd = self.get_cmd()
00245         cmd.ensure_finalized()
00246         cmd.metadata_check = 0
00247         cmd.run()
00248         warnings = self.get_logs(WARN)
00249         self.assertEqual(len(warnings), 0)

Here is the call graph for this function:

Definition at line 87 of file test_sdist.py.

00087 
00088     def test_prune_file_list(self):
00089         # this test creates a package with some vcs dirs in it
00090         # and launch sdist to make sure they get pruned
00091         # on all systems
00092 
00093         # creating VCS directories with some files in them
00094         os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
00095         self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
00096 
00097         os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
00098         self.write_file((self.tmp_dir, 'somecode', '.hg',
00099                          'ok'), 'xxx')
00100 
00101         os.mkdir(join(self.tmp_dir, 'somecode', '.git'))
00102         self.write_file((self.tmp_dir, 'somecode', '.git',
00103                          'ok'), 'xxx')
00104 
00105         # now building a sdist
00106         dist, cmd = self.get_cmd()
00107 
00108         # zip is available universally
00109         # (tar might not be installed under win32)
00110         cmd.formats = ['zip']
00111 
00112         cmd.ensure_finalized()
00113         cmd.run()
00114 
00115         # now let's check what we have
00116         dist_folder = join(self.tmp_dir, 'dist')
00117         files = os.listdir(dist_folder)
00118         self.assertEqual(files, ['fake-1.0.zip'])
00119 
00120         zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
00121         try:
00122             content = zip_file.namelist()
00123         finally:
00124             zip_file.close()
00125 
00126         # making sure everything has been pruned correctly
00127         self.assertEqual(len(content), 4)

Here is the call graph for this function:

Definition at line 103 of file test_config.py.

00103 
00104     def test_server_empty_registration(self):
00105         cmd = self._cmd(self.dist)
00106         rc = cmd._get_rc_file()
00107         self.assertTrue(not os.path.exists(rc))
00108         cmd._store_pypirc('tarek', 'xxx')
00109         self.assertTrue(os.path.exists(rc))
00110         f = open(rc)
00111         try:
00112             content = f.read()
00113             self.assertEqual(content, WANTED)
00114         finally:
00115             f.close()

Here is the call graph for this function:

Definition at line 78 of file test_config.py.

00078 
00079     def test_server_registration(self):
00080         # This test makes sure PyPIRCCommand knows how to:
00081         # 1. handle several sections in .pypirc
00082         # 2. handle the old format
00083 
00084         # new format
00085         self.write_file(self.rc, PYPIRC)
00086         cmd = self._cmd(self.dist)
00087         config = cmd._read_pypirc()
00088 
00089         config = list(sorted(config.items()))
00090         waited = [('password', 'secret'), ('realm', 'pypi'),
00091                   ('repository', 'http://pypi.python.org/pypi'),
00092                   ('server', 'server1'), ('username', 'me')]
00093         self.assertEqual(config, waited)
00094 
00095         # old format
00096         self.write_file(self.rc, PYPIRC_OLD)
00097         config = cmd._read_pypirc()
00098         config = list(sorted(config.items()))
00099         waited = [('password', 'secret'), ('realm', 'pypi'),
00100                   ('repository', 'http://pypi.python.org/pypi'),
00101                   ('server', 'server-login'), ('username', 'tarek')]
00102         self.assertEqual(config, waited)

Here is the call graph for this function:

Definition at line 258 of file test_sdist.py.

00258 
00259     def test_show_formats(self):
00260         with captured_stdout() as stdout:
00261             show_formats()
00262 
00263         # the output should be a header line + one line per format
00264         num_formats = len(ARCHIVE_FORMATS.keys())
00265         output = [line for line in stdout.getvalue().split('\n')
00266                   if line.strip().startswith('--formats=')]
00267         self.assertEqual(len(output), num_formats)

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 61 of file test_config.py.

Definition at line 25 of file support.py.

Definition at line 107 of file object.h.

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.

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 125 of file support.py.

Definition at line 55 of file test_sdist.py.

Definition at line 71 of file test_config.py.

Definition at line 60 of file test_config.py.

Definition at line 58 of file support.py.

Definition at line 19 of file support.py.

Definition at line 58 of file test_config.py.


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