This works amazingly!
There should be a place in the manual or API that talks about running tests like this.
Thank you,

Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 3/15/2015 6:16 AM, claudio canepa wrote:


On Sat, Mar 14, 2015 at 8:59 PM, Brandon Keith Biggs <brandonkeithbi...@gmail.com <mailto:brandonkeithbi...@gmail.com>> 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 pyglet-users+unsubscr...@googlegroups.com <mailto:pyglet-users+unsubscr...@googlegroups.com>. To post to this group, send email to pyglet-users@googlegroups.com <mailto:pyglet-users@googlegroups.com>.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

--
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 pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to