From: Simon Pomarede Date: Thu, 4 Feb 2016 13:32:08 +0000 (+0100) Subject: Py3 porting. NOTE: may not be Py2 compliant anymore => to be done X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f0c6c9732be261dd0ba5e449779974c07b29cd07;p=tools%2Fsat.git Py3 porting. NOTE: may not be Py2 compliant anymore => to be done --- diff --git a/test/_testTools/HTMLTestRunner.py b/test/_testTools/HTMLTestRunner.py index 0439bf4..1ace962 100644 --- a/test/_testTools/HTMLTestRunner.py +++ b/test/_testTools/HTMLTestRunner.py @@ -91,7 +91,10 @@ Version in 0.7.1 # TODO: simplify javascript using ,ore than 1 class in the class attribute? import datetime -import StringIO +try: + from StringIO import StringIO +except ImportError: + from io import StringIO import sys import time import unittest @@ -536,7 +539,7 @@ class _TestResult(TestResult): def startTest(self, test): TestResult.startTest(self, test) # just one buffer for both stdout and stderr - self.outputBuffer = StringIO.StringIO() + self.outputBuffer = StringIO() stdout_redirector.fp = self.outputBuffer stderr_redirector.fp = self.outputBuffer self.stdout0 = sys.stdout @@ -628,7 +631,8 @@ class HTMLTestRunner(Template_mixin): test(result) self.stopTime = datetime.datetime.now() self.generateReport(test, result) - print >>sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime) + print ("\nTime Elapsed: %s" %(self.stopTime-self.startTime), + file=sys.stderr) return result @@ -639,7 +643,7 @@ class HTMLTestRunner(Template_mixin): classes = [] for n,t,o,e in result_list: cls = t.__class__ - if not rmap.has_key(cls): + if not cls in rmap: rmap[cls] = [] classes.append(cls) rmap[cls].append((n,t,o,e)) @@ -684,7 +688,7 @@ class HTMLTestRunner(Template_mixin): report = report, ending = ending, ) - self.stream.write(output.encode('utf8')) + self.stream.write(output) def _generate_stylesheet(self): @@ -763,13 +767,13 @@ class HTMLTestRunner(Template_mixin): if isinstance(o,str): # TODO: some problem with 'string_escape': it escape \n and mess up formating # uo = unicode(o.encode('string_escape')) - uo = o.decode('latin-1') + uo = bytes(o, 'utf-8').decode('latin-1') else: uo = o if isinstance(e,str): # TODO: some problem with 'string_escape': it escape \n and mess up formating # ue = unicode(e.encode('string_escape')) - ue = e.decode('latin-1') + ue = bytes(e, 'utf-8').decode('latin-1') else: ue = e