Commits

Gael Pasgrimaud committed 1d83346

py3 compat

  • Participants
  • Parent commits 8c39907

Comments (0)

Files changed (2)

tests/test_selenium.py

 from webob import exc
 from tests.compat import unittest
 from webtest.compat import PY3
+from tests.compat import u
 
-if PY3:
-    raise NotImplementedError
+#if PY3:
+#    raise NotImplementedError
 
 files = os.path.dirname(__file__)
 
         if os.path.isfile(filename):
             kw = dict(message=req.params.get('message', ''),
                       redirect=req.params.get('redirect', ''))
-            resp.unicode_body = unicode(open(filename).read()) % kw
+            resp.unicode_body = u(open(filename).read()) % kw
             _, ext = os.path.splitext(filename)
             if ext == '.html':
                 resp.content_type = 'text/html'
 from webtest import app as testapp
 from wsgiref import simple_server
 from contextlib import contextmanager
+from webtest.compat import PY3
 from webtest.compat import urlencode
 from webtest.compat import binary_type
 from webtest.compat import HTTPConnection
 except NameError:
     unicode = str
 
-
 log = logging.getLogger(__name__)
 
 
         try:
             yield response
         finally:
-            resp.body = app.browser.getHtmlSource()
+            body = app.browser.getHtmlSource()
+            if PY3:
+                body = body.encode(resp.charset or 'utf-8')
+            resp.body = body
             resp._forms_indexed = None
             resp.updated = True
             app.close()
             data = resp.read()
         finally:
             conn.close()
+        if PY3:
+            data = str(data, 'utf-8')
         if data.startswith('ERROR: Unknown command:'):
             raise AttributeError(repr(data))
         elif not data.startswith('OK'):
 
     def _body__get(self):
         body = self.browser.getHtmlSource()
+        if PY3:
+            return body.encode(self.charset or 'utf-8')
         if isinstance(body, binary_type):
             return unicode(body, self.charset or 'utf-8')
         else:
             body = open(filename).read()
             body.replace('http://localhost/',
                          'http://%s/' % req.host)
-            resp.body = body
+            if PY3:
+                resp.text = body
+            else:
+                resp.body = body
             return resp(environ, start_response)
         elif '__application__' in environ['PATH_INFO']:
             resp = webob.Response()
-            resp.body = 'Application running'
             return resp(environ, start_response)
         return self.app(environ, start_response)