Debian Codegraph @

tests/test_gtype.py

raw
1 import unittest
2
3 from gi.repository import GObject
4 from gi.repository import GIMarshallingTests
5
6
7 class CustomBase(GObject.GObject):
8 pass
9
10
11 class CustomChild(CustomBase, GIMarshallingTests.Interface):
12 pass
13
14
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")
20
21 def test_type_from_name(self):
22 # A complete test is not needed here since the TYPE_* defines are created
23 # using this method.
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__)
27
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)
38
39 def test_type_children(self):
40 self.assertEqual(GObject.type_children(CustomBase), [CustomChild.__gtype__])
41 self.assertEqual(len(GObject.type_children(CustomChild)), 0)
42
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(
47 GObject.type_interfaces(CustomChild),
48 [GIMarshallingTests.Interface.__gtype__],
49 )
50
51 def test_type_parent(self):
52 self.assertEqual(GObject.type_parent(CustomChild), CustomBase.__gtype__)
53 self.assertEqual(GObject.type_parent(CustomBase), GObject.TYPE_OBJECT)
54 self.assertRaises(RuntimeError, GObject.type_parent, GObject.GObject)
55
56
57 def test_gtype_has_value_table():
58 assert CustomBase.__gtype__.has_value_table()
59 assert not GIMarshallingTests.Interface.__gtype__.has_value_table()
60 assert CustomChild.__gtype__.has_value_table()
61
62
63 def test_gtype_is_abstract():
64 assert not CustomBase.__gtype__.is_abstract()
65 assert not GIMarshallingTests.Interface.__gtype__.is_abstract()
66 assert not CustomChild.__gtype__.is_abstract()
67
68
69 def test_gtype_is_classed():
70 assert CustomBase.__gtype__.is_classed()
71 assert not GIMarshallingTests.Interface.__gtype__.is_classed()
72 assert CustomChild.__gtype__.is_classed()
73
74
75 def test_gtype_is_deep_derivable():
76 assert CustomBase.__gtype__.is_deep_derivable()
77 assert not GIMarshallingTests.Interface.__gtype__.is_deep_derivable()
78 assert CustomChild.__gtype__.is_deep_derivable()
79
80
81 def test_gtype_is_derivable():
82 assert CustomBase.__gtype__.is_derivable()
83 assert GIMarshallingTests.Interface.__gtype__.is_derivable()
84 assert CustomChild.__gtype__.is_derivable()
85
86
87 def test_gtype_is_value_abstract():
88 assert not CustomBase.__gtype__.is_value_abstract()
89 assert not GIMarshallingTests.Interface.__gtype__.is_value_abstract()
90 assert not CustomChild.__gtype__.is_value_abstract()
91
92
93 def test_gtype_is_value_type():
94 assert CustomBase.__gtype__.is_value_type()
95 assert not GIMarshallingTests.Interface.__gtype__.is_value_type()
96 assert CustomChild.__gtype__.is_value_type()
97
98
99 def test_gtype_children():
100 assert CustomBase.__gtype__.children == [CustomChild.__gtype__]
101 assert GIMarshallingTests.Interface.__gtype__.children == []
102 assert CustomChild.__gtype__.children == []
103
104
105 def test_gtype_depth():
106 assert CustomBase.__gtype__.depth == 2
107 assert GIMarshallingTests.Interface.__gtype__.depth == 2
108 assert CustomChild.__gtype__.depth == 3
109
110
111 def test_gtype_interfaces():
112 assert CustomBase.__gtype__.interfaces == []
113 assert GIMarshallingTests.Interface.__gtype__.interfaces == []
114 assert CustomChild.__gtype__.interfaces == [GIMarshallingTests.Interface.__gtype__]