3 from gi
.repository
import GObject
4 from gi
.repository
import GIMarshallingTests
7 class CustomBase(GObject
.GObject
):
11 class CustomChild(CustomBase
, GIMarshallingTests
.Interface
):
15 class TestTypeModuleLevelFunctions(unittest
.TestCase
):
16 def test_type_name(self
):
17 self
.assertEqual(GObject
.type_name(GObject
.TYPE_NONE
), 'void')
18 self
.assertEqual(GObject
.type_name(GObject
.TYPE_OBJECT
), 'GObject')
19 self
.assertEqual(GObject
.type_name(GObject
.TYPE_PYOBJECT
), 'PyObject')
21 def test_type_from_name(self
):
22 # A complete test is not needed here since the TYPE_* defines are created
24 self
.assertRaises(RuntimeError, GObject
.type_from_name
, '!NOT_A_REAL_TYPE!')
25 self
.assertEqual(GObject
.type_from_name('GObject'), GObject
.TYPE_OBJECT
)
26 self
.assertEqual(GObject
.type_from_name('GObject'), GObject
.GObject
.__gtype
__)
28 def test_type_is_a(self
):
29 self
.assertTrue(GObject
.type_is_a(CustomBase
, GObject
.TYPE_OBJECT
))
30 self
.assertTrue(GObject
.type_is_a(CustomChild
, CustomBase
))
31 self
.assertTrue(GObject
.type_is_a(CustomBase
, GObject
.GObject
))
32 self
.assertTrue(GObject
.type_is_a(CustomBase
.__gtype
__, GObject
.TYPE_OBJECT
))
33 self
.assertFalse(GObject
.type_is_a(GObject
.TYPE_OBJECT
, CustomBase
))
34 self
.assertFalse(GObject
.type_is_a(CustomBase
, int)) # invalid type
35 self
.assertRaises(TypeError, GObject
.type_is_a
, CustomBase
, 1)
36 self
.assertRaises(TypeError, GObject
.type_is_a
, 2, GObject
.TYPE_OBJECT
)
37 self
.assertRaises(TypeError, GObject
.type_is_a
, 1, 2)
39 def test_type_children(self
):
40 self
.assertEqual(GObject
.type_children(CustomBase
), [CustomChild
.__gtype
__])
41 self
.assertEqual(len(GObject
.type_children(CustomChild
)), 0)
43 def test_type_interfaces(self
):
44 self
.assertEqual(len(GObject
.type_interfaces(CustomBase
)), 0)
45 self
.assertEqual(len(GObject
.type_interfaces(CustomChild
)), 1)
46 self
.assertEqual(GObject
.type_interfaces(CustomChild
), [GIMarshallingTests
.Interface
.__gtype
__])
48 def test_type_parent(self
):
49 self
.assertEqual(GObject
.type_parent(CustomChild
), CustomBase
.__gtype
__)
50 self
.assertEqual(GObject
.type_parent(CustomBase
), GObject
.TYPE_OBJECT
)
51 self
.assertRaises(RuntimeError, GObject
.type_parent
, GObject
.GObject
)