Imported Upstream version 3.13.92
[platform/upstream/pygobject2.git] / tests / test_interface.py
1 # -*- Mode: Python -*-
2
3 import unittest
4
5 from gi.repository 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 test_reimplement_interface(self):
41         m = MyUnknown()
42         m.iface_method()
43         self.assertEqual(m.called, True)
44
45     def test_implement_interface(self):
46         m = MyObject()
47         m.iface_method()
48         self.assertEqual(m.called, True)