| 1 |
import unittest |
| 2 |
|
| 3 |
from gi.repository import GObject |
| 4 |
import testhelper |
| 5 |
|
| 6 |
|
| 7 |
GUnknown = GObject.type_from_name("TestUnknown") |
| 8 |
Unknown = GUnknown.pytype |
| 9 |
|
| 10 |
|
| 11 |
class MyUnknown(Unknown, testhelper.Interface): |
| 12 |
some_property = GObject.Property(type=str) |
| 13 |
|
| 14 |
def __init__(self): |
| 15 |
Unknown.__init__(self) |
| 16 |
self.called = False |
| 17 |
|
| 18 |
def do_iface_method(self): |
| 19 |
self.called = True |
| 20 |
Unknown.do_iface_method(self) |
| 21 |
|
| 22 |
|
| 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 |
|
| 36 |
|
| 37 |
GObject.type_register(MyObject) |
| 38 |
|
| 39 |
|
| 40 |
class TestIfaceImpl(unittest.TestCase): |
| 41 |
def test_reimplement_interface(self): |
| 42 |
m = MyUnknown() |
| 43 |
m.iface_method() |
| 44 |
self.assertEqual(m.called, True) |
| 45 |
|
| 46 |
def test_implement_interface(self): |
| 47 |
m = MyObject() |
| 48 |
m.iface_method() |
| 49 |
self.assertEqual(m.called, True) |