[Python-checkins] distutils2: Mocked PyPIServer - Some work to isolate the tests cases from each others
tarek.ziade
python-checkins at python.org
Sun Jul 4 11:48:39 CEST 2010
tarek.ziade pushed e29b378fc23a to distutils2:
http://hg.python.org/distutils2/rev/e29b378fc23a
changeset: 293:e29b378fc23a
user: Alexis Metaireau <ametaireau at gmail.com>
date: Tue Jun 01 12:15:53 2010 +0200
summary: Mocked PyPIServer - Some work to isolate the tests cases from each others
files: docs/source/test_framework.rst, src/distutils2/tests/pypi_server.py, src/distutils2/tests/pypiserver/external/index.html, src/distutils2/tests/pypiserver/simple/index.html, src/distutils2/tests/pypiserver/test_pypi_server/external/index.html, src/distutils2/tests/pypiserver/test_pypi_server/simple/index.html, src/distutils2/tests/test_pypi_server.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
@@ -23,14 +23,17 @@
server = PyPIServer(static_uri_paths=["first_path", "second_path"])
-You need to create the content that will be served under the `/test/pypiserver`
-path. If you want to serve content from another place, you also can specify
-another filesystem path::
+You need to create the content that will be served under the
+`/tests/pypiserver/default` path. If you want to serve content from another
+place, you also can specify another filesystem path (wich need to be under
+`tests/pypiserver/`. This will replace the default behavior of the server, and
+it will not serve content from the `default` dir ::
server = PyPIServer(static_filesystem_paths=["path/to/your/dir"])
-Or add some paths to the existing ones, the server will alwas try to load paths
-in reverse order (e.g here, try "another/super/path" then the default one) ::
+If you just need to add some paths to the existing ones, you can do as shown,
+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.static_filesystem_paths.append("another/super/path")
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
@@ -19,7 +19,7 @@
"""Thread that wraps a wsgi app"""
def __init__(self, static_uri_paths=["pypi"],
- static_filesystem_paths=[PYPI_DEFAULT_STATIC_PATH]):
+ static_filesystem_paths=["default"]):
"""Initialize the server.
static_uri_paths and static_base_path are parameters used to provides
@@ -36,7 +36,8 @@
self.default_response_headers = [('Content-type', 'text/plain')]
self.default_response_data = ["hello"]
self.static_uri_paths = static_uri_paths
- self.static_filesystem_paths = static_filesystem_paths
+ self.static_filesystem_paths = [PYPI_DEFAULT_STATIC_PATH + "/" + path
+ for path in static_filesystem_paths]
def run(self):
self.httpd.serve_forever()
@@ -76,6 +77,7 @@
fs_paths.reverse()
for fs_path in fs_paths:
try:
+ print fs_path + relative_path
file = open(fs_path + relative_path)
data = file.read()
start_response("200 OK", [('Content-type', 'text/plain')])
diff --git a/src/distutils2/tests/pypiserver/external/index.html b/src/distutils2/tests/pypiserver/external/index.html
deleted file mode 100644
--- a/src/distutils2/tests/pypiserver/external/index.html
+++ /dev/null
@@ -1,1 +0,0 @@
-index.html from external server
diff --git a/src/distutils2/tests/pypiserver/test_pypi_server/external/index.html b/src/distutils2/tests/pypiserver/test_pypi_server/external/index.html
new file mode 100644
--- /dev/null
+++ b/src/distutils2/tests/pypiserver/test_pypi_server/external/index.html
@@ -0,0 +1,1 @@
+index.html from external server
diff --git a/src/distutils2/tests/pypiserver/simple/index.html b/src/distutils2/tests/pypiserver/test_pypi_server/simple/index.html
rename from src/distutils2/tests/pypiserver/simple/index.html
rename to src/distutils2/tests/pypiserver/test_pypi_server/simple/index.html
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
@@ -33,10 +33,12 @@
url = server.full_address + url_path
request = urllib2.Request(url)
response = urllib2.urlopen(request)
- file = open(PYPI_DEFAULT_STATIC_PATH + url_path)
+ file = open(PYPI_DEFAULT_STATIC_PATH + "/test_pypi_server" +
+ url_path)
return response.read() == file.read()
- server = PyPIServer(static_uri_paths=["simple", "external"])
+ 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
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list