On Sat, Mar 14, 2015 at 8:59 PM, Brandon Keith Biggs <
[email protected]> wrote:
> Hello,
> So the dispatch_event works great, but now I can't seem to get it to work
> with unittest, nose or py.test.
> I have the following code in my py.test file:
>
>
> import pyglet
> k = pyglet.window.key
> my_app = pyglet.app
> window = pyglet.window.Window(caption="Test app")
>
> def setup_module(module):
> my_app.run()
>
> def teardown_module(module):
> my_app.exit()
>
> def test_keys():
> r = False
> def on_key_press(key, mods):
> if key == k.A:
> r = True
> window.push_handlers(on_key_press)
> window.dispatch_event('on_key_press', k.A, 0)
> assert r == True
>
>
> When it runs, it says that r is False.
> Also, the window does not close. Does anyone know why this is?
> thanks,
>
>
> <http://www.brandonkeithbiggs.com/>
>
You probably not want to put app.run in tear up, because that wiil not
return.
The test, without any third party helper (py.test, unittest) can be written
as
import pyglet
k = pyglet.window.key
my_app = pyglet.app
window = pyglet.window.Window(caption="Test app")
r = False
def on_key_press(key, mods):
global r
if key == k.A:
r = True
my_app.exit()
def send_key(dt):
window.dispatch_event('on_key_press', k.A, 0)
window.push_handlers()
window.set_handler("on_key_press", on_key_press)
pyglet.clock.schedule_once(send_key, 1.0)
my_app.run()
assert r == True
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.