[Python-checkins] distutils2: Add a simpler way to use the PyPIServer on tests.

tarek.ziade python-checkins at python.org
Sun Jul 4 11:48:39 CEST 2010


tarek.ziade pushed 87cc41b3aaca to distutils2:

http://hg.python.org/distutils2/rev/87cc41b3aaca
changeset:   295:87cc41b3aaca
user:        Alexis Metaireau <ametaireau at gmail.com>
date:        Tue Jun 01 14:57:53 2010 +0200
summary:     Add a simpler way to use the PyPIServer on tests.
files:       docs/source/test_framework.rst, src/distutils2/tests/pypi_server.py, src/distutils2/tests/test_pypi_server.py, src/distutils2/tests/test_pypi_simple.py

diff --git a/docs/source/test_framework.rst b/docs/source/test_framework.rst
--- a/docs/source/test_framework.rst
+++ b/docs/source/test_framework.rst
@@ -35,18 +35,17 @@
 keeping in mind that the server will alwas try to load paths in reverse order 
 (e.g here, try "another/super/path" then the default one) ::
 
-    server = PyPIServer()
+    server = PyPIServer(test_static_path="another/super/path")
+    server = PyPIServer("another/super/path")
+    # or 
     server.static_filesystem_paths.append("another/super/path")
 
 As a result of what, in your tests, while you need to use the PyPIServer, in
 order to isolates the test cases, the best practice is to place the common files
 in the `default` folder, and to create a directory for each specific test case::
 
-    server = PyPIServer(static_uri_paths=["simple", "external"],
-        static_filesystem_paths = ["default", "test_pypi_server"])
-
-    # or just
-    server = PyPiServer(["simple", "external"], ["default", "test_pypi_server"])
+    server = PyPIServer(static_filesystem_paths = ["default", "test_pypi_server"],
+        static_uri_paths=["simple", "external"])
 
 ``PyPIServerTestCase``
 ======================
diff --git a/src/distutils2/tests/pypi_server.py b/src/distutils2/tests/pypi_server.py
--- a/src/distutils2/tests/pypi_server.py
+++ b/src/distutils2/tests/pypi_server.py
@@ -18,8 +18,8 @@
 class PyPIServer(threading.Thread):
     """Thread that wraps a wsgi app"""
     
-    def __init__(self, static_uri_paths=["pypi"],
-            static_filesystem_paths=["default"]):
+    def __init__(self, test_static_path=None, 
+            static_filesystem_paths=["default"], static_uri_paths=["simple"]):
         """Initialize the server.
 
         static_uri_paths and static_base_path are parameters used to provides
@@ -36,6 +36,8 @@
         self.default_response_headers = [('Content-type', 'text/plain')]
         self.default_response_data = ["hello"]
         self.static_uri_paths = static_uri_paths
+        if test_static_path is not None:
+            static_filesystem_paths.append(test_static_path)
         self.static_filesystem_paths = [PYPI_DEFAULT_STATIC_PATH + "/" + path 
             for path in static_filesystem_paths]
 
diff --git a/src/distutils2/tests/test_pypi_server.py b/src/distutils2/tests/test_pypi_server.py
--- a/src/distutils2/tests/test_pypi_server.py
+++ b/src/distutils2/tests/test_pypi_server.py
@@ -37,7 +37,8 @@
                url_path)
             return response.read() == file.read()
 
-        server = PyPIServer(["simple", "external"],["test_pypi_server"])
+        server = PyPIServer(static_uri_paths=["simple", "external"],
+            static_filesystem_paths = ["test_pypi_server"])
         server.start()
         
         # the file does not exists on the disc, so it might not be served
diff --git a/src/distutils2/tests/test_pypi_simple.py b/src/distutils2/tests/test_pypi_simple.py
--- a/src/distutils2/tests/test_pypi_simple.py
+++ b/src/distutils2/tests/test_pypi_simple.py
@@ -77,6 +77,9 @@
         url = 'file:///tmp/test_simple'
         self.assert_(index.url_ok(url, True))
 
+    def test_found_links(self):
+        server = PyPIServer("test_found_links")
+
     def test_links_priority(self):
         """
         Download links from the pypi simple index should be used before
@@ -93,7 +96,7 @@
         -> Distribute should use the link from pypi, not the external one.
         """
         # start an index server
-        server = PyPIServer(["simple", "external"],["test_link_priority"])
+        server = PyPIServer(None, ["test_link_priority"], ["simple", "external"])
         server.start()
         index_url = server.full_address + '/simple/'
 

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list