Commits

Jason R. Coombs committed 06f2cf0

Expanded TestSetupRequires so it actually stages the installation of an sdist with a setup_requires.

Comments (0)

Files changed (1)

setuptools/tests/test_easy_install.py

 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
         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 tempdir_context():
+def argv_context(repl):
+    old_argv = sys.argv[:]
+    sys.argv[:] = repl
+    yield
+    sys.argv[:] = old_argv
+
+@contextlib.contextmanager
+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