functions: revert the function init order to make pylint happy again. See #217
[pygobject.git] / tests / test_typeclass.py
blobb584fdd9f9fad469272842f4b6ff2434157caadd
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
21 # USA
23 from __future__ import absolute_import
25 import unittest
27 from gi.repository import GObject
28 from gi.repository import GIMarshallingTests
31 class TestCoercion(unittest.TestCase):
32 def test_coerce_from_class(self):
33 prop = GObject.ObjectClass.find_property(GIMarshallingTests.PropertiesObject,
34 'some-int')
36 self.assertIsInstance(prop, GObject.GParamSpec)
37 self.assertEqual(prop.name, 'some-int')
38 self.assertEqual(prop.value_type, GObject.TYPE_INT)
39 self.assertEqual(prop.owner_type,
40 GIMarshallingTests.PropertiesObject.__gtype__)
42 def test_coerce_from_gtype(self):
43 gtype = GIMarshallingTests.PropertiesObject.__gtype__
44 prop = GObject.ObjectClass.find_property(gtype, 'some-int')
46 self.assertIsInstance(prop, GObject.GParamSpec)
47 self.assertEqual(prop.name, 'some-int')
48 self.assertEqual(prop.value_type, GObject.TYPE_INT)
49 self.assertEqual(prop.owner_type, gtype)
51 def test_coerce_from_instance(self):
52 obj = GIMarshallingTests.PropertiesObject()
53 prop = GObject.ObjectClass.find_property(obj, 'some-int')
55 self.assertIsInstance(prop, GObject.GParamSpec)
56 self.assertEqual(prop.name, 'some-int')
57 self.assertEqual(prop.value_type, GObject.TYPE_INT)
58 self.assertEqual(prop.owner_type, obj.__gtype__)
60 def test_marshalling_error(self):
61 with self.assertRaises(TypeError):
62 GObject.ObjectClass.find_property(object, 'some-int')
64 with self.assertRaises(TypeError):
65 GObject.ObjectClass.find_property(42, 'some-int')
68 class TestTypeClassMethodsMovedToClass(unittest.TestCase):
69 def test_list_child_properties(self):
70 pspecs = GIMarshallingTests.PropertiesObject.list_properties()
71 pnames = [pspec.name for pspec in pspecs]
72 self.assertTrue('some-int' in pnames)
73 self.assertTrue('some-float' in pnames)
74 self.assertTrue('some-char' in pnames)
76 def test_find_child_property(self):
77 pspec = GIMarshallingTests.PropertiesObject.find_property('some-int')
78 self.assertEqual(pspec.name, 'some-int')