fbc05860f27ddcd145f80e509c7864e076955c9d
[platform/upstream/pygobject2.git] / tests / test_interface.py
1 # -*- Mode: Python -*-
2
3 import unittest
4
5 import gobject
6 import testhelper
7
8
9 GUnknown = gobject.type_from_name("TestUnknown")
10 Unknown = GUnknown.pytype
11
12
13 class MyUnknown(Unknown, testhelper.Interface):
14     some_property = gobject.property(type=str)
15
16     def __init__(self):
17         Unknown.__init__(self)
18         self.called = False
19
20     def do_iface_method(self):
21         self.called = True
22         Unknown.do_iface_method(self)
23 gobject.type_register(MyUnknown)
24
25
26 class MyObject(gobject.GObject, testhelper.Interface):
27     some_property = gobject.property(type=str)
28
29     def __init__(self):
30         gobject.GObject.__init__(self)
31         self.called = False
32
33     def do_iface_method(self):
34         self.called = True
35 gobject.type_register(MyObject)
36
37
38 class TestIfaceImpl(unittest.TestCase):
39
40     def testReImplementInterface(self):
41         m = MyUnknown()
42         m.iface_method()
43         self.assertEqual(m.called, True)
44
45     def testImplementInterface(self):
46         m = MyObject()
47         m.iface_method()
48         self.assertEqual(m.called, True)
49