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
25 from gi
.repository
import GIMarshallingTests
26 from gi
.repository
import Regress
29 ResultTuple
= gi
._gi
.ResultTuple
32 class TestResultTuple(unittest
.TestCase
):
35 self
.assertTrue(issubclass(ResultTuple
, tuple))
37 def test_create(self
):
38 new
= ResultTuple
._new
_type
([None, "foo", None, "bar"])
39 self
.assertTrue(issubclass(new
, ResultTuple
))
41 def test_repr_dir(self
):
42 new
= ResultTuple
._new
_type
([None, "foo", None, "bar"])
43 inst
= new([1, 2, 3, "a"])
45 self
.assertEqual(repr(inst
), "(1, foo=2, 3, bar='a')")
46 self
.assertTrue("foo" in dir(inst
))
48 def test_repr_dir_empty(self
):
49 new
= ResultTuple
._new
_type
([])
51 self
.assertEqual(repr(inst
), "()")
54 def test_getatttr(self
):
55 new
= ResultTuple
._new
_type
([None, "foo", None, "bar"])
56 inst
= new([1, 2, 3, "a"])
58 self
.assertTrue(hasattr(inst
, "foo"))
59 self
.assertEqual(inst
.foo
, inst
[1])
60 self
.assertRaises(AttributeError, getattr, inst
, "nope")
62 def test_pickle(self
):
63 new
= ResultTuple
._new
_type
([None, "foo", None, "bar"])
64 inst
= new([1, 2, 3, "a"])
66 inst2
= pickle
.loads(pickle
.dumps(inst
))
67 self
.assertEqual(inst2
, inst
)
68 self
.assertTrue(isinstance(inst2
, tuple))
69 self
.assertFalse(isinstance(inst2
, new
))
72 res
= GIMarshallingTests
.init_function([])
73 self
.assertEqual(repr(res
), "(True, argv=[])")
75 res
= GIMarshallingTests
.array_return_etc(5, 9)
76 self
.assertEqual(repr(res
), "([5, 0, 1, 9], sum=14)")
78 res
= GIMarshallingTests
.array_out_etc(-5, 9)
79 self
.assertEqual(repr(res
), "(ints=[-5, 0, 1, 9], sum=4)")
82 res
= GIMarshallingTests
.callback_multiple_out_parameters(cb
)
83 self
.assertEqual(repr(res
), "(a=1.0, b=2.0)")
85 def test_regress(self
):
86 res
= Regress
.TestObj().skip_return_val(50, 42.0, 60, 2, 3)
87 self
.assertEqual(repr(res
), "(out_b=51, inout_d=61, out_sum=32)")