summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_sdist.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/tests/test_sdist.py')
-rw-r--r--Lib/distutils/tests/test_sdist.py137
1 files changed, 95 insertions, 42 deletions
diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py
index b2e9800..de58811 100644
--- a/Lib/distutils/tests/test_sdist.py
+++ b/Lib/distutils/tests/test_sdist.py
@@ -12,6 +12,7 @@ from distutils.core import Distribution
from distutils.tests.test_config import PyPIRCCommandTestCase
from distutils.errors import DistutilsExecError
from distutils.spawn import find_executable
+from distutils.tests import support
SETUP_PY = """
from distutils.core import setup
@@ -20,13 +21,20 @@ import somecode
setup(name='fake')
"""
-MANIFEST_IN = """
-recursive-include somecode *
+MANIFEST = """\
+README
+setup.py
+data/data.dt
+scripts/script.py
+somecode/__init__.py
+somecode/doc.dat
+somecode/doc.txt
"""
-class sdistTestCase(PyPIRCCommandTestCase):
+class sdistTestCase(support.LoggingSilencer, PyPIRCCommandTestCase):
def setUp(self):
+ support.LoggingSilencer.setUp(self)
# PyPIRCCommandTestCase creates a temp dir already
# and put it in self.tmp_dir
PyPIRCCommandTestCase.setUp(self)
@@ -34,24 +42,34 @@ class sdistTestCase(PyPIRCCommandTestCase):
self.old_path = os.getcwd()
os.mkdir(join(self.tmp_dir, 'somecode'))
os.mkdir(join(self.tmp_dir, 'dist'))
- # creating a MANIFEST, a package, and a README
- self._write(join(self.tmp_dir, 'MANIFEST.in'), MANIFEST_IN)
- self._write(join(self.tmp_dir, 'README'), 'xxx')
- self._write(join(self.tmp_dir, 'somecode', '__init__.py'), '#')
- self._write(join(self.tmp_dir, 'setup.py'), SETUP_PY)
+ # a package, and a README
+ self.write_file((self.tmp_dir, 'README'), 'xxx')
+ self.write_file((self.tmp_dir, 'somecode', '__init__.py'), '#')
+ self.write_file((self.tmp_dir, 'setup.py'), SETUP_PY)
os.chdir(self.tmp_dir)
def tearDown(self):
# back to normal
os.chdir(self.old_path)
PyPIRCCommandTestCase.tearDown(self)
-
- def _write(self, path, content):
- f = open(path, 'w')
- try:
- f.write(content)
- finally:
- f.close()
+ support.LoggingSilencer.tearDown(self)
+
+ def get_cmd(self, metadata=None):
+ """Returns a cmd"""
+ if metadata is None:
+ metadata = {'name': 'fake', 'version': '1.0',
+ 'url': 'xxx', 'author': 'xxx',
+ 'author_email': 'xxx'}
+ dist = Distribution(metadata)
+ dist.script_name = 'setup.py'
+ dist.packages = ['somecode']
+ dist.include_package_data = True
+ cmd = sdist(dist)
+ cmd.dist_dir = 'dist'
+ def _warn(*args):
+ pass
+ cmd.warn = _warn
+ return dist, cmd
def test_prune_file_list(self):
# this test creates a package with some vcs dirs in it
@@ -60,33 +78,24 @@ class sdistTestCase(PyPIRCCommandTestCase):
# creating VCS directories with some files in them
os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
- self._write(join(self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
+ self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
- self._write(join(self.tmp_dir, 'somecode', '.hg',
+ self.write_file((self.tmp_dir, 'somecode', '.hg',
'ok'), 'xxx')
os.mkdir(join(self.tmp_dir, 'somecode', '.git'))
- self._write(join(self.tmp_dir, 'somecode', '.git',
+ self.write_file((self.tmp_dir, 'somecode', '.git',
'ok'), 'xxx')
# now building a sdist
- dist = Distribution()
- dist.script_name = 'setup.py'
- dist.metadata.name = 'fake'
- dist.metadata.version = '1.0'
- dist.metadata.url = 'http://xxx'
- dist.metadata.author = dist.metadata.author_email = 'xxx'
- dist.packages = ['somecode']
- dist.include_package_data = True
- cmd = sdist(dist)
- cmd.manifest = 'MANIFEST'
- cmd.template = 'MANIFEST.in'
- cmd.dist_dir = 'dist'
+ dist, cmd = self.get_cmd()
# zip is available universally
# (tar might not be installed under win32)
cmd.formats = ['zip']
+
+ cmd.ensure_finalized()
cmd.run()
# now let's check what we have
@@ -111,21 +120,11 @@ class sdistTestCase(PyPIRCCommandTestCase):
return
# now building a sdist
- dist = Distribution()
- dist.script_name = 'setup.py'
- dist.metadata.name = 'fake'
- dist.metadata.version = '1.0'
- dist.metadata.url = 'http://xxx'
- dist.metadata.author = dist.metadata.author_email = 'xxx'
- dist.packages = ['somecode']
- dist.include_package_data = True
- cmd = sdist(dist)
- cmd.manifest = 'MANIFEST'
- cmd.template = 'MANIFEST.in'
- cmd.dist_dir = 'dist'
+ dist, cmd = self.get_cmd()
# creating a gztar then a tar
cmd.formats = ['gztar', 'tar']
+ cmd.ensure_finalized()
cmd.run()
# making sure we have two files
@@ -140,6 +139,8 @@ class sdistTestCase(PyPIRCCommandTestCase):
# now trying a tar then a gztar
cmd.formats = ['tar', 'gztar']
+
+ cmd.ensure_finalized()
cmd.run()
result = os.listdir(dist_folder)
@@ -147,6 +148,58 @@ class sdistTestCase(PyPIRCCommandTestCase):
self.assertEquals(result,
['fake-1.0.tar', 'fake-1.0.tar.gz'])
+ def test_add_defaults(self):
+
+ # http://bugs.python.org/issue2279
+
+ # add_default should also include
+ # data_files and package_data
+ dist, cmd = self.get_cmd()
+
+ # filling data_files by pointing files
+ # in package_data
+ dist.package_data = {'': ['*.cfg', '*.dat'],
+ 'somecode': ['*.txt']}
+ self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
+ self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#')
+
+ # adding some data in data_files
+ data_dir = join(self.tmp_dir, 'data')
+ os.mkdir(data_dir)
+ self.write_file((data_dir, 'data.dt'), '#')
+ dist.data_files = [('data', ['data.dt'])]
+
+ # adding a script
+ script_dir = join(self.tmp_dir, 'scripts')
+ os.mkdir(script_dir)
+ self.write_file((script_dir, 'script.py'), '#')
+ dist.scripts = [join('scripts', 'script.py')]
+
+
+ cmd.formats = ['zip']
+ cmd.use_defaults = True
+
+ cmd.ensure_finalized()
+ cmd.run()
+
+ # now let's check what we have
+ dist_folder = join(self.tmp_dir, 'dist')
+ files = os.listdir(dist_folder)
+ self.assertEquals(files, ['fake-1.0.zip'])
+
+ zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
+ try:
+ content = zip_file.namelist()
+ finally:
+ zip_file.close()
+
+ # making sure everything was added
+ self.assertEquals(len(content), 8)
+
+ # checking the MANIFEST
+ manifest = open(join(self.tmp_dir, 'MANIFEST')).read()
+ self.assertEquals(manifest, MANIFEST)
+
def test_suite():
return unittest.makeSuite(sdistTestCase)