aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests/test_easy_install.py
diff options
context:
space:
mode:
authorErik Bray <embray@stsci.edu>2012-09-11 13:53:29 -0400
committerErik Bray <embray@stsci.edu>2012-09-11 13:53:29 -0400
commitdbbfab8fe8a8c146c2353f751d617c8761f6ddc4 (patch)
treeb6c0a99cdd01f7ad2f6e4cbd102ff12e27ef3386 /setuptools/tests/test_easy_install.py
parentcada83b25777a9b089b85bc4417baa7016a9c652 (diff)
downloadexternal_python_setuptools-dbbfab8fe8a8c146c2353f751d617c8761f6ddc4.tar.gz
external_python_setuptools-dbbfab8fe8a8c146c2353f751d617c8761f6ddc4.tar.bz2
external_python_setuptools-dbbfab8fe8a8c146c2353f751d617c8761f6ddc4.zip
Fixes and adds a regression test for #323; required adding some new keyword arguments to existing pkg_resources methods. Also had to update how __path__ is handled for namespace packages to ensure that when a new egg distribution containing a namespace package is placed on sys.path, the entries in __path__ are in the same order they would have been in had that egg been on the path when pkg_resources was first imported
--HG-- branch : distribute extra : rebase_source : 63a120c9397f6619d2768ec982e5c6b664c97e40
Diffstat (limited to 'setuptools/tests/test_easy_install.py')
-rw-r--r--setuptools/tests/test_easy_install.py142
1 files changed, 104 insertions, 38 deletions
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index e49c6f49..1540bdc6 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -17,8 +17,10 @@ from setuptools.command.easy_install import easy_install, get_script_args, main
from setuptools.command.easy_install import PthDistributions
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
+from pkg_resources import working_set, VersionConflict
from pkg_resources import Distribution as PRDistribution
import setuptools.tests.server
+import pkg_resources
try:
# import multiprocessing solely for the purpose of testing its existence
@@ -273,48 +275,16 @@ class TestUserInstallTest(unittest.TestCase):
SandboxViolation.
"""
- test_setup_attrs = {
- 'name': 'test_pkg', 'version': '0.0',
- 'setup_requires': ['foobar'],
- 'dependency_links': [os.path.abspath(self.dir)]
- }
-
- test_pkg = os.path.join(self.dir, 'test_pkg')
+ test_pkg = create_setup_requires_package(self.dir)
test_setup_py = os.path.join(test_pkg, 'setup.py')
- test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
- os.mkdir(test_pkg)
- f = open(test_setup_py, 'w')
- f.write(textwrap.dedent("""\
- import setuptools
- setuptools.setup(**%r)
- """ % test_setup_attrs))
- f.close()
-
- foobar_path = os.path.join(self.dir, 'foobar-0.1.tar.gz')
- make_trivial_sdist(
- foobar_path,
- textwrap.dedent("""\
- import setuptools
- setuptools.setup(
- name='foobar',
- version='0.1'
- )
- """))
-
- old_stdout = sys.stdout
- old_stderr = sys.stderr
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
try:
- reset_setup_stop_context(
- lambda: run_setup(test_setup_py, ['install'])
- )
+ quiet_context(
+ lambda: reset_setup_stop_context(
+ lambda: run_setup(test_setup_py, ['install'])
+ ))
except SandboxViolation:
self.fail('Installation caused SandboxViolation')
- finally:
- sys.stdout = old_stdout
- sys.stderr = old_stderr
class TestSetupRequires(unittest.TestCase):
@@ -360,7 +330,7 @@ class TestSetupRequires(unittest.TestCase):
tempdir_context(install_at)
# create an sdist that has a build-time dependency.
- self.create_sdist(install)
+ quiet_context(lambda: self.create_sdist(install))
# there should have been two or three requests to the server
# (three happens on Python 3.3a)
@@ -387,6 +357,81 @@ class TestSetupRequires(unittest.TestCase):
installer(dist_path)
tempdir_context(build_sdist)
+ def test_setup_requires_overrides_version_conflict(self):
+ """
+ Regression test for issue #323.
+
+ Ensures that a distribution's setup_requires requirements can still be
+ installed and used locally even if a conflicting version of that
+ requirement is already on the path.
+ """
+
+ pr_state = pkg_resources.__getstate__()
+ fake_dist = PRDistribution('does-not-matter', project_name='foobar',
+ version='0.0')
+ working_set.add(fake_dist)
+
+ def setup_and_run(temp_dir):
+ test_pkg = create_setup_requires_package(temp_dir)
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ try:
+ stdout, stderr = quiet_context(
+ lambda: reset_setup_stop_context(
+ # Don't even need to install the package, just running
+ # the setup.py at all is sufficient
+ lambda: run_setup(test_setup_py, ['--name'])
+ ))
+ except VersionConflict:
+ self.fail('Installing setup.py requirements caused '
+ 'VersionConflict')
+
+ lines = stdout.splitlines()
+ self.assertGreater(len(lines), 0)
+ self.assert_(lines[-1].strip(), 'test_pkg')
+
+ try:
+ tempdir_context(setup_and_run)
+ finally:
+ pkg_resources.__setstate__(pr_state)
+
+
+def create_setup_requires_package(path):
+ """Creates a source tree under path for a trivial test package that has a
+ single requirement in setup_requires--a tarball for that requirement is
+ also created and added to the dependency_links argument.
+ """
+
+ test_setup_attrs = {
+ 'name': 'test_pkg', 'version': '0.0',
+ 'setup_requires': ['foobar==0.1'],
+ 'dependency_links': [os.path.abspath(path)]
+ }
+
+ test_pkg = os.path.join(path, 'test_pkg')
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
+ os.mkdir(test_pkg)
+
+ f = open(test_setup_py, 'w')
+ f.write(textwrap.dedent("""\
+ import setuptools
+ setuptools.setup(**%r)
+ """ % test_setup_attrs))
+ f.close()
+
+ foobar_path = os.path.join(path, 'foobar-0.1.tar.gz')
+ make_trivial_sdist(
+ foobar_path,
+ textwrap.dedent("""\
+ import setuptools
+ setuptools.setup(
+ name='foobar',
+ version='0.1'
+ )
+ """))
+
+ return test_pkg
+
def make_trivial_sdist(dist_path, setup_py):
"""Create a simple sdist tarball at dist_path, containing just a
@@ -421,6 +466,7 @@ def tempdir_context(f, cd=lambda dir:None):
cd(orig_dir)
shutil.rmtree(temp_dir)
+
def environment_context(f, **updates):
"""
Invoke f in the context
@@ -434,6 +480,7 @@ def environment_context(f, **updates):
del os.environ[key]
os.environ.update(old_env)
+
def argv_context(f, repl):
"""
Invoke f in the context
@@ -445,6 +492,7 @@ def argv_context(f, repl):
finally:
sys.argv[:] = old_argv
+
def reset_setup_stop_context(f):
"""
When the distribute tests are run using setup.py test, and then
@@ -458,3 +506,21 @@ def reset_setup_stop_context(f):
f()
finally:
distutils.core._setup_stop_after = setup_stop_after
+
+
+def quiet_context(f):
+ """
+ Redirect stdout/stderr to StringIO objects to prevent console output from
+ distutils commands.
+ """
+
+ old_stdout = sys.stdout
+ old_stderr = sys.stderr
+ new_stdout = sys.stdout = StringIO.StringIO()
+ new_stderr = sys.stderr = StringIO.StringIO()
+ try:
+ f()
+ finally:
+ sys.stdout = old_stdout
+ sys.stderr = old_stderr
+ return new_stdout.getvalue(), new_stderr.getvalue()