Testing events, I'm missing the gist

Good inhabitants of this list,

While attempting to test my naughty control
I wrote some doctests covering the whole
But when it came to a sent text event
Wx did its best to prevent
Success.

Many paths in my quest I wandered
Many hours in futility squandered
Many googled wx docs read I
Many prayers did I send to the sky...
Nothing.

All I wanted was a handler to test.
Send an event wrapped char to rest,
After traversing bound method to Skip()
To yon text field's furthest lip
Blank.

I conversed with friends of diverse name
EmulateKeyPress, wx.KeyEvent, the selfsame.
Events I created and ruefully spent
sending to GetEventHandler().ProcessEvent()
None.

The ProcessEvent finally filled me with hope
The event traversed the bound method's scope
Then reaching the end leaped through event.Skip
Never to be seen, nay, nary a blip.
0x00000000

My question to all, as I was wonderin':
Where is my char after all that conjurin'?
I am perplexed, and my tests are dissolute
Having no purpose, their depression's acute.
:frowning:

Below is a sample of what I was trying.
In development, by pants I am currently flying
I cannot regress or refactor with aplomb
With only debugger and luck I will bomb
Eventually.

Ta for reactions in advance of posting
I return with debugger to merry code-roasting.
I hope you will forgive my horrible rhyming,
And I'm not really pleased at all with the timing.
Thanks.

8<--------------------------------------------------------

>>> app = wx.App()
>>> app.frame = wx.Frame(None, -1)
>>> app.pan = wx.Panel(app.frame, -1)
>>> c = wx.TextCtrl(app.pan, -1)
>>> c.AppendText('a')
>>> c.GetInsertionPoint()
1
>>> len(c.GetValue())
1

Now we want to pass the event of adding a b
>>> event = wx.KeyEvent(wx.wxEVT_CHAR)
>>> event.m_keyCode = ord('a')
>>> event.GetKeyCode()
97
>>> c.SetFocus()
>>> c.GetEventHandler().ProcessEvent(event)
False
>>> event.Skip()
>>> c.GetValue()
u''
>>> c.GetEventHandler().ProcessEvent(event)
False
>>> c.GetValue()
u'a'

This fails when run, as c.GetValue() still has u''

Rohan wrote:

Good inhabitants of this list,

While attempting to test my naughty control
I wrote some doctests covering the whole
But when it came to a sent text event
Wx did its best to prevent
Success.

Many paths in my quest I wandered
Many hours in futility squandered
Many googled wx docs read I
Many prayers did I send to the sky...
Nothing.

All I wanted was a handler to test.
Send an event wrapped char to rest,
After traversing bound method to Skip()
To yon text field's furthest lip
Blank.

I conversed with friends of diverse name
EmulateKeyPress, wx.KeyEvent, the selfsame.
Events I created and ruefully spent
sending to GetEventHandler().ProcessEvent()
None.

The ProcessEvent finally filled me with hope
The event traversed the bound method's scope
Then reaching the end leaped through event.Skip
Never to be seen, nay, nary a blip.
0x00000000

My question to all, as I was wonderin':
Where is my char after all that conjurin'?
I am perplexed, and my tests are dissolute
Having no purpose, their depression's acute.
:frowning:

Below is a sample of what I was trying.
In development, by pants I am currently flying
I cannot regress or refactor with aplomb
With only debugger and luck I will bomb
Eventually.

Ta for reactions in advance of posting
I return with debugger to merry code-roasting.
I hope you will forgive my horrible rhyming,
And I'm not really pleased at all with the timing.
Thanks.

This was actually a fun poem...give yourself some credit!

8<--------------------------------------------------------

>>> app = wx.App()
>>> app.frame = wx.Frame(None, -1)
>>> app.pan = wx.Panel(app.frame, -1)
>>> c = wx.TextCtrl(app.pan, -1)
>>> c.AppendText('a')
>>> c.GetInsertionPoint()
1
>>> len(c.GetValue())
1

Now we want to pass the event of adding a b
>>> event = wx.KeyEvent(wx.wxEVT_CHAR)
>>> event.m_keyCode = ord('a')
>>> event.GetKeyCode()
97
>>> c.SetFocus()
>>> c.GetEventHandler().ProcessEvent(event)
False
>>> event.Skip()
>>> c.GetValue()
u''
>>> c.GetEventHandler().ProcessEvent(event)
False
>>> c.GetValue()
u'a'

This fails when run, as c.GetValue() still has u''
______________________________________

I don't think this will behave correctly from a shell, but I could be mistaken. Did you try it in a self-contained script?

ยทยทยท

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Mike Driscoll wrote:

This was actually a fun poem...give yourself some credit!

Thanks.

>>> app = wx.App()
>>> app.frame = wx.Frame(None, -1)
>>> app.pan = wx.Panel(app.frame, -1)
>>> c = wx.TextCtrl(app.pan, -1)
>>> c.AppendText('a')
>>> c.GetInsertionPoint()
1
>>> len(c.GetValue())
1

Now we want to pass the event of adding a b
>>> event = wx.KeyEvent(wx.wxEVT_CHAR)
>>> event.m_keyCode = ord('a')
>>> event.GetKeyCode()
97
>>> c.SetFocus()
>>> c.GetEventHandler().ProcessEvent(event)
False
>>> event.Skip()
>>> c.GetValue()
u''
>>> c.GetEventHandler().ProcessEvent(event)
False
>>> c.GetValue()
u'a'

This fails when run, as c.GetValue() still has u''
______________________________________

I don't think this will behave correctly from a shell, but I could be mistaken. Did you try it in a self-contained script?

No, it was in a doctest in the docstring of the OnChar method.

I will try wrapping and running it...

Huh, it runs as a separate script (printing in all the places where I
expected values and they match). Go figure.

I have now also tweaked the doctest a bit, and it is also working.

All that dogrel for nothing. Well I hope people find it entertaining.

Thanks for the tip and the help. Now to write the rest of what is
needed to have some sort of working regression tests.

Rohan

Rohan wrote:

Mike Driscoll wrote:

This was actually a fun poem...give yourself some credit!

Thanks.

Funny start to my day, at least!