[tests] Port unittest_cwctl to py3k
authorRémi Cardona <remi.cardona@logilab.fr>
Mon, 21 Sep 2015 17:54:15 +0200
changeset 10721 e9abbaa835f5
parent 10720 201028085e12
child 10722 1d0b5aef7523
[tests] Port unittest_cwctl to py3k On python 2, sys.stdout takes bytes-like objects whereas python 3's takes unicode-like objects and handles the encoding on its own.
test/unittest_cwctl.py
--- a/test/unittest_cwctl.py	Mon Sep 21 17:51:58 2015 +0200
+++ b/test/unittest_cwctl.py	Mon Sep 21 17:54:15 2015 +0200
@@ -18,7 +18,10 @@
 import sys
 import os
 from os.path import join
-from cStringIO import StringIO
+from io import StringIO, BytesIO
+
+from six import PY2
+
 from logilab.common.testlib import TestCase, unittest_main
 
 from cubicweb.cwconfig import CubicWebConfiguration
@@ -30,7 +33,7 @@
 
 class CubicWebCtlTC(TestCase):
     def setUp(self):
-        self.stream = StringIO()
+        self.stream = BytesIO() if PY2 else StringIO()
         sys.stdout = self.stream
     def tearDown(self):
         sys.stdout = sys.__stdout__