# HG changeset patch # User RĂ©mi Cardona # Date 1442247020 -7200 # Node ID 987fbc88f09703affd6edad2fcdae1b1294ee7b5 # Parent 30ebd6b2eaf37ee76a7c3a884a036acf337024b1 [devtools/testlib] Port CubicWebTC.view() to py3k testlib.TestCase.set_description's argument will eventually be printed out to sys.stdout/stderr. On python 2, this object takes bytes-like objects (eg, str) whereas python 3's takes unicode-like objects and handles the encoding on its own. Thus the 'str' type can used in both versions to eventually display the description on screen. diff -r 30ebd6b2eaf3 -r 987fbc88f097 devtools/test/unittest_testlib.py --- a/devtools/test/unittest_testlib.py Mon Sep 14 18:12:44 2015 +0200 +++ b/devtools/test/unittest_testlib.py Mon Sep 14 18:10:20 2015 +0200 @@ -17,10 +17,10 @@ # with CubicWeb. If not, see . """unittests for cw.devtools.testlib module""" -from cStringIO import StringIO -from io import BytesIO +from io import BytesIO, StringIO +from unittest import TextTestRunner -from unittest import TextTestRunner +from six import PY2 from logilab.common.testlib import TestSuite, TestCase, unittest_main from logilab.common.registry import yes @@ -52,7 +52,7 @@ class WebTestTC(TestCase): def setUp(self): - output = StringIO() + output = BytesIO() if PY2 else StringIO() self.runner = TextTestRunner(stream=output) def test_error_raised(self): diff -r 30ebd6b2eaf3 -r 987fbc88f097 devtools/testlib.py --- a/devtools/testlib.py Mon Sep 14 18:12:44 2015 +0200 +++ b/devtools/testlib.py Mon Sep 14 18:10:20 2015 +0200 @@ -908,8 +908,11 @@ view = viewsreg.select(vid, req, rset=rset, **kwargs) # set explicit test description if rset is not None: + # coerce to "bytes" on py2 because the description will be sent to + # sys.stdout/stderr which takes "bytes" on py2 and "unicode" on py3 + rql = str(rset.printable_rql()) self.set_description("testing vid=%s defined in %s with (%s)" % ( - vid, view.__module__, rset.printable_rql())) + vid, view.__module__, rql)) else: self.set_description("testing vid=%s defined in %s without rset" % ( vid, view.__module__))