2009-01-03 20:04:49 -04:00
|
|
|
"""Tests for distutils.command.sdist."""
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import shutil
|
|
|
|
import zipfile
|
|
|
|
from os.path import join
|
2009-01-25 19:34:00 -04:00
|
|
|
import sys
|
2009-02-14 10:10:23 -04:00
|
|
|
import tempfile
|
2009-01-03 20:04:49 -04:00
|
|
|
|
|
|
|
from distutils.command.sdist import sdist
|
|
|
|
from distutils.core import Distribution
|
|
|
|
from distutils.tests.test_config import PyPIRCCommandTestCase
|
2009-01-25 19:34:00 -04:00
|
|
|
from distutils.errors import DistutilsExecError
|
2009-01-29 19:49:17 -04:00
|
|
|
from distutils.spawn import find_executable
|
2009-02-16 17:38:01 -04:00
|
|
|
from distutils.tests import support
|
2009-01-03 20:04:49 -04:00
|
|
|
|
|
|
|
SETUP_PY = """
|
|
|
|
from distutils.core import setup
|
|
|
|
import somecode
|
|
|
|
|
|
|
|
setup(name='fake')
|
|
|
|
"""
|
|
|
|
|
2009-02-16 17:38:01 -04:00
|
|
|
MANIFEST = """\
|
|
|
|
README
|
|
|
|
setup.py
|
|
|
|
data/data.dt
|
|
|
|
scripts/script.py
|
|
|
|
somecode/__init__.py
|
|
|
|
somecode/doc.dat
|
|
|
|
somecode/doc.txt
|
2009-01-03 20:04:49 -04:00
|
|
|
"""
|
|
|
|
|
2009-02-16 17:38:01 -04:00
|
|
|
class sdistTestCase(support.LoggingSilencer, PyPIRCCommandTestCase):
|
2009-01-03 20:04:49 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2009-02-16 17:38:01 -04:00
|
|
|
support.LoggingSilencer.setUp(self)
|
2009-02-14 10:10:23 -04:00
|
|
|
# PyPIRCCommandTestCase creates a temp dir already
|
|
|
|
# and put it in self.tmp_dir
|
2009-01-03 20:04:49 -04:00
|
|
|
PyPIRCCommandTestCase.setUp(self)
|
2009-02-14 10:10:23 -04:00
|
|
|
# setting up an environment
|
2009-01-03 20:04:49 -04:00
|
|
|
self.old_path = os.getcwd()
|
2009-02-14 10:10:23 -04:00
|
|
|
os.mkdir(join(self.tmp_dir, 'somecode'))
|
|
|
|
os.mkdir(join(self.tmp_dir, 'dist'))
|
2009-02-16 17:38:01 -04:00
|
|
|
# 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)
|
2009-02-14 10:10:23 -04:00
|
|
|
os.chdir(self.tmp_dir)
|
2009-01-03 20:04:49 -04:00
|
|
|
|
|
|
|
def tearDown(self):
|
2009-02-14 10:10:23 -04:00
|
|
|
# back to normal
|
2009-01-03 20:04:49 -04:00
|
|
|
os.chdir(self.old_path)
|
|
|
|
PyPIRCCommandTestCase.tearDown(self)
|
2009-02-16 17:38:01 -04:00
|
|
|
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
|
2009-01-03 20:04:49 -04:00
|
|
|
|
|
|
|
def test_prune_file_list(self):
|
|
|
|
# this test creates a package with some vcs dirs in it
|
|
|
|
# and launch sdist to make sure they get pruned
|
|
|
|
# on all systems
|
|
|
|
|
|
|
|
# creating VCS directories with some files in them
|
2009-02-14 10:10:23 -04:00
|
|
|
os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
|
2009-02-16 17:38:01 -04:00
|
|
|
self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
|
2009-01-03 20:04:49 -04:00
|
|
|
|
2009-02-14 10:10:23 -04:00
|
|
|
os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
|
2009-02-16 17:38:01 -04:00
|
|
|
self.write_file((self.tmp_dir, 'somecode', '.hg',
|
2009-01-03 20:04:49 -04:00
|
|
|
'ok'), 'xxx')
|
|
|
|
|
2009-02-14 10:10:23 -04:00
|
|
|
os.mkdir(join(self.tmp_dir, 'somecode', '.git'))
|
2009-02-16 17:38:01 -04:00
|
|
|
self.write_file((self.tmp_dir, 'somecode', '.git',
|
2009-01-03 20:04:49 -04:00
|
|
|
'ok'), 'xxx')
|
|
|
|
|
|
|
|
# now building a sdist
|
2009-02-16 17:38:01 -04:00
|
|
|
dist, cmd = self.get_cmd()
|
2009-01-03 20:04:49 -04:00
|
|
|
|
|
|
|
# zip is available universally
|
|
|
|
# (tar might not be installed under win32)
|
|
|
|
cmd.formats = ['zip']
|
2009-02-16 17:38:01 -04:00
|
|
|
|
|
|
|
cmd.ensure_finalized()
|
2009-01-03 20:04:49 -04:00
|
|
|
cmd.run()
|
|
|
|
|
|
|
|
# now let's check what we have
|
2009-02-14 10:10:23 -04:00
|
|
|
dist_folder = join(self.tmp_dir, 'dist')
|
2009-01-03 20:04:49 -04:00
|
|
|
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 has been pruned correctly
|
|
|
|
self.assertEquals(len(content), 4)
|
|
|
|
|
2009-01-25 19:34:00 -04:00
|
|
|
def test_make_distribution(self):
|
|
|
|
|
2009-01-29 19:49:17 -04:00
|
|
|
# check if tar and gzip are installed
|
|
|
|
if (find_executable('tar') is None or
|
|
|
|
find_executable('gzip') is None):
|
|
|
|
return
|
2009-01-25 19:34:00 -04:00
|
|
|
|
|
|
|
# now building a sdist
|
2009-02-16 17:38:01 -04:00
|
|
|
dist, cmd = self.get_cmd()
|
2009-01-25 19:34:00 -04:00
|
|
|
|
|
|
|
# creating a gztar then a tar
|
|
|
|
cmd.formats = ['gztar', 'tar']
|
2009-02-16 17:38:01 -04:00
|
|
|
cmd.ensure_finalized()
|
2009-01-25 19:34:00 -04:00
|
|
|
cmd.run()
|
|
|
|
|
|
|
|
# making sure we have two files
|
2009-02-14 10:10:23 -04:00
|
|
|
dist_folder = join(self.tmp_dir, 'dist')
|
2009-01-25 19:34:00 -04:00
|
|
|
result = os.listdir(dist_folder)
|
|
|
|
result.sort()
|
|
|
|
self.assertEquals(result,
|
|
|
|
['fake-1.0.tar', 'fake-1.0.tar.gz'] )
|
|
|
|
|
|
|
|
os.remove(join(dist_folder, 'fake-1.0.tar'))
|
|
|
|
os.remove(join(dist_folder, 'fake-1.0.tar.gz'))
|
|
|
|
|
|
|
|
# now trying a tar then a gztar
|
|
|
|
cmd.formats = ['tar', 'gztar']
|
2009-02-16 17:38:01 -04:00
|
|
|
|
|
|
|
cmd.ensure_finalized()
|
2009-01-25 19:34:00 -04:00
|
|
|
cmd.run()
|
|
|
|
|
|
|
|
result = os.listdir(dist_folder)
|
|
|
|
result.sort()
|
|
|
|
self.assertEquals(result,
|
|
|
|
['fake-1.0.tar', 'fake-1.0.tar.gz'])
|
|
|
|
|
2009-02-16 17:38:01 -04:00
|
|
|
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)
|
|
|
|
|
2009-01-03 20:04:49 -04:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(sdistTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main(defaultTest="test_suite")
|