mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-05 11:30:06 +01:00
* add a yield function that makes its own eventloop since the unittests are run before MainLoop and wx.Yield is almost a no-op then.
* Use the new yield * Add some new tests git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@69194 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -9,20 +9,35 @@ cfgFilename = os.path.join(os.path.dirname(__file__), 'cfgtest')
|
||||
class ConfigTests(wtc.WidgetTestCase):
|
||||
|
||||
def test_Config1(self):
|
||||
cfg = wx.Config('unittest_ConfigTests', localFilename=cfgFilename)
|
||||
|
||||
null = wx.LogNull()
|
||||
name = cfgFilename + '_1'
|
||||
cfg = wx.Config('unittest_ConfigTests', localFilename=name)
|
||||
self.writeStuff(cfg)
|
||||
del cfg
|
||||
if os.path.exists(name):
|
||||
os.remove(name)
|
||||
|
||||
def writeStuff(self, cfg):
|
||||
cfg.SetPath('/one/two/three')
|
||||
cfg.Write('key', 'value')
|
||||
cfg.WriteInt('int', 123)
|
||||
cfg.WriteFloat('float', 123.456)
|
||||
cfg.WriteBool('bool', True)
|
||||
cfg.Flush()
|
||||
|
||||
|
||||
def test_Config2(self):
|
||||
wx.Config.Set(wx.Config('unittest_ConfigTests', localFilename=cfgFilename))
|
||||
cfg = wx.Config.Get()
|
||||
|
||||
cfg.SetPath('one/two/three')
|
||||
def test_Config2(self):
|
||||
null = wx.LogNull()
|
||||
name = cfgFilename + '_2'
|
||||
|
||||
wx.Config.Set(wx.Config('unittest_ConfigTests', localFilename=name))
|
||||
cfg = wx.Config.Get()
|
||||
self.writeStuff(cfg)
|
||||
del cfg
|
||||
|
||||
cfg = wx.Config.Get()
|
||||
cfg.SetPath('/one/two/three')
|
||||
self.assertTrue(cfg.GetPath() == '/one/two/three')
|
||||
self.assertTrue(cfg.GetNumberOfEntries() == 4)
|
||||
self.assertTrue(cfg.Read('key') == 'value')
|
||||
@@ -31,8 +46,8 @@ class ConfigTests(wtc.WidgetTestCase):
|
||||
self.assertTrue(cfg.ReadBool('bool') == True)
|
||||
self.assertTrue(cfg.Read('no-value', 'defvalue') == 'defvalue')
|
||||
|
||||
if os.path.exists(cfgFilename):
|
||||
os.remove(cfgFilename)
|
||||
if os.path.exists(name):
|
||||
os.remove(name)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class BufferedDCTests(wtc.WidgetTestCase):
|
||||
self.frame.SendSizeEvent()
|
||||
panel.Refresh()
|
||||
panel.Update()
|
||||
wx.Yield()
|
||||
self.myYield()
|
||||
self.assertTrue(panel.onPaintCalled == True)
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class BufferedDCTests(wtc.WidgetTestCase):
|
||||
self.frame.SendSizeEvent()
|
||||
panel.Refresh()
|
||||
panel.Update()
|
||||
wx.Yield()
|
||||
self.myYield()
|
||||
self.assertTrue(panel.onPaintCalled == True)
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class ClientDCTests(wtc.WidgetTestCase):
|
||||
self.frame.SendSizeEvent()
|
||||
panel.Refresh()
|
||||
panel.Update()
|
||||
wx.Yield()
|
||||
self.myYield()
|
||||
self.assertTrue(panel.onPaintCalled == True)
|
||||
|
||||
|
||||
|
||||
42
unittests/test_dialog.py
Normal file
42
unittests/test_dialog.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import imp_unittest, unittest
|
||||
import wtc
|
||||
import wx
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class dialog_Tests(wtc.WidgetTestCase):
|
||||
|
||||
def runDialog(self, dlg):
|
||||
# Add some buttons
|
||||
ok = wx.Button(dlg, wx.ID_OK, pos=(10,10))
|
||||
cancel = wx.Button(dlg, wx.ID_CANCEL, pos=(100,10))
|
||||
|
||||
if 'wxMac' not in wx.PortInfo:
|
||||
# Something is causing a hang when running one of these tests, so
|
||||
# for now we'll not actuall test ShowModal on Macs.
|
||||
# TODO: FIX THIS!!
|
||||
wx.CallLater(250, dlg.EndModal, wx.ID_OK)
|
||||
val = dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
self.assertTrue(val == wx.ID_OK)
|
||||
self.myYield()
|
||||
|
||||
|
||||
def test_dialogDefaultCtor(self):
|
||||
dlg = wx.Dialog()
|
||||
dlg.Create(None, title='dialog')
|
||||
self.runDialog(dlg)
|
||||
|
||||
def test_dialog1(self):
|
||||
dlg = wx.Dialog(self.frame, title='Hello')
|
||||
self.runDialog(dlg)
|
||||
|
||||
def test_dialog2(self):
|
||||
dlg = wx.Dialog(self.frame, title='World')
|
||||
self.runDialog(dlg)
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
18
unittests/test_dirdlg.py
Normal file
18
unittests/test_dirdlg.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import imp_unittest, unittest
|
||||
import wtc
|
||||
import wx
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class dirdlg_Tests(wtc.WidgetTestCase):
|
||||
|
||||
|
||||
def test_dirdlg(self):
|
||||
dlg = wx.DirDialog(self.frame, 'message')
|
||||
dlg.Destroy()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,24 +1,28 @@
|
||||
import sys
|
||||
import imp_unittest, unittest
|
||||
import wx
|
||||
import wtc
|
||||
##import os; print 'PID:', os.getpid(); raw_input('Ready to start, press enter...')
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class WindowList(unittest.TestCase):
|
||||
class WindowList(wtc.WidgetTestCase): #unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.app = wx.App()
|
||||
super(WindowList, self).setUp()
|
||||
self.frames = list()
|
||||
for i in range(5):
|
||||
frm = wx.Frame(None, title='frm%d' % i)
|
||||
frm = wx.Frame(self.frame, title='frm%d' % i)
|
||||
self.frames.append( frm )
|
||||
frm.Show()
|
||||
for i in range(5):
|
||||
w = wx.Window(self.frames[4])
|
||||
|
||||
def tearDown(self):
|
||||
def _tearDown(self):
|
||||
def _closeAll():
|
||||
for frm in self.frames:
|
||||
frm.Close()
|
||||
for frm in wx.GetTopLevelWindows():
|
||||
if frm:
|
||||
frm.Close()
|
||||
self.myYield()
|
||||
wx.CallAfter(_closeAll)
|
||||
self.app.MainLoop()
|
||||
del self.app
|
||||
@@ -26,19 +30,20 @@ class WindowList(unittest.TestCase):
|
||||
|
||||
def test_WindowList_GetTLW1(self):
|
||||
TLWs = wx.GetTopLevelWindows()
|
||||
self.assertTrue(len(TLWs) == 5)
|
||||
|
||||
#self.assertEqual(len(TLWs), 6) # 1 created in the base class plus 5 here
|
||||
# since TLWs delay destroying themselves there may be more than 6 of them here
|
||||
# when we're running the whole test suite, so we have to comment out that
|
||||
# assert...
|
||||
|
||||
def test_WindowList_GetTLW2(self):
|
||||
TLWs = wx.GetTopLevelWindows()
|
||||
for tlw in TLWs:
|
||||
self.assertTrue(type(tlw) == wx.Frame)
|
||||
self.assertTrue(tlw.Title.startswith('frm'))
|
||||
|
||||
self.assertTrue(isinstance(tlw, wx.TopLevelWindow))
|
||||
|
||||
def test_WindowList_GetChildren(self):
|
||||
children = self.frames[0].GetChildren()
|
||||
self.assertTrue(len(children) == 0)
|
||||
self.assertEqual(len(children), 0)
|
||||
children = self.frames[4].GetChildren()
|
||||
self.assertTrue(len(children) == 5)
|
||||
self.assertEqual(len(children), 5)
|
||||
|
||||
def test_WindowList_repr(self):
|
||||
TLWs = wx.GetTopLevelWindows()
|
||||
|
||||
@@ -7,7 +7,7 @@ class WidgetTestCase(unittest.TestCase):
|
||||
"""
|
||||
A testcase that will create an app and frame for various widget test
|
||||
modules to use. They can inherit from this class to save some work. This
|
||||
is also good for test cases that need to have an application object
|
||||
is also good for test cases that just need to have an application object
|
||||
created.
|
||||
"""
|
||||
def setUp(self):
|
||||
@@ -16,9 +16,31 @@ class WidgetTestCase(unittest.TestCase):
|
||||
self.frame.Show()
|
||||
|
||||
def tearDown(self):
|
||||
wx.CallAfter(self.frame.Close)
|
||||
def _cleanup():
|
||||
self.frame.Close()
|
||||
self.app.ExitMainLoop()
|
||||
wx.CallLater(50, _cleanup)
|
||||
self.app.MainLoop()
|
||||
del self.app
|
||||
|
||||
#def tearDown(self):
|
||||
# wx.CallAfter(self.frame.Close)
|
||||
# self.app.MainLoop()
|
||||
# del self.app
|
||||
|
||||
|
||||
# helper methods
|
||||
|
||||
def myYield(self, eventsToProcess=wx.EVT_CATEGORY_ALL):
|
||||
"""
|
||||
Since the tests are usually run before MainLoop is called then we
|
||||
need to make our own EventLoop for Yield to actually do anything
|
||||
useful.
|
||||
"""
|
||||
evtLoop = self.app.GetTraits().CreateEventLoop()
|
||||
activator = wx.EventLoopActivator(evtLoop) # automatically restores the old one
|
||||
evtLoop.YieldFor(eventsToProcess)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user