functions: revert the function init order to make pylint happy again. See #217
[pygobject.git] / tests / test_resulttuple.py
blob4576495269ed04dd3262ae4901bb60c6ee789c95
1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
4 # Copyright (C) 2015 Christoph Reiter <reiter.christoph@gmail.com>
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 # USA
21 from __future__ import absolute_import
23 import unittest
24 import pickle
26 import gi
27 from gi.repository import GIMarshallingTests
28 from gi.repository import Regress
31 ResultTuple = gi._gi.ResultTuple
34 class TestResultTuple(unittest.TestCase):
36 def test_base(self):
37 self.assertTrue(issubclass(ResultTuple, tuple))
39 def test_create(self):
40 names = [None, "foo", None, "bar"]
41 for i in range(10):
42 new = ResultTuple._new_type(names)
43 self.assertTrue(issubclass(new, ResultTuple))
45 def test_repr_dir(self):
46 new = ResultTuple._new_type([None, "foo", None, "bar"])
47 inst = new([1, 2, 3, "a"])
49 self.assertEqual(repr(inst), "(1, foo=2, 3, bar='a')")
50 self.assertTrue("foo" in dir(inst))
52 def test_repr_dir_empty(self):
53 new = ResultTuple._new_type([])
54 inst = new()
55 self.assertEqual(repr(inst), "()")
56 dir(inst)
58 def test_getatttr(self):
59 new = ResultTuple._new_type([None, "foo", None, "bar"])
60 inst = new([1, 2, 3, "a"])
62 self.assertTrue(hasattr(inst, "foo"))
63 self.assertEqual(inst.foo, inst[1])
64 self.assertRaises(AttributeError, getattr, inst, "nope")
66 def test_pickle(self):
67 new = ResultTuple._new_type([None, "foo", None, "bar"])
68 inst = new([1, 2, 3, "a"])
70 inst2 = pickle.loads(pickle.dumps(inst))
71 self.assertEqual(inst2, inst)
72 self.assertTrue(isinstance(inst2, tuple))
73 self.assertFalse(isinstance(inst2, new))
75 def test_gi(self):
76 res = GIMarshallingTests.init_function([])
77 self.assertEqual(repr(res), "(True, argv=[])")
79 res = GIMarshallingTests.array_return_etc(5, 9)
80 self.assertEqual(repr(res), "([5, 0, 1, 9], sum=14)")
82 res = GIMarshallingTests.array_out_etc(-5, 9)
83 self.assertEqual(repr(res), "(ints=[-5, 0, 1, 9], sum=4)")
85 cb = lambda: (1, 2)
86 res = GIMarshallingTests.callback_multiple_out_parameters(cb)
87 self.assertEqual(repr(res), "(a=1.0, b=2.0)")
89 def test_regress(self):
90 res = Regress.TestObj().skip_return_val(50, 42.0, 60, 2, 3)
91 self.assertEqual(repr(res), "(out_b=51, inout_d=61, out_sum=32)")