Synchronize some distutils tests with 3.2.
- Actually check the contents of the file created by bdist_dumb. - Don’t use “RECORD” as filename for non-PEP 376 record file - Don’t start method name with “_test”, it looks like a disabled test method instead of an helper method - Fix some idioms (assertIn, addCleanup)
This commit is contained in:
parent
7f4b3be2cc
commit
ae50babe32
|
@ -1,8 +1,10 @@
|
||||||
"""Tests for distutils.command.bdist_dumb."""
|
"""Tests for distutils.command.bdist_dumb."""
|
||||||
|
|
||||||
import unittest
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import zipfile
|
||||||
|
import unittest
|
||||||
|
from test.test_support import run_unittest
|
||||||
|
|
||||||
# zlib is not used here, but if it's not available
|
# zlib is not used here, but if it's not available
|
||||||
# test_simple_built will fail
|
# test_simple_built will fail
|
||||||
|
@ -11,8 +13,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
zlib = None
|
zlib = None
|
||||||
|
|
||||||
from test.test_support import run_unittest
|
|
||||||
|
|
||||||
from distutils.core import Distribution
|
from distutils.core import Distribution
|
||||||
from distutils.command.bdist_dumb import bdist_dumb
|
from distutils.command.bdist_dumb import bdist_dumb
|
||||||
from distutils.tests import support
|
from distutils.tests import support
|
||||||
|
@ -73,15 +73,23 @@ class BuildDumbTestCase(support.TempdirManager,
|
||||||
|
|
||||||
# see what we have
|
# see what we have
|
||||||
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
||||||
base = "%s.%s" % (dist.get_fullname(), cmd.plat_name)
|
base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
|
||||||
if os.name == 'os2':
|
if os.name == 'os2':
|
||||||
base = base.replace(':', '-')
|
base = base.replace(':', '-')
|
||||||
|
|
||||||
wanted = ['%s.zip' % base]
|
self.assertEqual(dist_created, [base])
|
||||||
self.assertEqual(dist_created, wanted)
|
|
||||||
|
|
||||||
# now let's check what we have in the zip file
|
# now let's check what we have in the zip file
|
||||||
# XXX to be done
|
fp = zipfile.ZipFile(os.path.join('dist', base))
|
||||||
|
try:
|
||||||
|
contents = fp.namelist()
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
contents = sorted(os.path.basename(fn) for fn in contents)
|
||||||
|
wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2],
|
||||||
|
'foo.py', 'foo.pyc']
|
||||||
|
self.assertEqual(contents, sorted(wanted))
|
||||||
|
|
||||||
def test_finalize_options(self):
|
def test_finalize_options(self):
|
||||||
pkg_dir, dist = self.create_dist()
|
pkg_dir, dist = self.create_dist()
|
||||||
|
|
|
@ -86,19 +86,17 @@ class InstallTestCase(support.TempdirManager,
|
||||||
self.old_expand = os.path.expanduser
|
self.old_expand = os.path.expanduser
|
||||||
os.path.expanduser = _expanduser
|
os.path.expanduser = _expanduser
|
||||||
|
|
||||||
try:
|
def cleanup():
|
||||||
# this is the actual test
|
|
||||||
self._test_user_site()
|
|
||||||
finally:
|
|
||||||
site.USER_BASE = self.old_user_base
|
site.USER_BASE = self.old_user_base
|
||||||
site.USER_SITE = self.old_user_site
|
site.USER_SITE = self.old_user_site
|
||||||
install_module.USER_BASE = self.old_user_base
|
install_module.USER_BASE = self.old_user_base
|
||||||
install_module.USER_SITE = self.old_user_site
|
install_module.USER_SITE = self.old_user_site
|
||||||
os.path.expanduser = self.old_expand
|
os.path.expanduser = self.old_expand
|
||||||
|
|
||||||
def _test_user_site(self):
|
self.addCleanup(cleanup)
|
||||||
|
|
||||||
for key in ('nt_user', 'unix_user', 'os2_home'):
|
for key in ('nt_user', 'unix_user', 'os2_home'):
|
||||||
self.assertTrue(key in INSTALL_SCHEMES)
|
self.assertIn(key, INSTALL_SCHEMES)
|
||||||
|
|
||||||
dist = Distribution({'name': 'xx'})
|
dist = Distribution({'name': 'xx'})
|
||||||
cmd = install(dist)
|
cmd = install(dist)
|
||||||
|
@ -106,14 +104,14 @@ class InstallTestCase(support.TempdirManager,
|
||||||
# making sure the user option is there
|
# making sure the user option is there
|
||||||
options = [name for name, short, lable in
|
options = [name for name, short, lable in
|
||||||
cmd.user_options]
|
cmd.user_options]
|
||||||
self.assertTrue('user' in options)
|
self.assertIn('user', options)
|
||||||
|
|
||||||
# setting a value
|
# setting a value
|
||||||
cmd.user = 1
|
cmd.user = 1
|
||||||
|
|
||||||
# user base and site shouldn't be created yet
|
# user base and site shouldn't be created yet
|
||||||
self.assertTrue(not os.path.exists(self.user_base))
|
self.assertFalse(os.path.exists(self.user_base))
|
||||||
self.assertTrue(not os.path.exists(self.user_site))
|
self.assertFalse(os.path.exists(self.user_site))
|
||||||
|
|
||||||
# let's run finalize
|
# let's run finalize
|
||||||
cmd.ensure_finalized()
|
cmd.ensure_finalized()
|
||||||
|
@ -122,8 +120,8 @@ class InstallTestCase(support.TempdirManager,
|
||||||
self.assertTrue(os.path.exists(self.user_base))
|
self.assertTrue(os.path.exists(self.user_base))
|
||||||
self.assertTrue(os.path.exists(self.user_site))
|
self.assertTrue(os.path.exists(self.user_site))
|
||||||
|
|
||||||
self.assertTrue('userbase' in cmd.config_vars)
|
self.assertIn('userbase', cmd.config_vars)
|
||||||
self.assertTrue('usersite' in cmd.config_vars)
|
self.assertIn('usersite', cmd.config_vars)
|
||||||
|
|
||||||
def test_handle_extra_path(self):
|
def test_handle_extra_path(self):
|
||||||
dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
|
dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
|
||||||
|
@ -176,15 +174,16 @@ class InstallTestCase(support.TempdirManager,
|
||||||
|
|
||||||
def test_record(self):
|
def test_record(self):
|
||||||
install_dir = self.mkdtemp()
|
install_dir = self.mkdtemp()
|
||||||
project_dir, dist = self.create_dist(scripts=['hello'])
|
project_dir, dist = self.create_dist(py_modules=['hello'],
|
||||||
self.addCleanup(os.chdir, os.getcwd())
|
scripts=['sayhi'])
|
||||||
os.chdir(project_dir)
|
os.chdir(project_dir)
|
||||||
self.write_file('hello', "print('o hai')")
|
self.write_file('hello.py', "def main(): print 'o hai'")
|
||||||
|
self.write_file('sayhi', 'from hello import main; main()')
|
||||||
|
|
||||||
cmd = install(dist)
|
cmd = install(dist)
|
||||||
dist.command_obj['install'] = cmd
|
dist.command_obj['install'] = cmd
|
||||||
cmd.root = install_dir
|
cmd.root = install_dir
|
||||||
cmd.record = os.path.join(project_dir, 'RECORD')
|
cmd.record = os.path.join(project_dir, 'filelist')
|
||||||
cmd.ensure_finalized()
|
cmd.ensure_finalized()
|
||||||
cmd.run()
|
cmd.run()
|
||||||
|
|
||||||
|
@ -195,7 +194,7 @@ class InstallTestCase(support.TempdirManager,
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
found = [os.path.basename(line) for line in content.splitlines()]
|
found = [os.path.basename(line) for line in content.splitlines()]
|
||||||
expected = ['hello',
|
expected = ['hello.py', 'hello.pyc', 'sayhi',
|
||||||
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
|
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
|
||||||
self.assertEqual(found, expected)
|
self.assertEqual(found, expected)
|
||||||
|
|
||||||
|
@ -203,7 +202,6 @@ class InstallTestCase(support.TempdirManager,
|
||||||
install_dir = self.mkdtemp()
|
install_dir = self.mkdtemp()
|
||||||
project_dir, dist = self.create_dist(ext_modules=[
|
project_dir, dist = self.create_dist(ext_modules=[
|
||||||
Extension('xx', ['xxmodule.c'])])
|
Extension('xx', ['xxmodule.c'])])
|
||||||
self.addCleanup(os.chdir, os.getcwd())
|
|
||||||
os.chdir(project_dir)
|
os.chdir(project_dir)
|
||||||
support.copy_xxmodule_c(project_dir)
|
support.copy_xxmodule_c(project_dir)
|
||||||
|
|
||||||
|
@ -215,7 +213,7 @@ class InstallTestCase(support.TempdirManager,
|
||||||
dist.command_obj['install'] = cmd
|
dist.command_obj['install'] = cmd
|
||||||
dist.command_obj['build_ext'] = buildextcmd
|
dist.command_obj['build_ext'] = buildextcmd
|
||||||
cmd.root = install_dir
|
cmd.root = install_dir
|
||||||
cmd.record = os.path.join(project_dir, 'RECORD')
|
cmd.record = os.path.join(project_dir, 'filelist')
|
||||||
cmd.ensure_finalized()
|
cmd.ensure_finalized()
|
||||||
cmd.run()
|
cmd.run()
|
||||||
|
|
||||||
|
@ -241,6 +239,7 @@ class InstallTestCase(support.TempdirManager,
|
||||||
install_module.DEBUG = False
|
install_module.DEBUG = False
|
||||||
self.assertTrue(len(self.logs) > old_logs_len)
|
self.assertTrue(len(self.logs) > old_logs_len)
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
return unittest.makeSuite(InstallTestCase)
|
return unittest.makeSuite(InstallTestCase)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import warnings
|
||||||
import zipfile
|
import zipfile
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
from test.test_support import captured_stdout, check_warnings, run_unittest
|
||||||
|
|
||||||
# zlib is not used here, but if it's not available
|
# zlib is not used here, but if it's not available
|
||||||
# the tests that use zipfile may fail
|
# the tests that use zipfile may fail
|
||||||
|
@ -21,7 +22,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
UID_GID_SUPPORT = False
|
UID_GID_SUPPORT = False
|
||||||
|
|
||||||
from test.test_support import captured_stdout, check_warnings, run_unittest
|
|
||||||
|
|
||||||
from distutils.command.sdist import sdist, show_formats
|
from distutils.command.sdist import sdist, show_formats
|
||||||
from distutils.core import Distribution
|
from distutils.core import Distribution
|
||||||
|
@ -375,7 +375,7 @@ class SDistTestCase(PyPIRCCommandTestCase):
|
||||||
# the following tests make sure there is a nice error message instead
|
# the following tests make sure there is a nice error message instead
|
||||||
# of a traceback when parsing an invalid manifest template
|
# of a traceback when parsing an invalid manifest template
|
||||||
|
|
||||||
def _test_template(self, content):
|
def _check_template(self, content):
|
||||||
dist, cmd = self.get_cmd()
|
dist, cmd = self.get_cmd()
|
||||||
os.chdir(self.tmp_dir)
|
os.chdir(self.tmp_dir)
|
||||||
self.write_file('MANIFEST.in', content)
|
self.write_file('MANIFEST.in', content)
|
||||||
|
@ -386,17 +386,17 @@ class SDistTestCase(PyPIRCCommandTestCase):
|
||||||
self.assertEqual(len(warnings), 1)
|
self.assertEqual(len(warnings), 1)
|
||||||
|
|
||||||
def test_invalid_template_unknown_command(self):
|
def test_invalid_template_unknown_command(self):
|
||||||
self._test_template('taunt knights *')
|
self._check_template('taunt knights *')
|
||||||
|
|
||||||
def test_invalid_template_wrong_arguments(self):
|
def test_invalid_template_wrong_arguments(self):
|
||||||
# this manifest command takes one argument
|
# this manifest command takes one argument
|
||||||
self._test_template('prune')
|
self._check_template('prune')
|
||||||
|
|
||||||
@unittest.skipIf(os.name != 'nt', 'test relevant for Windows only')
|
@unittest.skipIf(os.name != 'nt', 'test relevant for Windows only')
|
||||||
def test_invalid_template_wrong_path(self):
|
def test_invalid_template_wrong_path(self):
|
||||||
# on Windows, trailing slashes are not allowed
|
# on Windows, trailing slashes are not allowed
|
||||||
# this used to crash instead of raising a warning: #8286
|
# this used to crash instead of raising a warning: #8286
|
||||||
self._test_template('include examples/')
|
self._check_template('include examples/')
|
||||||
|
|
||||||
@unittest.skipUnless(zlib, "requires zlib")
|
@unittest.skipUnless(zlib, "requires zlib")
|
||||||
def test_get_file_list(self):
|
def test_get_file_list(self):
|
||||||
|
|
Loading…
Reference in New Issue