Make the pubsub tests Py3 compatible

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@76021 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2014-02-26 03:54:09 +00:00
parent 207c1f294c
commit 09a9eae1ba
6 changed files with 11 additions and 10 deletions

View File

@@ -285,7 +285,7 @@ class lib_pubsub_Except(wtc.PubsubTestCase):
self.pub.getDefaultTopicMgr().newTopic(tName, 'desc', required, **args)
msg = 'Should have raised self.pub.MessageDataSpecError for %s, %s, %s'
assert False, msg % (tName, required, args)
except self.pub.MessageDataSpecError, exc:
except self.pub.MessageDataSpecError as exc:
#import traceback
#traceback.print_exc()
pass

View File

@@ -10,7 +10,7 @@ import imp_unittest, unittest
import wtc
from wx.lib.pubsub.utils import notification
from StringIO import StringIO
from wx.lib.six import StringIO
#---------------------------------------------------------------------------

View File

@@ -300,7 +300,7 @@ class lib_pubsub_ArgsInfo(wtc.PubsubTestCase):
self.assertRaises(ListenerMismatchError, getArgs, 1)
try:
getArgs(1)
except ListenerMismatchError, exc:
except ListenerMismatchError as exc:
msg = 'Listener "int" (from module "__main__") inadequate: type "int" not supported'
self.assertEqual(str(exc), msg)

View File

@@ -11,7 +11,6 @@ import wtc
from difflib import ndiff, unified_diff, context_diff
import wx.lib.six as six
#---------------------------------------------------------------------------
@@ -23,7 +22,7 @@ class lib_pubsub_Notify(wtc.PubsubTestCase):
from wx.lib.pubsub.utils.notification import useNotifyByWriteFile
def captureStdout():
from six import StringIO
from wx.lib.six import StringIO
capture = StringIO()
useNotifyByWriteFile( fileObj = capture )
return capture

View File

@@ -89,7 +89,7 @@ class lib_pubsub_Except(wtc.PubsubTestCase):
pass
"""
myTopicTree = file('myTopicTree.py', 'w')
myTopicTree = open('myTopicTree.py', 'w')
myTopicTree.write(dedent(provFile))
myTopicTree.close()
self.pub.addTopicDefnProvider('myTopicTree',
@@ -236,8 +236,10 @@ class lib_pubsub_Except(wtc.PubsubTestCase):
self.pub.exportTopicTreeSpec(os.path.join(basepath,'lib_pubsub_provider_actual'),
rootTopic='test_import_export_no_change2',
moduleDoc=treeDoc)
lines1 = open(os.path.join(basepath,'lib_pubsub_provider_actual.py'), 'r').readlines()
lines2 = open(os.path.join(basepath,'lib_pubsub_provider_expect.py'), 'r').readlines()
with open(os.path.join(basepath,'lib_pubsub_provider_actual.py'), 'r') as f:
lines1 = f.readlines()
with open(os.path.join(basepath,'lib_pubsub_provider_expect.py'), 'r') as f:
lines2 = f.readlines()
diffs = ndiff( lines1, lines2 )
diffs = [d for d in diffs if not d.startswith(' ')]
assert not list(diffs) or list(diffs) == ['- # - fileObj: TextIOWrapper\n', '+ # - fileObj: file\n']

View File

@@ -305,7 +305,7 @@ class lib_pubsub_TopicMgr2_GetOrCreate_DefnProv(wtc.PubsubTestCase):
topicName)
try:
assert topicMgr.getOrCreateTopic(topicName) is None
except MessageDataSpecError, exc:
except MessageDataSpecError as exc:
# ok, did raise but is it correct message?
try:
str(exc).index(expectMsg)
@@ -359,7 +359,7 @@ class lib_pubsub_TopicMgr3_TreeTraverser(wtc.PubsubTestCase):
topicMgr.getOrCreateTopic('a2.b.a')
topicMgr.getOrCreateTopic('a2.b.b')
from StringIO import StringIO
from wx.lib.six import StringIO
buffer = StringIO()
printTreeDocs(rootTopic=root, width=70, fileObj=buffer)
self.assertEqual( buffer.getvalue(), self.expectedOutput )