diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2012-04-07 12:16:56 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2012-04-07 12:16:56 -0400 |
| commit | dea4120fdc2cd90d9d68d3ffbc6e2118aadde125 (patch) | |
| tree | c0bec5459dac52e9a5078242e19533b603315bc7 | |
| parent | 5112a1e998a49093f2531fa17fbbb21b6fcdb9d2 (diff) | |
| download | python-setuptools-git-dea4120fdc2cd90d9d68d3ffbc6e2118aadde125.tar.gz | |
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
| -rw-r--r-- | setuptools/tests/server.py | 10 | ||||
| -rw-r--r-- | setuptools/tests/test_easy_install.py | 10 |
2 files changed, 11 insertions, 9 deletions
diff --git a/setuptools/tests/server.py b/setuptools/tests/server.py index e04dcca5..8e06cc1d 100644 --- a/setuptools/tests/server.py +++ b/setuptools/tests/server.py @@ -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) diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 54e3cdf9..87d24bb7 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -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 |
