summaryrefslogtreecommitdiff
path: root/tests/test_interface.py
blob: ba20cb41db3fe2a41fc82f94c5935b770988f020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- Mode: Python -*-

import unittest

from gi.repository import GObject
import testhelper


GUnknown = GObject.type_from_name("TestUnknown")
Unknown = GUnknown.pytype


class MyUnknown(Unknown, testhelper.Interface):
    some_property = GObject.Property(type=str)

    def __init__(self):
        Unknown.__init__(self)
        self.called = False

    def do_iface_method(self):
        self.called = True
        Unknown.do_iface_method(self)


GObject.type_register(MyUnknown)


class MyObject(GObject.GObject, testhelper.Interface):
    some_property = GObject.Property(type=str)

    def __init__(self):
        GObject.GObject.__init__(self)
        self.called = False

    def do_iface_method(self):
        self.called = True


GObject.type_register(MyObject)


class TestIfaceImpl(unittest.TestCase):

    def test_reimplement_interface(self):
        m = MyUnknown()
        m.iface_method()
        self.assertEqual(m.called, True)

    def test_implement_interface(self):
        m = MyObject()
        m.iface_method()
        self.assertEqual(m.called, True)