aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests
diff options
context:
space:
mode:
authorDaniel Holth <dholth@fastmail.fm>2012-09-17 08:46:35 -0400
committerDaniel Holth <dholth@fastmail.fm>2012-09-17 08:46:35 -0400
commit20c14661288e0418b44e7fb1a2ea3873fc4f6c21 (patch)
tree888f9a276a85bbb11017c6a331a0507dac2687ce /setuptools/tests
parentfb321a77f92988e24bac25f3493397c82146db6a (diff)
parentcada83b25777a9b089b85bc4417baa7016a9c652 (diff)
downloadexternal_python_setuptools-20c14661288e0418b44e7fb1a2ea3873fc4f6c21.tar.gz
external_python_setuptools-20c14661288e0418b44e7fb1a2ea3873fc4f6c21.tar.bz2
external_python_setuptools-20c14661288e0418b44e7fb1a2ea3873fc4f6c21.zip
merge
--HG-- branch : distribute extra : rebase_source : e10714ab6506fa313a8bfb3f88f0620d3ab1707d
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/__init__.py2
-rw-r--r--setuptools/tests/test_easy_install.py109
-rw-r--r--setuptools/tests/test_sdist.py79
3 files changed, 167 insertions, 23 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index eec76efd..b6988a08 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -38,7 +38,7 @@ def makeSetup(**args):
try:
return setuptools.setup(**args)
finally:
- distutils.core_setup_stop_after = None
+ distutils.core._setup_stop_after = None
class DependsTests(unittest.TestCase):
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 13f668d0..e49c6f49 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -12,6 +12,7 @@ import urlparse
import StringIO
import distutils.core
+from setuptools.sandbox import run_setup, SandboxViolation
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
@@ -110,7 +111,9 @@ class TestEasyInstallTest(unittest.TestCase):
old_wd = os.getcwd()
try:
os.chdir(dir)
- main([])
+ reset_setup_stop_context(
+ lambda: self.assertRaises(SystemExit, main, [])
+ )
finally:
os.chdir(old_wd)
shutil.rmtree(dir)
@@ -247,7 +250,7 @@ class TestUserInstallTest(unittest.TestCase):
cmd.local_index.scan([new_location])
res = cmd.easy_install('foo')
self.assertEqual(os.path.realpath(res.location),
- os.path.realpath(new_location))
+ os.path.realpath(new_location))
finally:
sys.path.remove(target)
for basedir in [new_location, target, ]:
@@ -262,6 +265,57 @@ class TestUserInstallTest(unittest.TestCase):
else:
del os.environ['PYTHONPATH']
+ def test_setup_requires(self):
+ """Regression test for issue #318
+
+ Ensures that a package with setup_requires can be installed when
+ distribute is installed in the user site-packages without causing a
+ 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_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'])
+ )
+ except SandboxViolation:
+ self.fail('Installation caused SandboxViolation')
+ finally:
+ sys.stdout = old_stdout
+ sys.stderr = old_stderr
+
class TestSetupRequires(unittest.TestCase):
@@ -319,30 +373,41 @@ class TestSetupRequires(unittest.TestCase):
doesn't exist) and invoke installer on it.
"""
def build_sdist(dir):
- setup_py = tarfile.TarInfo(name="setup.py")
- try:
- # Python 3 (StringIO gets converted to io module)
- MemFile = StringIO.BytesIO
- except AttributeError:
- MemFile = StringIO.StringIO
- setup_py_bytes = MemFile(textwrap.dedent("""
- import setuptools
- setuptools.setup(
- name="distribute-test-fetcher",
- version="1.0",
- setup_requires = ['does-not-exist'],
- )
- """).lstrip().encode('utf-8'))
- setup_py.size = len(setup_py_bytes.getvalue())
dist_path = os.path.join(dir, 'distribute-test-fetcher-1.0.tar.gz')
- dist = tarfile.open(dist_path, 'w:gz')
- try:
- dist.addfile(setup_py, fileobj=setup_py_bytes)
- finally:
- dist.close()
+ make_trivial_sdist(
+ dist_path,
+ textwrap.dedent("""
+ import setuptools
+ setuptools.setup(
+ name="distribute-test-fetcher",
+ version="1.0",
+ setup_requires = ['does-not-exist'],
+ )
+ """).lstrip())
installer(dist_path)
tempdir_context(build_sdist)
+
+def make_trivial_sdist(dist_path, setup_py):
+ """Create a simple sdist tarball at dist_path, containing just a
+ setup.py, the contents of which are provided by the setup_py string.
+ """
+
+ setup_py_file = tarfile.TarInfo(name='setup.py')
+ try:
+ # Python 3 (StringIO gets converted to io module)
+ MemFile = StringIO.BytesIO
+ except AttributeError:
+ MemFile = StringIO.StringIO
+ setup_py_bytes = MemFile(setup_py.encode('utf-8'))
+ setup_py_file.size = len(setup_py_bytes.getvalue())
+ dist = tarfile.open(dist_path, 'w:gz')
+ try:
+ dist.addfile(setup_py_file, fileobj=setup_py_bytes)
+ finally:
+ dist.close()
+
+
def tempdir_context(f, cd=lambda dir:None):
"""
Invoke f in the context
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
new file mode 100644
index 00000000..8d9ed922
--- /dev/null
+++ b/setuptools/tests/test_sdist.py
@@ -0,0 +1,79 @@
+"""sdist tests"""
+
+
+import os
+import shutil
+import sys
+import tempfile
+import unittest
+from StringIO import StringIO
+
+
+from setuptools.command.sdist import sdist
+from setuptools.dist import Distribution
+
+
+SETUP_ATTRS = {
+ 'name': 'sdist_test',
+ 'version': '0.0',
+ 'packages': ['sdist_test'],
+ 'package_data': {'sdist_test': ['*.txt']}
+}
+
+
+SETUP_PY = """\
+from setuptools import setup
+
+setup(**%r)
+""" % SETUP_ATTRS
+
+
+class TestSdistTest(unittest.TestCase):
+ def setUp(self):
+ self.temp_dir = tempfile.mkdtemp()
+ f = open(os.path.join(self.temp_dir, 'setup.py'), 'w')
+ f.write(SETUP_PY)
+ f.close()
+ # Set up the rest of the test package
+ test_pkg = os.path.join(self.temp_dir, 'sdist_test')
+ os.mkdir(test_pkg)
+ # *.rst was not included in package_data, so c.rst should not be
+ # automatically added to the manifest when not under version control
+ for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']:
+ # Just touch the files; their contents are irrelevant
+ open(os.path.join(test_pkg, fname), 'w').close()
+
+ self.old_cwd = os.getcwd()
+ os.chdir(self.temp_dir)
+
+ def tearDown(self):
+ os.chdir(self.old_cwd)
+ shutil.rmtree(self.temp_dir)
+
+ def test_package_data_in_sdist(self):
+ """Regression test for pull request #4: ensures that files listed in
+ package_data are included in the manifest even if they're not added to
+ version control.
+ """
+
+ dist = Distribution(SETUP_ATTRS)
+ dist.script_name = 'setup.py'
+ cmd = sdist(dist)
+ cmd.ensure_finalized()
+
+ # squelch output
+ old_stdout = sys.stdout
+ old_stderr = sys.stderr
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+ try:
+ cmd.run()
+ finally:
+ sys.stdout = old_stdout
+ sys.stderr = old_stderr
+
+ manifest = cmd.filelist.files
+
+ self.assert_(os.path.join('sdist_test', 'a.txt') in manifest)
+ self.assert_(os.path.join('sdist_test', 'b.txt') in manifest)
+ self.assert_(os.path.join('sdist_test', 'c.rst') not in manifest)