aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests/test_easy_install.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2012-04-07 11:24:05 -0400
committerJason R. Coombs <jaraco@jaraco.com>2012-04-07 11:24:05 -0400
commitb06c48c01625706c398e6ef6db343cbb192c184e (patch)
tree2b5d08b62ba1b2a5e08979a22c080c1553875774 /setuptools/tests/test_easy_install.py
parentea977c0c8db023626f40f9b7c159549846f14a47 (diff)
downloadexternal_python_setuptools-b06c48c01625706c398e6ef6db343cbb192c184e.tar.gz
external_python_setuptools-b06c48c01625706c398e6ef6db343cbb192c184e.tar.bz2
external_python_setuptools-b06c48c01625706c398e6ef6db343cbb192c184e.zip
Expanded TestSetupRequires so it actually stages the installation of an sdist with a setup_requires.
--HG-- branch : distribute extra : rebase_source : 4266165d9e75e9e19551a3bf646820f309f631df
Diffstat (limited to 'setuptools/tests/test_easy_install.py')
-rw-r--r--setuptools/tests/test_easy_install.py95
1 files changed, 81 insertions, 14 deletions
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 6dcb1cbd..aff2688a 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -7,6 +7,7 @@ import tempfile
import unittest
import site
import contextlib
+import textwrap
from setuptools.command.easy_install import easy_install, get_script_args, main
from setuptools.command.easy_install import PthDistributions
@@ -269,29 +270,95 @@ class TestSetupRequires(unittest.TestCase):
p_index = setuptools.tests.server.MockServer()
p_index.handle_request_in_thread()
# create an sdist that has a build-time dependency.
- dist_file = self.create_sdist()
- with tempdir_context() as temp_install_dir:
- with environment_context(PYTHONPATH=temp_install_dir):
- ei_params = ['--index-url', p_index.url,
- '--allow-hosts', 'localhost',
- '--exclude-scripts', '--install-dir', temp_install_dir,
- dist_file]
- easy_install_pkg.main(ei_params)
- self.assertTrue(os.listdir(temp_install_dir))
+ with TestSetupRequires.create_sdist() as dist_file:
+ with tempdir_context() as temp_install_dir:
+ with environment_context(PYTHONPATH=temp_install_dir):
+ ei_params = ['--index-url', p_index.url,
+ '--allow-hosts', 'localhost',
+ '--exclude-scripts', '--install-dir', temp_install_dir,
+ dist_file]
+ # attempt to install the dist. It will fail because
+ # our fake server can't actually supply the dependency
+ try:
+ easy_install_pkg.main(ei_params)
+ except Exception:
+ pass
+ #self.assertTrue(os.listdir(temp_install_dir))
self.assertEqual(len(p_index.requests), 1)
self.assertEqual(p_index.requests[0].path, 'x')
- def create_sdist(self):
- # for now, just use a known dist
- return ('http://pypi.python.org/packages/source/j/jaraco.util/'
- 'jaraco.util-5.3.zip')
+ @staticmethod
+ @contextlib.contextmanager
+ def create_sdist():
+ """
+ Return an sdist generated by self.generate_dist()
+
+ We don't generate it dynamically, because we don't want the test suite
+ to have to connect to the network for the setup_requires declaration
+ just to build the sdist.
+ """
+ with tempdir_context() as d:
+ dist_path = os.path.join(d, 'distribute-test-fetcher-1.0.tar.gz')
+ with open(dist_path, 'wb') as dist:
+ dist.write("""
+ H4sICLBagE8C/2Rpc3RcZGlzdHJpYnV0ZS10ZXN0LWZldGNoZXItMS4wLnRhcgDtmNtvmzAUh/Ns
+ Kf+DlZduUkmBYJAi5WHaXd2SqlG7h6pCNJwQa9xmm2j57+eQaqGpktKt0F3O9wI+XCJy/JmfCLlU
+ gt8UCgwFUhlzULMFCMPqmyedJ8LUeJ5XbjW723LfsjzHNBmzXV23HJuxDmWdFiikCgSlT/KQ1Yf7
+ SwgP9H97zF8f82+P9SGKDJ7Os5Om+m/brutg///4/oeQQxpCOlv5MU+/yr76rvb8Na7rHui/te0/
+ 0/PEdvWgQ03sf+OQDvI/81v+n52+Nz6O301qqHHI/4HFdvwfePp09L8FPoMKwkAFxiUIybN0SHXn
+ u2QcJDCkeyZHl9w9eVokSSBWQ3oxPh1Pvoy75EOWgJEHEVRqrwq1yMS9ggFJwONK+ROfQSqrV74B
+ ORM8V+Uv/qyexYGaZyKplFDndv2fTi7OX7+d7nnt1/ffdHb8dxgboP9tIEEVeT9fkdqLPXnMtCC/
+ lCEfvkpluR/DEuKH5h7SoP81u/D4/M8cC/3H/I88q/81430tNWrn//L7HxswC/3H/I/5/zn932TD
+ 2Txq2H/r3vd/13QZ+t8GVzrM+eswd90lKoj8m4LHIR3RzUivDKAH5mYkl6kvYMnX6m+qqNy/73++
+ avr9b3ne3fyv/Tdt9L8NeJJnQtGy1SrLYkm2u/1y9wWhmlQHglFvz2zpHZfnLDepYNTTk+e2VN5B
+ LxrfCi5A6kXj6mgRlTc/uj4mL3H5QBAEQRAEaZsfEynDsQAoAAA=
+ """.decode('base64'))
+ yield dist_path
+
+ @classmethod
+ def generate_sdist(cls):
+ """
+ generate the sdist suitable for create_sdist
+ """
+ with tempdir_context(cd=os.chdir):
+ with open('setup.py', 'wb') as setup_script:
+ setup_script.write(textwrap.dedent("""
+ import setuptools
+ setuptools.setup(
+ name="distribute-test-fetcher",
+ version="1.0",
+ setup_requires = ['hgtools'],
+ )
+ """).lstrip())
+ with argv_context(['setup.py', 'sdist', '-q', '--formats', 'gztar']):
+ setuptools.setup(
+ name="distribute-test-fetcher",
+ version = "1.0",
+ setup_requires = ['hgtools'],
+ )
+ filename = 'distribute-test-fetcher-1.0.tar.gz'
+ dist = os.path.join('dist', filename)
+ assert os.path.isfile(dist)
+ with open(dist, 'rb') as dist_f:
+ print("=====================")
+ print(dist_f.read().encode('base64'))
+
+@contextlib.contextmanager
+def argv_context(repl):
+ old_argv = sys.argv[:]
+ sys.argv[:] = repl
+ yield
+ sys.argv[:] = old_argv
@contextlib.contextmanager
-def tempdir_context():
+def tempdir_context(cd=lambda dir:None):
temp_dir = tempfile.mkdtemp()
+ orig_dir = os.getcwd()
try:
+ cd(temp_dir)
yield temp_dir
finally:
+ cd(orig_dir)
shutil.rmtree(temp_dir)
@contextlib.contextmanager