functions: revert the function init order to make pylint happy again. See #217
[pygobject.git] / tests / test_gtype.py
blobb9d3349d65485157e1bc28b29e8857e86a94c6db
1 from __future__ import absolute_import
3 import unittest
5 from gi.repository import GObject
6 from gi.repository import GIMarshallingTests
9 class CustomBase(GObject.GObject):
10 pass
13 class CustomChild(CustomBase, GIMarshallingTests.Interface):
14 pass
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
25 # using this method.
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__]