Debian Codegraph @

tests/test_typeclass.py

raw
1 # test_typeclass.py: Tests for GTypeClass related methods and marshalling.
2 #
3 # Copyright (C) 2014 Simon Feltman <[email protected]>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18 # USA
19
20 import unittest
21
22 from gi.repository import GObject
23 from gi.repository import GIMarshallingTests
24
25
26 class TestCoercion(unittest.TestCase):
27 def test_coerce_from_class(self):
28 prop = GObject.ObjectClass.find_property(
29 GIMarshallingTests.PropertiesObject, "some-int"
30 )
31
32 self.assertIsInstance(prop, GObject.ParamSpec)
33 self.assertEqual(prop.name, "some-int")
34 self.assertEqual(prop.value_type, GObject.TYPE_INT)
35 self.assertEqual(prop.owner_type, GIMarshallingTests.PropertiesObject.__gtype__)
36
37 def test_coerce_from_gtype(self):
38 gtype = GIMarshallingTests.PropertiesObject.__gtype__
39 prop = GObject.ObjectClass.find_property(gtype, "some-int")
40
41 self.assertIsInstance(prop, GObject.ParamSpec)
42 self.assertEqual(prop.name, "some-int")
43 self.assertEqual(prop.value_type, GObject.TYPE_INT)
44 self.assertEqual(prop.owner_type, gtype)
45
46 def test_coerce_from_instance(self):
47 obj = GIMarshallingTests.PropertiesObject()
48 prop = GObject.ObjectClass.find_property(obj, "some-int")
49
50 self.assertIsInstance(prop, GObject.ParamSpec)
51 self.assertEqual(prop.name, "some-int")
52 self.assertEqual(prop.value_type, GObject.TYPE_INT)
53 self.assertEqual(prop.owner_type, obj.__gtype__)
54
55 def test_marshalling_error(self):
56 with self.assertRaises(TypeError):
57 GObject.ObjectClass.find_property(object, "some-int")
58
59 with self.assertRaises(TypeError):
60 GObject.ObjectClass.find_property(42, "some-int")
61
62
63 class TestTypeClassMethodsMovedToClass(unittest.TestCase):
64 def test_list_child_properties(self):
65 pspecs = GIMarshallingTests.PropertiesObject.list_properties()
66 pnames = [pspec.name for pspec in pspecs]
67 self.assertTrue("some-int" in pnames)
68 self.assertTrue("some-float" in pnames)
69 self.assertTrue("some-char" in pnames)
70
71 def test_find_child_property(self):
72 pspec = GIMarshallingTests.PropertiesObject.find_property("some-int")
73 self.assertEqual(pspec.name, "some-int")