File: test_typeclass.py

package info (click to toggle)
pygobject 3.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,492 kB
  • ctags: 5,045
  • sloc: ansic: 20,987; python: 15,991; sh: 4,659; makefile: 569; xml: 31
file content (80 lines) | stat: -rw-r--r-- 3,149 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# test_typeclass.py: Tests for GTypeClass related methods and marshalling.
#
# Copyright (C) 2014 Simon Feltman <sfeltman@gnome.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

import unittest

from gi.repository import GObject
from gi.repository import GIMarshallingTests


class TestCoercion(unittest.TestCase):
    def test_coerce_from_class(self):
        prop = GObject.ObjectClass.find_property(GIMarshallingTests.PropertiesObject,
                                                 'some-int')

        self.assertIsInstance(prop, GObject.GParamSpec)
        self.assertEqual(prop.name, 'some-int')
        self.assertEqual(prop.value_type, GObject.TYPE_INT)
        self.assertEqual(prop.owner_type,
                         GIMarshallingTests.PropertiesObject.__gtype__)

    def test_coerce_from_gtype(self):
        gtype = GIMarshallingTests.PropertiesObject.__gtype__
        prop = GObject.ObjectClass.find_property(gtype, 'some-int')

        self.assertIsInstance(prop, GObject.GParamSpec)
        self.assertEqual(prop.name, 'some-int')
        self.assertEqual(prop.value_type, GObject.TYPE_INT)
        self.assertEqual(prop.owner_type, gtype)

    def test_coerce_from_instance(self):
        obj = GIMarshallingTests.PropertiesObject()
        prop = GObject.ObjectClass.find_property(obj, 'some-int')

        self.assertIsInstance(prop, GObject.GParamSpec)
        self.assertEqual(prop.name, 'some-int')
        self.assertEqual(prop.value_type, GObject.TYPE_INT)
        self.assertEqual(prop.owner_type, obj.__gtype__)

    def test_marshalling_error(self):
        with self.assertRaises(TypeError):
            GObject.ObjectClass.find_property(object, 'some-int')

        with self.assertRaises(TypeError):
            GObject.ObjectClass.find_property(42, 'some-int')


class TestTypeClassMethodsMovedToClass(unittest.TestCase):
    def test_list_child_properties(self):
        pspecs = GIMarshallingTests.PropertiesObject.list_properties()
        pnames = [pspec.name for pspec in pspecs]
        self.assertTrue('some-int' in pnames)
        self.assertTrue('some-float' in pnames)
        self.assertTrue('some-char' in pnames)

    def test_find_child_property(self):
        pspec = GIMarshallingTests.PropertiesObject.find_property('some-int')
        self.assertEqual(pspec.name, 'some-int')


if __name__ == '__main__':
    unittest.main()