diff options
author | Manish Singh <yosh@src.gnome.org> | 2005-07-10 22:17:15 +0000 |
---|---|---|
committer | Manish Singh <yosh@src.gnome.org> | 2005-07-10 22:17:15 +0000 |
commit | e21ff29b499e826db720a85ad6ad4d1fa04ebc1c (patch) | |
tree | b26a3de49d939f15e8b0a7851f523216fe722227 /tests/test_source.py | |
parent | 50b04202cf2af33f8fe9f610a2dd4b100b422ab8 (diff) | |
download | pygobject-e21ff29b499e826db720a85ad6ad4d1fa04ebc1c.tar.gz pygobject-e21ff29b499e826db720a85ad6ad4d1fa04ebc1c.tar.xz pygobject-e21ff29b499e826db720a85ad6ad4d1fa04ebc1c.zip |
gobject/pygobject-private.h gobject/gobjectmodule.c gobject/Makefile.am
* gobject/pygobject-private.h
* gobject/gobjectmodule.c
* gobject/Makefile.am
* gobject/pygsource.c: GSource wrapper, allows for pure python
GSource implementations, as well as objectifying Idle and Timeout
sources.
* tests/Makefile.am
* tests/test_source.py: Add test for the above.
* gobject/gobjectmodule.c: timeout_add should take an explicit
unsigned value. Also wrap g_get_current_time and g_main_depth.
* gobject/pygiochannel.c (py_io_channel_write_chars): fix thread
unblock/block logic.
Diffstat (limited to 'tests/test_source.py')
-rw-r--r-- | tests/test_source.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_source.py b/tests/test_source.py new file mode 100644 index 0000000..5e0f01b --- /dev/null +++ b/tests/test_source.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +import exceptions +import os +import sys +import select +import unittest + +from common import gobject + +class Idle(gobject.Idle): + def __init__(self, loop): + gobject.Idle.__init__(self) + self.count = 0 + self.set_callback(self.callback, loop) + + def callback(self, loop): + self.count += 1 + return True + +class MySource(gobject.Source): + def __init__(self): + gobject.Source.__init__(self) + + def prepare(self): + return True, 0 + + def check(self): + return True + + def dispatch(self, callback, args): + return callback(*args) + +class TestSource(unittest.TestCase): + def timeout_callback(self, loop): + loop.quit() + + def my_callback(self, loop): + self.pos += 1 + return True + + def setup_timeout(self, loop): + timeout = gobject.Timeout(500) + timeout.set_callback(self.timeout_callback, loop) + timeout.attach() + + def testSources(self): + loop = gobject.MainLoop() + + self.setup_timeout(loop) + + idle = Idle(loop) + idle.attach() + + self.pos = 0 + + m = MySource() + m.set_callback(self.my_callback, loop) + m.attach() + + loop.run() + + assert self.pos >= 0 and idle.count >= 0 + +if __name__ == '__main__': + unittest.main() |