Hello
I am using a wx.Timer in a gui frame that I want to unit test. The problem is that under windows the timer events seems not to be taken in account when unit testing.
In the frame (wxtimer_unittest.py) when the user clicks the pushbutton, the text label changes to "timer Ok". I want to test this.
The unit test is in the file testgui.py.
When I launch the tests (python setup.py test), under Linux (py3+phoenix), the output is:
running build_ext
test0 (testgui.Tests_GUI) ... timer started
True
MyTimer.Notify
timer received
ok
=> The test is successful, whereas under Windows (still py3+phoenix), the output is:
running build_ext
test0 (testgui.Tests_GUI) ... timer started
True
FAIL
======================================================================
FAIL: test0 (testgui.Tests_GUI)
----------------------------------------------------------------------
Traceback (most recent call last):
File "f:\allobrogia\trunk\tests_wx\wxtimer_in_unittest\testgui.py", line 22, in test0
self.assertEqual(self.frame.text.GetLabel(),"timer Ok")
AssertionError: '' != 'timer Ok'
+ timer Ok
----------------------------------------------------------------------
Which means that the wx.Timer.Notify is never called.
Is there a way to make such a test working under windows ?
Regards
Cedric
You don't really need to test the functionality of wx.Timer. That is a
well-tested and well-understood component.
The argument of wx.Timer.Start is in milliseconds and the argument of time.sleep is in seconds.
So at the end of time.sleep, the timer should have fired 10 times.
On Wednesday, November 8, 2017 at 12:32:17 PM UTC-8, Cédric Boudinet wrote:
The argument of wx.Timer.Start is in milliseconds and the argument of time.sleep is in seconds.
So at the end of time.sleep, the timer should have fired 10 times.
No. It would have fired 10 times if the event loop was not blocked, but the time.sleep does indeed block. It simply sits there inside that function until the time expires and then returns. It does not do anything to allow events to be fetched from the system and dispatched to handlers. And, since timer events are typically a lower priority than others,