python - unittest: wxpython's event method raises exception but assertRaises does not detect it -


i have wxpython dialog raises typeerror exception when clicking ok button. test occurrence of exception unittest test not work expected. output shows exception raised. anyhow unittest notifies test fails:

"c:\program files (x86)\python\python.exe" test.py traceback (most recent call last):   file "test.py", line 22, in on_ok     raise typeerror( 'typeerror raised' ) typeerror: typeerror raised f ====================================================================== fail: test_should_raise (__main__.cdlgtest) ---------------------------------------------------------------------- traceback (most recent call last):   file "test.py", line 34, in test_should_raise     self._dut.m_button_ok.geteventhandler().processevent( event ) assertionerror: typeerror not raised  ---------------------------------------------------------------------- ran 1 test in 0.005s  failed (failures=1) 

here reduced sample of code:

import unittest import wx  class cdlgbase ( wx.dialog ):     """the ui"""     def __init__( self, parent ):         wx.dialog.__init__ ( self, parent )         bsizertest = wx.boxsizer( wx.vertical )         self.m_button_ok = wx.button( self, wx.id_any )         bsizertest.add( self.m_button_ok, 0 )         self.setsizer( bsizertest )         # connect events         self.m_button_ok.bind( wx.evt_button, self.on_ok )     def on_ok( self, event ):         event.skip()  class cdlg( cdlgbase ) :     """the dialog"""     def __init__(self, parent):         super( cdlg, self).__init__(parent)     def on_ok(self, event):         # exception should verified in test `test_should_raise()`.         raise typeerror( 'typeerror raised' )  class cdlgtest( unittest.testcase ) :     """the test class"""     def setup(self):         self._dut = cdlg(none)     def test_should_raise(self):         """the test verify raising typeerror exception in event          method `on_ok()`. test method wich works not expected."""         event = wx.commandevent( wx.evt_button.evttype[0] )         event.seteventobject( self._dut.m_button_ok )         self.assertraises( typeerror ) :             """simulate "ok" click. `on_ok()` executed              , raises typeerror exception."""             self._dut.m_button_ok.geteventhandler().processevent( event )  if __name__ == '__main__':     app = wx.app()     tests = [ unittest.testloader().loadtestsfromtestcase( cdlgtest) ]     unittest.texttestrunner(verbosity=2, failfast=true).run(unittest.testsuite(tests) ) 

can please me find out did wrong?

see: https://wiki.wxpython.org/cppandpythonsandwich

exceptions not passed call stack though c++ layers. when control returns c++ python checks if there python exception not caught, if prints , clears error.

one way deal in unit tests catch exception in event handler, , set flag. in test code can check flag being set or not.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -