From a1c2bc60bd137b0faecb75a22f8c96c952c4ada4 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 23 May 2008 16:54:58 +0000 Subject: Merge from trunk: 2008-05-23 Johan Dahlin Merge from trunk: * gobject/__init__.py: * tests/test_properties.py: Allow gobject.property work with subclasses. Add tests. (#523352, Tomeu Vizoso) * gobject/pygsource.c: * tests/test_source.py: Unbreak Source.prepare (#523075, Bryan Silverthorn) * gobject/gobjectmodule.c (REGISTER_TYPE): Never override customly set 'tp_new' and 'tp_alloc'. * configure.ac: Don't link against libffi if we cannot find libffi on the system. (#496006, Ed Catmur) * Makefile.am: Dist .m4 files. (#496011, Ed Catmur) * gobject/pygenum.c (pyg_enum_richcompare): Don't return NULL after warning; more useful warning message (bug #519631). svn path=/branches/pygobject-2-14/; revision=781 --- tests/test_properties.py | 35 +++++++++++++++++++++++++++++++++++ tests/test_source.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) (limited to 'tests') diff --git a/tests/test_properties.py b/tests/test_properties.py index de93f62..a691b32 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -327,6 +327,41 @@ class TestProperty(unittest.TestCase): b.prop1 = 20 self.assertEquals(b.prop1, 20) + def testPropertySubclassCustomSetter(self): + # test for #523352 + class A(GObject): + def get_first(self): + return 'first' + first = gobject.property(type=str, getter=get_first) + + class B(A): + def get_second(self): + return 'second' + second = gobject.property(type=str, getter=get_second) + + a = A() + self.assertEquals(a.first, 'first') + self.assertRaises(TypeError, setattr, a, 'first', 'foo') + + b = B() + self.assertEquals(b.first, 'first') + self.assertRaises(TypeError, setattr, b, 'first', 'foo') + self.assertEquals(b.second, 'second') + self.assertRaises(TypeError, setattr, b, 'second', 'foo') + + def testPropertySubclassCustomSetterError(self): + try: + class A(GObject): + def get_first(self): + return 'first' + first = gobject.property(type=str, getter=get_first) + + def do_get_property(self, pspec): + pass + except TypeError: + pass + else: + raise AssertionError if __name__ == '__main__': unittest.main() diff --git a/tests/test_source.py b/tests/test_source.py index 5e0f01b..fd5f310 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -62,5 +62,33 @@ class TestSource(unittest.TestCase): assert self.pos >= 0 and idle.count >= 0 + def testSourcePrepare(self): + # this test may not terminate if prepare() is wrapped incorrectly + dispatched = [False] + loop = gobject.MainLoop() + + class CustomTimeout(gobject.Source): + def prepare(self): + return (False, 10) + + def check(self): + return True + + def dispatch(self, callback, args): + dispatched[0] = True + + loop.quit() + + return False + + source = CustomTimeout() + + source.attach() + source.set_callback(dir) + + loop.run() + + assert dispatched[0] + if __name__ == '__main__': unittest.main() -- cgit