Commits

Jason R. Coombs committed 8f93340

Improved the MockServer so it now more effectively handles multiple requests (as any index server really must).
Test now more accurately captures the working scenario.

  • Participants
  • Parent commits 342e978

Comments (0)

Files changed (2)

File setuptools/tests/server.py

         requests.append(self)
         self.send_response(200, 'OK')
 
-class MockServer(HTTPServer):
+class MockServer(HTTPServer, threading.Thread):
     """
     A simple HTTP Server that records the requests made to it.
     """
             bind_and_activate=True):
         HTTPServer.__init__(self, server_address, RequestHandlerClass,
             bind_and_activate)
-        self.threads = []
+        threading.Thread.__init__(self)
+        self.daemon = True
 
-    def handle_request_in_thread(self):
-        self.threads.append(threading.Thread(target = self.handle_request))
-        # todo: ensure that threads are closed.
+    def run(self):
+        self.serve_forever()
 
     def url(self):
         return 'http://localhost:%(server_port)s/' % vars(self)

File setuptools/tests/test_easy_install.py

 import contextlib
 import textwrap
 import tarfile
+import urlparse
 
 from setuptools.command.easy_install import easy_install, get_script_args, main
 from setuptools.command.easy_install import  PthDistributions
         """
         # set up a server which will simulate an alternate package index.
         p_index = setuptools.tests.server.MockServer()
-        p_index.handle_request_in_thread()
+        p_index.start()
+        p_index_loc = urlparse.urlparse(p_index.url).netloc
         # create an sdist that has a build-time dependency.
         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',
+                        '--allow-hosts', p_index_loc,
                         '--exclude-scripts', '--install-dir', temp_install_dir,
                         dist_file]
                     # attempt to install the dist. It should fail because
                     self.assertRaises(SystemExit,
                         easy_install_pkg.main, ei_params)
                 #self.assertTrue(os.listdir(temp_install_dir))
-        self.assertEqual(len(p_index.requests), 1)
-        self.assertEqual(p_index.requests[0].path, 'x')
+        self.assertEqual(len(p_index.requests), 2)
+        self.assertEqual(p_index.requests[0].path, '/does-not-exist/')
 
     @staticmethod
     @contextlib.contextmanager