Commit dea4120f authored by Jason R. Coombs's avatar Jason R. Coombs

Improved the MockServer so it now more effectively handles multiple requests...

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.

--HG--
branch : distribute
extra : rebase_source : 8ee0afdd95219047e4700b85356792f6128b1fd8
parent 5112a1e9
......@@ -61,7 +61,7 @@ class RequestRecorder(BaseHTTPServer.BaseHTTPRequestHandler):
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.
"""
......@@ -70,11 +70,11 @@ class MockServer(HTTPServer):
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)
......
......@@ -9,6 +9,7 @@ import site
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
......@@ -269,13 +270,14 @@ class TestSetupRequires(unittest.TestCase):
"""
# 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
......@@ -283,8 +285,8 @@ class TestSetupRequires(unittest.TestCase):
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment