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 | 8d12c8ab15831709973b26e043f477de9bf6b543 (patch) | |
tree | ccf9402a513b1bbc1c6a9be93269035e7242994b /tests | |
parent | ae74bdd14dc6af56c21202eebe39b5149653a6cf (diff) | |
download | pygtk-8d12c8ab15831709973b26e043f477de9bf6b543.tar.gz |
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')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/test_source.py | 66 |
2 files changed, 68 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 25a1a6d8..b6ced0ed 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,7 +30,8 @@ tests = \ test_subprocess.py \ test_subtype.py \ test_gdkevent.py \ - test_unknown.py + test_unknown.py \ + test_source.py # This is a hack to make sure a shared library is built testhelper.la: $(testhelper_la_OBJECTS) $(testhelper_la_DEPENDENCIES) diff --git a/tests/test_source.py b/tests/test_source.py new file mode 100644 index 00000000..5e0f01b7 --- /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() |