Brange merge

This commit is contained in:
Éric Araujo 2011-06-17 19:38:38 +02:00
commit 74d68135ad
16 changed files with 123 additions and 147 deletions

View file

@ -38,7 +38,7 @@ class build_ext(Command):
# XXX thoughts on how to deal with complex command-line options like # XXX thoughts on how to deal with complex command-line options like
# these, i.e. how to make it so fancy_getopt can suck them off the # these, i.e. how to make it so fancy_getopt can suck them off the
# command line and make it look like setup.py defined the appropriate # command line and turn them into the appropriate
# lists of tuples of what-have-you. # lists of tuples of what-have-you.
# - each command needs a callback to process its command-line options # - each command needs a callback to process its command-line options
# - Command.__init__() needs access to its share of the whole # - Command.__init__() needs access to its share of the whole
@ -287,9 +287,6 @@ class build_ext(Command):
def run(self): def run(self):
from packaging.compiler import new_compiler from packaging.compiler import new_compiler
# 'self.extensions', as supplied by setup.py, is a list of
# Extension instances. See the documentation for Extension (in
# distutils.extension) for details.
if not self.extensions: if not self.extensions:
return return

View file

@ -130,10 +130,10 @@ class MacroExpander:
raise KeyError("sdkinstallrootv2.0") raise KeyError("sdkinstallrootv2.0")
except KeyError: except KeyError:
raise PackagingPlatformError( raise PackagingPlatformError(
"""Python was built with Visual Studio 2008; """Python was built with Visual Studio 2008; extensions must be built with a
extensions must be built with a compiler than can generate compatible binaries. compiler than can generate compatible binaries. Visual Studio 2008 was not
Visual Studio 2008 was not found on this system. If you have Cygwin installed, found on this system. If you have Cygwin installed, you can try compiling
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""") with MingW32, by passing "-c mingw32" to pysetup.""")
if version >= 9.0: if version >= 9.0:
self.set_macro("FrameworkVersion", self.vsbase, "clr version") self.set_macro("FrameworkVersion", self.vsbase, "clr version")

View file

@ -134,8 +134,7 @@ class MacroExpander:
"""Python was built with Visual Studio 2003; extensions must be built with """Python was built with Visual Studio 2003; extensions must be built with
a compiler than can generate compatible binaries. Visual Studio 2003 was a compiler than can generate compatible binaries. Visual Studio 2003 was
not found on this system. If you have Cygwin installed, you can try not found on this system. If you have Cygwin installed, you can try
compiling with MingW32, by passing "-c mingw32" to setup.py.""") compiling with MingW32, by passing "-c mingw32" to pysetup.""")
# XXX update this comment for setup.cfg
p = r"Software\Microsoft\NET Framework Setup\Product" p = r"Software\Microsoft\NET Framework Setup\Product"
for base in HKEYS: for base in HKEYS:

View file

@ -33,7 +33,7 @@ import sysconfig
# we need some way for outsiders to feed preprocessor/compiler/linker # we need some way for outsiders to feed preprocessor/compiler/linker
# flags in to us -- eg. a sysadmin might want to mandate certain flags # flags in to us -- eg. a sysadmin might want to mandate certain flags
# via a site config file, or a user might want to set something for # via a site config file, or a user might want to set something for
# compiling this module distribution only via the setup.py command # compiling this module distribution only via the pysetup command
# line, whatever. As long as these options come from something on the # line, whatever. As long as these options come from something on the
# current system, they can be as system-dependent as they like, and we # current system, they can be as system-dependent as they like, and we
# should just happily stuff them into the preprocessor/compiler/linker # should just happily stuff them into the preprocessor/compiler/linker

View file

@ -72,7 +72,7 @@ def clear_cache():
_cache_generated_egg = False _cache_generated_egg = False
def _yield_distributions(include_dist, include_egg, paths=sys.path): def _yield_distributions(include_dist, include_egg, paths):
""" """
Yield .dist-info and .egg(-info) distributions, based on the arguments Yield .dist-info and .egg(-info) distributions, based on the arguments
@ -92,7 +92,7 @@ def _yield_distributions(include_dist, include_egg, paths=sys.path):
yield EggInfoDistribution(dist_path) yield EggInfoDistribution(dist_path)
def _generate_cache(use_egg_info=False, paths=sys.path): def _generate_cache(use_egg_info, paths):
global _cache_generated, _cache_generated_egg global _cache_generated, _cache_generated_egg
if _cache_generated_egg or (_cache_generated and not use_egg_info): if _cache_generated_egg or (_cache_generated and not use_egg_info):
@ -472,7 +472,7 @@ def distinfo_dirname(name, version):
return '-'.join([name, normalized_version]) + file_extension return '-'.join([name, normalized_version]) + file_extension
def get_distributions(use_egg_info=False, paths=sys.path): def get_distributions(use_egg_info=False, paths=None):
""" """
Provides an iterator that looks for ``.dist-info`` directories in Provides an iterator that looks for ``.dist-info`` directories in
``sys.path`` and returns :class:`Distribution` instances for each one of ``sys.path`` and returns :class:`Distribution` instances for each one of
@ -482,6 +482,9 @@ def get_distributions(use_egg_info=False, paths=sys.path):
:rtype: iterator of :class:`Distribution` and :class:`EggInfoDistribution` :rtype: iterator of :class:`Distribution` and :class:`EggInfoDistribution`
instances instances
""" """
if paths is None:
paths = sys.path
if not _cache_enabled: if not _cache_enabled:
for dist in _yield_distributions(True, use_egg_info, paths): for dist in _yield_distributions(True, use_egg_info, paths):
yield dist yield dist
@ -513,7 +516,7 @@ def get_distribution(name, use_egg_info=False, paths=None):
:rtype: :class:`Distribution` or :class:`EggInfoDistribution` or None :rtype: :class:`Distribution` or :class:`EggInfoDistribution` or None
""" """
if paths == None: if paths is None:
paths = sys.path paths = sys.path
if not _cache_enabled: if not _cache_enabled:
@ -632,7 +635,7 @@ def get_file_users(path):
def get_file_path(distribution_name, relative_path): def get_file_path(distribution_name, relative_path):
"""Return the path to a resource file.""" """Return the path to a resource file."""
dist = get_distribution(distribution_name) dist = get_distribution(distribution_name)
if dist != None: if dist is not None:
return dist.get_resource_path(relative_path) return dist.get_resource_path(relative_path)
raise LookupError('no distribution named %r found' % distribution_name) raise LookupError('no distribution named %r found' % distribution_name)

View file

@ -47,7 +47,7 @@ class Distribution:
# 'global_options' describes the command-line options that may be # 'global_options' describes the command-line options that may be
# supplied to the setup script prior to any actual commands. # supplied to the setup script prior to any actual commands.
# Eg. "./setup.py -n" or "./setup.py --dry-run" both take advantage of # Eg. "pysetup -n" or "pysetup --dry-run" both take advantage of
# these global options. This list should be kept to a bare minimum, # these global options. This list should be kept to a bare minimum,
# since every global option is also valid as a command option -- and we # since every global option is also valid as a command option -- and we
# don't want to pollute the commands with too many options that they # don't want to pollute the commands with too many options that they
@ -63,14 +63,15 @@ class Distribution:
common_usage = """\ common_usage = """\
Common commands: (see '--help-commands' for more) Common commands: (see '--help-commands' for more)
setup.py build will build the package underneath 'build/' pysetup run build will build the package underneath 'build/'
setup.py install will install the package pysetup run install will install the package
""" """
# options that are not propagated to the commands # options that are not propagated to the commands
display_options = [ display_options = [
('help-commands', None, ('help-commands', None,
"list all available commands"), "list all available commands"),
# XXX this is obsoleted by the pysetup metadata action
('name', None, ('name', None,
"print package name"), "print package name"),
('version', 'V', ('version', 'V',
@ -360,7 +361,7 @@ Common commands: (see '--help-commands' for more)
return return
# Handle the cases of --help as a "global" option, ie. # Handle the cases of --help as a "global" option, ie.
# "setup.py --help" and "setup.py --help command ...". For the # "pysetup run --help" and "pysetup run --help command ...". For the
# former, we show global options (--dry-run, etc.) # former, we show global options (--dry-run, etc.)
# and display-only options (--name, --version, etc.); for the # and display-only options (--name, --version, etc.); for the
# latter, we omit the display-only options and show help for # latter, we omit the display-only options and show help for

View file

@ -54,10 +54,8 @@ def _move_files(files, destination):
try: try:
os.makedirs(os.path.dirname(new)) os.makedirs(os.path.dirname(new))
except OSError as e: except OSError as e:
if e.errno == errno.EEXIST: if e.errno != errno.EEXIST:
pass raise
else:
raise e
os.rename(old, new) os.rename(old, new)
yield old, new yield old, new
@ -169,7 +167,7 @@ def _run_install_from_dir(source_dir):
os.chdir(old_dir) os.chdir(old_dir)
def install_dists(dists, path, paths=sys.path): def install_dists(dists, path, paths=None):
"""Install all distributions provided in dists, with the given prefix. """Install all distributions provided in dists, with the given prefix.
If an error occurs while installing one of the distributions, uninstall all If an error occurs while installing one of the distributions, uninstall all
@ -196,13 +194,13 @@ def install_dists(dists, path, paths=sys.path):
# reverting # reverting
for installed_dist in installed_dists: for installed_dist in installed_dists:
logger.info('Reverting %s', installed_dist) logger.info('Reverting %s', installed_dist)
_remove_dist(installed_dist, paths) remove(installed_dist.name, paths)
raise e raise e
return installed_dists return installed_dists
def install_from_infos(install_path=None, install=[], remove=[], conflicts=[], def install_from_infos(install_path=None, install=[], remove=[], conflicts=[],
paths=sys.path): paths=None):
"""Install and remove the given distributions. """Install and remove the given distributions.
The function signature is made to be compatible with the one of get_infos. The function signature is made to be compatible with the one of get_infos.
@ -383,11 +381,7 @@ def _update_infos(infos, new_infos):
infos[key].extend(new_infos[key]) infos[key].extend(new_infos[key])
def _remove_dist(dist, paths=sys.path): def remove(project_name, paths=None, auto_confirm=True):
remove(dist.name, paths)
def remove(project_name, paths=sys.path, auto_confirm=True):
"""Removes a single project from the installation. """Removes a single project from the installation.
Returns True on success Returns True on success
@ -539,7 +533,6 @@ def install(project):
def _main(**attrs): def _main(**attrs):
if 'script_args' not in attrs: if 'script_args' not in attrs:
import sys
attrs['requirements'] = sys.argv[1] attrs['requirements'] = sys.argv[1]
get_infos(**attrs) get_infos(**attrs)

View file

@ -7,15 +7,13 @@ Release objects contain metadata-related information (see PEP 376);
distribution objects contain download-related information. distribution objects contain download-related information.
""" """
import sys
import mimetypes
import re import re
import hashlib
import tempfile import tempfile
import urllib.request import urllib.request
import urllib.parse import urllib.parse
import urllib.error import urllib.error
import urllib.parse import urllib.parse
import hashlib
from shutil import unpack_archive from shutil import unpack_archive
from packaging.errors import IrrationalVersionError from packaging.errors import IrrationalVersionError
@ -318,7 +316,6 @@ class DistInfo(IndexReference):
path = tempfile.mkdtemp() path = tempfile.mkdtemp()
filename = self.download(path) filename = self.download(path)
content_type = mimetypes.guess_type(filename)[0]
unpack_archive(filename, path) unpack_archive(filename, path)
self._unpacked_dir = path self._unpacked_dir = path

View file

@ -1,7 +1,7 @@
"""Tests for distutils.command.bdist_dumb.""" """Tests for distutils.command.bdist_dumb."""
import sys
import os import os
import packaging.util
from packaging.dist import Distribution from packaging.dist import Distribution
from packaging.command.bdist_dumb import bdist_dumb from packaging.command.bdist_dumb import bdist_dumb
@ -9,15 +9,6 @@ from packaging.tests import unittest, support
from packaging.tests.support import requires_zlib from packaging.tests.support import requires_zlib
SETUP_PY = """\
from distutils.run import setup
import foo
setup(name='foo', version='0.1', py_modules=['foo'],
url='xxx', author='xxx', author_email='xxx')
"""
class BuildDumbTestCase(support.TempdirManager, class BuildDumbTestCase(support.TempdirManager,
support.LoggingCatcher, support.LoggingCatcher,
unittest.TestCase): unittest.TestCase):
@ -25,12 +16,10 @@ class BuildDumbTestCase(support.TempdirManager,
def setUp(self): def setUp(self):
super(BuildDumbTestCase, self).setUp() super(BuildDumbTestCase, self).setUp()
self.old_location = os.getcwd() self.old_location = os.getcwd()
self.old_sys_argv = sys.argv, sys.argv[:]
def tearDown(self): def tearDown(self):
os.chdir(self.old_location) os.chdir(self.old_location)
sys.argv = self.old_sys_argv[0] packaging.util._path_created.clear()
sys.argv[:] = self.old_sys_argv[1]
super(BuildDumbTestCase, self).tearDown() super(BuildDumbTestCase, self).tearDown()
@requires_zlib @requires_zlib
@ -40,7 +29,6 @@ class BuildDumbTestCase(support.TempdirManager,
tmp_dir = self.mkdtemp() tmp_dir = self.mkdtemp()
pkg_dir = os.path.join(tmp_dir, 'foo') pkg_dir = os.path.join(tmp_dir, 'foo')
os.mkdir(pkg_dir) os.mkdir(pkg_dir)
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
self.write_file((pkg_dir, 'foo.py'), '#') self.write_file((pkg_dir, 'foo.py'), '#')
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
self.write_file((pkg_dir, 'README'), '') self.write_file((pkg_dir, 'README'), '')
@ -50,8 +38,6 @@ class BuildDumbTestCase(support.TempdirManager,
'url': 'xxx', 'author': 'xxx', 'url': 'xxx', 'author': 'xxx',
'author_email': 'xxx'}) 'author_email': 'xxx'})
os.chdir(pkg_dir) os.chdir(pkg_dir)
sys.argv[:] = ['setup.py']
cmd = bdist_dumb(dist) cmd = bdist_dumb(dist)
# so the output is the same no matter # so the output is the same no matter

View file

@ -33,6 +33,14 @@ class BuildExtTestCase(support.TempdirManager,
site.USER_BASE = self.mkdtemp() site.USER_BASE = self.mkdtemp()
build_ext.USER_BASE = site.USER_BASE build_ext.USER_BASE = site.USER_BASE
def tearDown(self):
# Get everything back to normal
if sys.version > "2.6":
site.USER_BASE = self.old_user_base
build_ext.USER_BASE = self.old_user_base
super(BuildExtTestCase, self).tearDown()
def _fixup_command(self, cmd): def _fixup_command(self, cmd):
# When Python was build with --enable-shared, -L. is not good enough # When Python was build with --enable-shared, -L. is not good enough
# to find the libpython<blah>.so. This is because regrtest runs it # to find the libpython<blah>.so. This is because regrtest runs it
@ -99,14 +107,6 @@ class BuildExtTestCase(support.TempdirManager,
code = code % self.tmp_dir code = code % self.tmp_dir
assert_python_ok('-c', code) assert_python_ok('-c', code)
def tearDown(self):
# Get everything back to normal
if sys.version > "2.6":
site.USER_BASE = self.old_user_base
build_ext.USER_BASE = self.old_user_base
super(BuildExtTestCase, self).tearDown()
def test_solaris_enable_shared(self): def test_solaris_enable_shared(self):
dist = Distribution({'name': 'xx'}) dist = Distribution({'name': 'xx'})
cmd = build_ext(dist) cmd = build_ext(dist)

View file

@ -259,12 +259,11 @@ class TestDatabase(support.LoggingCatcher,
disable_cache() disable_cache()
# Setup the path environment with our fake distributions # Setup the path environment with our fake distributions
current_path = os.path.abspath(os.path.dirname(__file__)) current_path = os.path.abspath(os.path.dirname(__file__))
self.sys_path = sys.path[:]
self.fake_dists_path = os.path.join(current_path, 'fake_dists') self.fake_dists_path = os.path.join(current_path, 'fake_dists')
sys.path.insert(0, self.fake_dists_path) sys.path.insert(0, self.fake_dists_path)
def tearDown(self): def tearDown(self):
sys.path[:] = self.sys_path sys.path.remove(self.fake_dists_path)
enable_cache() enable_cache()
super(TestDatabase, self).tearDown() super(TestDatabase, self).tearDown()
@ -488,20 +487,20 @@ class TestDatabase(support.LoggingCatcher,
dists = [('choxie', '2.0.0.9'), ('grammar', '1.0a4'), dists = [('choxie', '2.0.0.9'), ('grammar', '1.0a4'),
('towel-stuff', '0.1'), ('babar', '0.1')] ('towel-stuff', '0.1'), ('babar', '0.1')]
checkLists([], _yield_distributions(False, False)) checkLists([], _yield_distributions(False, False, sys.path))
found = [(dist.name, dist.metadata['Version']) found = [(dist.name, dist.metadata['Version'])
for dist in _yield_distributions(False, True) for dist in _yield_distributions(False, True, sys.path)
if dist.path.startswith(self.fake_dists_path)] if dist.path.startswith(self.fake_dists_path)]
checkLists(eggs, found) checkLists(eggs, found)
found = [(dist.name, dist.metadata['Version']) found = [(dist.name, dist.metadata['Version'])
for dist in _yield_distributions(True, False) for dist in _yield_distributions(True, False, sys.path)
if dist.path.startswith(self.fake_dists_path)] if dist.path.startswith(self.fake_dists_path)]
checkLists(dists, found) checkLists(dists, found)
found = [(dist.name, dist.metadata['Version']) found = [(dist.name, dist.metadata['Version'])
for dist in _yield_distributions(True, True) for dist in _yield_distributions(True, True, sys.path)
if dist.path.startswith(self.fake_dists_path)] if dist.path.startswith(self.fake_dists_path)]
checkLists(dists + eggs, found) checkLists(dists + eggs, found)

View file

@ -4,11 +4,13 @@ import io
import sys import sys
import logging import logging
import textwrap import textwrap
import sysconfig
import packaging.dist import packaging.dist
from packaging.dist import Distribution from packaging.dist import Distribution
from packaging.command import set_command from packaging.command import set_command
from packaging.command.cmd import Command from packaging.command.cmd import Command
from packaging.metadata import Metadata
from packaging.errors import PackagingModuleError, PackagingOptionError from packaging.errors import PackagingModuleError, PackagingOptionError
from packaging.tests import TESTFN, captured_stdout from packaging.tests import TESTFN, captured_stdout
from packaging.tests import support, unittest from packaging.tests import support, unittest
@ -202,21 +204,21 @@ class DistributionTestCase(support.TempdirManager,
config_file = os.path.join(temp_home, "config1.cfg") config_file = os.path.join(temp_home, "config1.cfg")
hooks_module = os.path.join(temp_home, pyname) hooks_module = os.path.join(temp_home, pyname)
self.write_file(config_file, textwrap.dedent(''' self.write_file(config_file, textwrap.dedent('''\
[test_dist] [test_dist]
pre-hook.test = %(modname)s.log_pre_call pre-hook.test = %(modname)s.log_pre_call
post-hook.test = %(modname)s.log_post_call''' post-hook.test = %(modname)s.log_post_call'''
% {'modname': module_name})) % {'modname': module_name}))
self.write_file(hooks_module, textwrap.dedent(''' self.write_file(hooks_module, textwrap.dedent('''\
record = [] record = []
def log_pre_call(cmd): def log_pre_call(cmd):
record.append('pre-%s' % cmd.get_command_name()) record.append('pre-%s' % cmd.get_command_name())
def log_post_call(cmd): def log_post_call(cmd):
record.append('post-%s' % cmd.get_command_name()) record.append('post-%s' % cmd.get_command_name())
''')) '''))
set_command('packaging.tests.test_dist.test_dist') set_command('packaging.tests.test_dist.test_dist')
d = create_distribution([config_file]) d = create_distribution([config_file])
@ -228,15 +230,9 @@ class DistributionTestCase(support.TempdirManager,
self.addCleanup(unload, module_name) self.addCleanup(unload, module_name)
record = __import__(module_name).record record = __import__(module_name).record
old_run = cmd.run
old_finalize = cmd.finalize_options
cmd.run = lambda: record.append('run') cmd.run = lambda: record.append('run')
cmd.finalize_options = lambda: record.append('finalize') cmd.finalize_options = lambda: record.append('finalize')
try: d.run_command('test_dist')
d.run_command('test_dist')
finally:
cmd.run = old_run
cmd.finalize_options = old_finalize
self.assertEqual(record, ['finalize', self.assertEqual(record, ['finalize',
'pre-test_dist', 'pre-test_dist',
@ -247,7 +243,7 @@ class DistributionTestCase(support.TempdirManager,
temp_home = self.mkdtemp() temp_home = self.mkdtemp()
config_file = os.path.join(temp_home, "config1.cfg") config_file = os.path.join(temp_home, "config1.cfg")
self.write_file(config_file, textwrap.dedent(''' self.write_file(config_file, textwrap.dedent('''\
[test_dist] [test_dist]
pre-hook.test = nonexistent.dotted.name''')) pre-hook.test = nonexistent.dotted.name'''))
@ -262,7 +258,7 @@ class DistributionTestCase(support.TempdirManager,
temp_home = self.mkdtemp() temp_home = self.mkdtemp()
config_file = os.path.join(temp_home, "config1.cfg") config_file = os.path.join(temp_home, "config1.cfg")
self.write_file(config_file, textwrap.dedent(''' self.write_file(config_file, textwrap.dedent('''\
[test_dist] [test_dist]
pre-hook.test = packaging.tests.test_dist.__doc__''')) pre-hook.test = packaging.tests.test_dist.__doc__'''))
@ -396,7 +392,8 @@ class MetadataTestCase(support.TempdirManager,
dist = Distribution() dist = Distribution()
sys.argv = [] sys.argv = []
dist.help = True dist.help = True
dist.script_name = 'setup.py' dist.script_name = os.path.join(sysconfig.get_path('scripts'),
'pysetup')
__, stdout = captured_stdout(dist.parse_command_line) __, stdout = captured_stdout(dist.parse_command_line)
output = [line for line in stdout.split('\n') output = [line for line in stdout.split('\n')
if line.strip() != ''] if line.strip() != '']
@ -427,14 +424,13 @@ class MetadataTestCase(support.TempdirManager,
"requires_dist": ['foo']} "requires_dist": ['foo']}
dist = Distribution(attrs) dist = Distribution(attrs)
metadata = dist.metadata
# write it then reloads it
PKG_INFO = io.StringIO() PKG_INFO = io.StringIO()
metadata.write_file(PKG_INFO) dist.metadata.write_file(PKG_INFO)
PKG_INFO.seek(0) PKG_INFO.seek(0)
metadata = Metadata()
metadata.read_file(PKG_INFO) metadata.read_file(PKG_INFO)
self.assertEqual(metadata['name'], "package") self.assertEqual(metadata['name'], "package")
self.assertEqual(metadata['version'], "1.0") self.assertEqual(metadata['version'], "1.0")
self.assertEqual(metadata['summary'], "xxx") self.assertEqual(metadata['summary'], "xxx")

View file

@ -1,5 +1,5 @@
"""Tests for packaging.command.build_py."""
import sys import sys
import textwrap
from packaging.tests import unittest, support from packaging.tests import unittest, support
from packaging.compat import Mixin2to3 from packaging.compat import Mixin2to3
@ -12,60 +12,69 @@ class Mixin2to3TestCase(support.TempdirManager,
@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher') @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_convert_code_only(self): def test_convert_code_only(self):
# used to check if code gets converted properly. # used to check if code gets converted properly.
code_content = "print 'test'\n" code = "print 'test'"
code_handle = self.mktempfile()
code_name = code_handle.name
code_handle.write(code_content) with self.mktempfile() as fp:
code_handle.flush() fp.write(code)
mixin2to3 = Mixin2to3() mixin2to3 = Mixin2to3()
mixin2to3._run_2to3([code_name]) mixin2to3._run_2to3([fp.name])
converted_code_content = "print('test')\n" expected = "print('test')"
with open(code_name) as fp:
new_code_content = "".join(fp.readlines())
self.assertEqual(new_code_content, converted_code_content) with open(fp.name) as fp:
converted = fp.read()
self.assertEqual(expected, converted)
@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher') @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_doctests_only(self): def test_doctests_only(self):
# used to check if doctests gets converted properly. # used to check if doctests gets converted properly.
doctest_content = '"""\n>>> print test\ntest\n"""\nprint test\n\n' doctest = textwrap.dedent('''\
doctest_handle = self.mktempfile() """Example docstring.
doctest_name = doctest_handle.name
doctest_handle.write(doctest_content) >>> print test
doctest_handle.flush() test
It works.
"""''')
with self.mktempfile() as fp:
fp.write(doctest)
mixin2to3 = Mixin2to3() mixin2to3 = Mixin2to3()
mixin2to3._run_2to3([doctest_name]) mixin2to3._run_2to3([fp.name])
expected = textwrap.dedent('''\
"""Example docstring.
converted_doctest_content = ['"""', '>>> print(test)', 'test', '"""', >>> print(test)
'print(test)', '', '', ''] test
converted_doctest_content = '\n'.join(converted_doctest_content)
with open(doctest_name) as fp:
new_doctest_content = "".join(fp.readlines())
self.assertEqual(new_doctest_content, converted_doctest_content) It works.
"""\n''')
with open(fp.name) as fp:
converted = fp.read()
self.assertEqual(expected, converted)
@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher') @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_additional_fixers(self): def test_additional_fixers(self):
# used to check if use_2to3_fixers works # used to check if use_2to3_fixers works
code_content = "type(x) is T" code = 'type(x) is not T'
code_handle = self.mktempfile()
code_name = code_handle.name
code_handle.write(code_content) with self.mktempfile() as fp:
code_handle.flush() fp.write(code)
mixin2to3 = Mixin2to3() mixin2to3 = Mixin2to3()
mixin2to3._run_2to3(files=[fp.name], doctests=[fp.name],
mixin2to3._run_2to3(files=[code_name], doctests=[code_name],
fixers=['packaging.tests.fixer']) fixers=['packaging.tests.fixer'])
converted_code_content = "isinstance(x, T)"
with open(code_name) as fp: expected = 'not isinstance(x, T)'
new_code_content = "".join(fp.readlines())
self.assertEqual(new_code_content, converted_code_content) with open(fp.name) as fp:
converted = fp.read()
self.assertEqual(expected, converted)
def test_suite(): def test_suite():

View file

@ -239,7 +239,6 @@ class TestReleasesList(unittest.TestCase):
def test_prefer_final(self): def test_prefer_final(self):
# Can order the distributions using prefer_final # Can order the distributions using prefer_final
fb10 = ReleaseInfo("FooBar", "1.0") # final distribution fb10 = ReleaseInfo("FooBar", "1.0") # final distribution
fb11a = ReleaseInfo("FooBar", "1.1a1") # alpha fb11a = ReleaseInfo("FooBar", "1.1a1") # alpha
fb12a = ReleaseInfo("FooBar", "1.2a1") # alpha fb12a = ReleaseInfo("FooBar", "1.2a1") # alpha
@ -252,22 +251,23 @@ class TestReleasesList(unittest.TestCase):
dists.sort_releases(prefer_final=False) dists.sort_releases(prefer_final=False)
self.assertEqual(fb12b, dists[0]) self.assertEqual(fb12b, dists[0])
# def test_prefer_source(self): @unittest.skip('method not implemented yet')
# # Ordering support prefer_source def test_prefer_source(self):
# fb_source = Dist("FooBar", "1.0", type="source") # Ordering supports prefer_source
# fb_binary = Dist("FooBar", "1.0", type="binary") fb_source = Dist("FooBar", "1.0", type="source")
# fb2_binary = Dist("FooBar", "2.0", type="binary") fb_binary = Dist("FooBar", "1.0", type="binary")
# dists = ReleasesList([fb_binary, fb_source]) fb2_binary = Dist("FooBar", "2.0", type="binary")
# dists = ReleasesList([fb_binary, fb_source])
# dists.sort_distributions(prefer_source=True)
# self.assertEqual(fb_source, dists[0]) dists.sort_distributions(prefer_source=True)
# self.assertEqual(fb_source, dists[0])
# dists.sort_distributions(prefer_source=False)
# self.assertEqual(fb_binary, dists[0]) dists.sort_distributions(prefer_source=False)
# self.assertEqual(fb_binary, dists[0])
# dists.append(fb2_binary)
# dists.sort_distributions(prefer_source=True) dists.append(fb2_binary)
# self.assertEqual(fb2_binary, dists[0]) dists.sort_distributions(prefer_source=True)
self.assertEqual(fb2_binary, dists[0])
def test_get_last(self): def test_get_last(self):
dists = ReleasesList('Foo') dists = ReleasesList('Foo')

View file

@ -3,6 +3,7 @@ import os
import sys import sys
from io import StringIO from io import StringIO
import stat import stat
import packaging.util
from packaging.database import disable_cache, enable_cache from packaging.database import disable_cache, enable_cache
from packaging.run import main from packaging.run import main
@ -43,6 +44,7 @@ class UninstallTestCase(support.TempdirManager,
def tearDown(self): def tearDown(self):
os.chdir(self.cwd) os.chdir(self.cwd)
packaging.util._path_created.clear()
super(UninstallTestCase, self).tearDown() super(UninstallTestCase, self).tearDown()
def run_setup(self, *args): def run_setup(self, *args):

View file

@ -700,14 +700,8 @@ class GlobTestCase(GlobTestCaseBase):
'{a**a,babar}', '{a**a,babar}',
'{bob,b**z}', '{bob,b**z}',
] ]
msg = "%r is not supposed to be a valid pattern"
for pattern in invalids: for pattern in invalids:
try: self.assertRaises(ValueError, iglob, pattern)
iglob(pattern)
except ValueError:
continue
else:
self.fail(msg % pattern)
class EggInfoToDistInfoTestCase(support.TempdirManager, class EggInfoToDistInfoTestCase(support.TempdirManager,