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