1 from __future__
import absolute_import
5 from gi
.repository
import GObject
6 from gi
.repository
import GIMarshallingTests
9 class CustomBase(GObject
.GObject
):
13 class CustomChild(CustomBase
, GIMarshallingTests
.Interface
):
17 class TestTypeModuleLevelFunctions(unittest
.TestCase
):
18 def test_type_name(self
):
19 self
.assertEqual(GObject
.type_name(GObject
.TYPE_NONE
), 'void')
20 self
.assertEqual(GObject
.type_name(GObject
.TYPE_OBJECT
), 'GObject')
21 self
.assertEqual(GObject
.type_name(GObject
.TYPE_PYOBJECT
), 'PyObject')
23 def test_type_from_name(self
):
24 # A complete test is not needed here since the TYPE_* defines are created
26 self
.assertRaises(RuntimeError, GObject
.type_from_name
, '!NOT_A_REAL_TYPE!')
27 self
.assertEqual(GObject
.type_from_name('GObject'), GObject
.TYPE_OBJECT
)
28 self
.assertEqual(GObject
.type_from_name('GObject'), GObject
.GObject
.__gtype
__)
30 def test_type_is_a(self
):
31 self
.assertTrue(GObject
.type_is_a(CustomBase
, GObject
.TYPE_OBJECT
))
32 self
.assertTrue(GObject
.type_is_a(CustomChild
, CustomBase
))
33 self
.assertTrue(GObject
.type_is_a(CustomBase
, GObject
.GObject
))
34 self
.assertTrue(GObject
.type_is_a(CustomBase
.__gtype
__, GObject
.TYPE_OBJECT
))
35 self
.assertFalse(GObject
.type_is_a(GObject
.TYPE_OBJECT
, CustomBase
))
36 self
.assertFalse(GObject
.type_is_a(CustomBase
, int)) # invalid type
37 self
.assertRaises(TypeError, GObject
.type_is_a
, CustomBase
, 1)
38 self
.assertRaises(TypeError, GObject
.type_is_a
, 2, GObject
.TYPE_OBJECT
)
39 self
.assertRaises(TypeError, GObject
.type_is_a
, 1, 2)
41 def test_type_children(self
):
42 self
.assertEqual(GObject
.type_children(CustomBase
), [CustomChild
.__gtype
__])
43 self
.assertEqual(len(GObject
.type_children(CustomChild
)), 0)
45 def test_type_interfaces(self
):
46 self
.assertEqual(len(GObject
.type_interfaces(CustomBase
)), 0)
47 self
.assertEqual(len(GObject
.type_interfaces(CustomChild
)), 1)
48 self
.assertEqual(GObject
.type_interfaces(CustomChild
), [GIMarshallingTests
.Interface
.__gtype
__])
50 def test_type_parent(self
):
51 self
.assertEqual(GObject
.type_parent(CustomChild
), CustomBase
.__gtype
__)
52 self
.assertEqual(GObject
.type_parent(CustomBase
), GObject
.TYPE_OBJECT
)
53 self
.assertRaises(RuntimeError, GObject
.type_parent
, GObject
.GObject
)
56 def test_gtype_has_value_table():
57 assert CustomBase
.__gtype
__.has_value_table()
58 assert not GIMarshallingTests
.Interface
.__gtype
__.has_value_table()
59 assert CustomChild
.__gtype
__.has_value_table()
62 def test_gtype_is_abstract():
63 assert not CustomBase
.__gtype
__.is_abstract()
64 assert not GIMarshallingTests
.Interface
.__gtype
__.is_abstract()
65 assert not CustomChild
.__gtype
__.is_abstract()
68 def test_gtype_is_classed():
69 assert CustomBase
.__gtype
__.is_classed()
70 assert not GIMarshallingTests
.Interface
.__gtype
__.is_classed()
71 assert CustomChild
.__gtype
__.is_classed()
74 def test_gtype_is_deep_derivable():
75 assert CustomBase
.__gtype
__.is_deep_derivable()
76 assert not GIMarshallingTests
.Interface
.__gtype
__.is_deep_derivable()
77 assert CustomChild
.__gtype
__.is_deep_derivable()
80 def test_gtype_is_derivable():
81 assert CustomBase
.__gtype
__.is_derivable()
82 assert GIMarshallingTests
.Interface
.__gtype
__.is_derivable()
83 assert CustomChild
.__gtype
__.is_derivable()
86 def test_gtype_is_value_abstract():
87 assert not CustomBase
.__gtype
__.is_value_abstract()
88 assert not GIMarshallingTests
.Interface
.__gtype
__.is_value_abstract()
89 assert not CustomChild
.__gtype
__.is_value_abstract()
92 def test_gtype_is_value_type():
93 assert CustomBase
.__gtype
__.is_value_type()
94 assert not GIMarshallingTests
.Interface
.__gtype
__.is_value_type()
95 assert CustomChild
.__gtype
__.is_value_type()
98 def test_gtype_children():
99 assert CustomBase
.__gtype
__.children
== [CustomChild
.__gtype
__]
100 assert GIMarshallingTests
.Interface
.__gtype
__.children
== []
101 assert CustomChild
.__gtype
__.children
== []
104 def test_gtype_depth():
105 assert CustomBase
.__gtype
__.depth
== 2
106 assert GIMarshallingTests
.Interface
.__gtype
__.depth
== 2
107 assert CustomChild
.__gtype
__.depth
== 3
110 def test_gtype_interfaces():
111 assert CustomBase
.__gtype
__.interfaces
== []
112 assert GIMarshallingTests
.Interface
.__gtype
__.interfaces
== []
113 assert CustomChild
.__gtype
__.interfaces
== \
114 [GIMarshallingTests
.Interface
.__gtype
__]