Test asserts and virtual method overrides

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@69780 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2011-11-17 03:51:56 +00:00
parent fd0a62c1c4
commit 1b1abbc360
2 changed files with 47 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ class asserts_Tests(wtc.WidgetTestCase):
with self.assertRaises(wx.PyAssertionError): with self.assertRaises(wx.PyAssertionError):
wx.NullBitmap.ConvertToImage() wx.NullBitmap.ConvertToImage()
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------

View File

@@ -0,0 +1,46 @@
import imp_unittest, unittest
import wtc
import wx
#---------------------------------------------------------------------------
# This test will ensure that a virtual C++ method from a base class can
# be overridden in a derived class implemented in Python, and that when
# the C++ method is called from C++ that the Python override is called.
# In addition the Python override will pass the call on to the base class
# implementation and this test will ensure that is successful as well.
#
# The AddChild method is a good cantidate for this test because it is
# easy to induce a call from C++ (just create a child window) and it is
# easy to test if the calling the base class AddChild works (the length
# of the GetChildren list will increase.)
class MyTestPanel(wx.Panel):
def __init__(self, *args, **kw):
wx.Panel.__init__(self, *args, **kw)
self.methodCalled = False
def AddChild(self, child):
self.methodCalled = True
if 1:
super(MyTestPanel, self).AddChild(child)
else:
wx.Panel.AddChild(self, child)
class virtualOverride_Tests(wtc.WidgetTestCase):
def test_virtualOverride(self):
p = MyTestPanel(self.frame)
count = len(p.Children)
b = wx.Button(p, -1, "Hello, I am a button")
self.assertTrue(p.methodCalled)
self.assertTrue(len(p.Children) == count+1)
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()