Robert Brewer committed 41874dc

trunk: sync with python3

Comments (0)

Files changed (3)


 """A library of helper functions for the CherryPy test suite."""
 import datetime
-from cherrypy._cpcompat import basestring, copyitems, HTTPSConnection, ntob
 import logging
 log = logging.getLogger(__name__)
 import os
 import warnings
 import cherrypy
+from cherrypy._cpcompat import basestring, copyitems, HTTPSConnection, ntob
 from cherrypy.lib import httputil
 from cherrypy.lib.reprconf import unrepr
 from cherrypy.test import webtest
+import nose
 _testconfig = None
 def get_tst_config(overconf = {}):
         return webtest.WebCase.getPage(self, url, headers, method, body, protocol)
     def skip(self, msg='skipped '):
-        sys.stderr.write(msg)
+        raise nose.SkipTest(msg)
     def assertErrorPage(self, status, message=None, pattern=''):
         """Compare the response body with a built in error page.


             c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
         c._output(ntob('GET /'))
-        response = c.response_class(c.sock, strict=c.strict, method='GET')
+        if hasattr(c, 'strict'):
+            response = c.response_class(c.sock, strict=c.strict, method='GET')
+        else:
+            # Python 3.2 removed the 'strict' feature, saying:
+            # "http.client now always assumes HTTP/1.x compliant servers."
+            response = c.response_class(c.sock, method='GET')
         self.assertEqual(response.status, 400)
         self.assertEqual(, ntob("Malformed Request-Line"))


-from cherrypy._cpcompat import HTTPConnection, HTTPSConnection
+from cherrypy._cpcompat import HTTPConnection, HTTPSConnection, ntob
 from cherrypy._cpcompat import BytesIO
 import os
     def setup_server():
         if not os.path.exists(has_space_filepath):
-            open(has_space_filepath, 'wb').write('Hello, world\r\n')
+            open(has_space_filepath, 'wb').write(ntob('Hello, world\r\n'))
         if not os.path.exists(bigfile_filepath):
-            open(bigfile_filepath, 'wb').write("x" * BIGFILE_SIZE)
+            open(bigfile_filepath, 'wb').write(ntob("x" * BIGFILE_SIZE))
         class Root:
    = True
             def bytesio(self):
-                f = BytesIO('Fee\nfie\nfo\nfum')
+                f = BytesIO(ntob('Fee\nfie\nfo\nfum'))
                 return static.serve_fileobj(f, content_type='text/plain')
    = True
         # Check that we get an error if no .file or .dir
-        self.assertInBody("TypeError: staticdir() takes at least 2 "
-                          "arguments (0 given)")
+        self.assertMatchesBody(ntob("TypeError: staticdir\(\) takes at least 2 "
+                                    "(positional )?arguments \(0 given\)"))
     def test_security(self):
         # Test up-level security
         self.assertEqual(response.status, 200)
-        body = ''
+        body = ntob('')
         remaining = BIGFILE_SIZE
         while remaining > 0:
             data =
                 newconn = HTTPConnection
             s, h, b = helper.webtest.openURL(
-                "/tell", headers=[], host=self.HOST, port=self.PORT,
+                ntob("/tell"), headers=[], host=self.HOST, port=self.PORT,
             if not b:
                 # The file was closed on the server.
                     "as intended, or at the wrong chunk size (65536)" %
                     (expected, tell_position))
-        if body != "x" * BIGFILE_SIZE:
+        if body != ntob("x" * BIGFILE_SIZE):
   "Body != 'x' * %d. Got %r instead (%d bytes)." %
                       (BIGFILE_SIZE, body[:50], len(body)))
         self.assertEqual(response.status, 200)
         body =
-        if body != "x" * len(body):
+        if body != ntob("x" * len(body)):
   "Body != 'x' * %d. Got %r instead (%d bytes)." %
                       (65536, body[:50], len(body)))
         # Make a second request, which should fetch the whole file.
         self.persistent = False
-        if self.body != "x" * BIGFILE_SIZE:
+        if self.body != ntob("x" * BIGFILE_SIZE):
   "Body != 'x' * %d. Got %r instead (%d bytes)." %
                       (BIGFILE_SIZE, self.body[:50], len(body)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.