[Python-checkins] distutils2: added pypi server documentation

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


tarek.ziade pushed 3c1b00037fb0 to distutils2:

http://hg.python.org/distutils2/rev/3c1b00037fb0
changeset:   274:3c1b00037fb0
user:        Konrad Delong <konryd at gmail.com>
date:        Mon May 17 01:55:02 2010 +0200
summary:     added pypi server documentation
files:       docs/source/index.rst, docs/source/test_framework.rst, src/distutils2/tests/pypi_server.py

diff --git a/docs/source/index.rst b/docs/source/index.rst
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -13,6 +13,7 @@
 
    metadata
    new_commands
+   test_framework
 
 Indices and tables
 ==================
diff --git a/docs/source/test_framework.rst b/docs/source/test_framework.rst
new file mode 100644
--- /dev/null
+++ b/docs/source/test_framework.rst
@@ -0,0 +1,34 @@
+==============
+Test Framework
+==============
+
+When you are testing code that works with distutils, you might find these tools
+useful.
+
+
+``PyPIServer``
+==============
+
+PyPIServer is a class that implements an HTTP server running in a separate
+thread. All it does is record the requests for further inspection. The recorded
+data is available under ``requests`` attribute. The default
+HTTP response can be overriden with the ``default_response_status``,
+``default_response_headers`` and ``default_response_data`` attributes.
+
+
+``PyPIServerTestCase``
+======================
+
+``PyPIServerTestCase`` is a test case class with setUp and tearDown methods that
+take care of a single PyPIServer instance attached as a ``pypi`` attribute on
+the test class. Use it as one of the base classes in you test case::
+
+  class UploadTestCase(PyPIServerTestCase):
+      def test_something(self):
+          cmd = self.prepare_command()
+          cmd.ensure_finalized()
+          cmd.repository = self.pypi.full_address
+          cmd.run()
+
+          environ, request_data = self.pypi.requests[-1]
+          self.assertEqual(request_data, EXPECTED_REQUEST_DATA)
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
@@ -21,9 +21,9 @@
         self.address = self.httpd.server_address
         self.request_queue = Queue.Queue()
         self._requests = []
-        self._default_response_status = "200 OK"
-        self._default_response_headers = [('Content-type', 'text/plain')]
-        self._default_response_data = ["hello"]
+        self.default_response_status = "200 OK"
+        self.default_response_headers = [('Content-type', 'text/plain')]
+        self.default_response_data = ["hello"]
 
     def run(self):
         self.httpd.serve_forever()
@@ -45,9 +45,9 @@
         return data
 
     def get_next_response(self):
-        return (self._default_response_status,
-                self._default_response_headers,
-                self._default_response_data)
+        return (self.default_response_status,
+                self.default_response_headers,
+                self.default_response_data)
 
     @property
     def requests(self):

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


More information about the Python-checkins mailing list