summaryrefslogtreecommitdiff
path: root/tests/test_gi.py
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:16 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:19 +0900
commit2af8b46dbcf9e73f2ca40ea26cab5ab7ccac5d2a (patch)
tree5b4e30d98b770811a333c49562b319bd1f8e9224 /tests/test_gi.py
parent3b5dc6176476d5ed2313cd7185d985f47e225165 (diff)
downloadpygobject2-2af8b46dbcf9e73f2ca40ea26cab5ab7ccac5d2a.tar.gz
pygobject2-2af8b46dbcf9e73f2ca40ea26cab5ab7ccac5d2a.tar.bz2
pygobject2-2af8b46dbcf9e73f2ca40ea26cab5ab7ccac5d2a.zip
Imported Upstream version 3.7.3
Change-Id: I340c8ed6916f5312452a0b7b1bf0f0b7a2d91264 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests/test_gi.py')
-rw-r--r--tests/test_gi.py67
1 files changed, 66 insertions, 1 deletions
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 4837204..a2664f1 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -711,6 +711,7 @@ class TestFilename(unittest.TestCase):
dirname = GLib.Dir.make_tmp('testäø.XXXXXX')
self.assertTrue('/testäø.' in dirname, dirname)
+ dirname = _bytes(dirname)
self.assertTrue(os.path.isdir(dirname))
os.rmdir(dirname)
@@ -958,6 +959,11 @@ class TestGArray(unittest.TestCase):
def test_garray_utf8_full_out(self):
self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_full_out())
+ @unittest.skipUnless(hasattr(GIMarshallingTests, 'garray_utf8_full_out_caller_allocated'),
+ 'too old gobject-introspection')
+ def test_garray_utf8_full_out_caller_allocated(self):
+ self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_full_out_caller_allocated())
+
def test_garray_utf8_none_inout(self):
self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.garray_utf8_none_inout(Sequence(('0', '1', '2'))))
@@ -1355,6 +1361,42 @@ class TestGClosure(unittest.TestCase):
self.assertRaises(TypeError, GIMarshallingTests.gclosure_in, None)
+class TestCallbacks(unittest.TestCase):
+ def test_return_value_only(self):
+ def cb():
+ return 5
+ self.assertEqual(GIMarshallingTests.callback_return_value_only(cb), 5)
+
+ @unittest.expectedFailure
+ def test_one_out_arg(self):
+ def cb():
+ return 5.5
+ self.assertAlmostEqual(GIMarshallingTests.callback_one_out_parameter(cb), 5.5)
+
+ @unittest.expectedFailure
+ def test_multiple_out_args(self):
+ def cb():
+ return (5.5, 42.0)
+ res = GIMarshallingTests.callback_multiple_out_parameters(cb)
+ self.assertAlmostEqual(res[0], 5.5)
+ self.assertAlmostEqual(res[1], 42.0)
+
+ @unittest.expectedFailure
+ def test_return_and_one_out_arg(self):
+ def cb():
+ return (5, 42.0)
+ res = GIMarshallingTests.callback_return_value_and_one_out_parameter(cb)
+ self.assertEqual(res[0], 5)
+ self.assertAlmostEqual(res[1], 42.0)
+
+ @unittest.expectedFailure
+ def test_return_and_multiple_out_arg(self):
+ def cb():
+ return (5, 42, -1000)
+ self.assertEqual(GIMarshallingTests.callback_return_value_and_multiple_out_parameters(cb),
+ (5, 42, -1000))
+
+
class TestPointer(unittest.TestCase):
def test_pointer_in_return(self):
self.assertEqual(GIMarshallingTests.pointer_in_return(42), 42)
@@ -1916,6 +1958,15 @@ class TestPythonGObject(unittest.TestCase):
def do_method_int8_out(self):
return 42
+ def do_method_int8_arg_and_out_caller(self, arg):
+ return arg + 1
+
+ def do_method_int8_arg_and_out_callee(self, arg):
+ return arg + 1
+
+ def do_method_str_arg_out_ret(self, arg):
+ return (arg.upper(), len(arg))
+
def do_method_with_default_implementation(self, int8):
GIMarshallingTests.Object.do_method_with_default_implementation(self, int8)
self.props.int += int8
@@ -1971,6 +2022,12 @@ class TestPythonGObject(unittest.TestCase):
self.assertEqual(object_.val, 84)
self.assertEqual(object_.method_int8_out(), 42)
+ # can be dropped when bumping g-i dependencies to >= 1.35.2
+ if hasattr(object_, 'method_int8_arg_and_out_caller'):
+ self.assertEqual(object_.method_int8_arg_and_out_caller(42), 43)
+ self.assertEqual(object_.method_int8_arg_and_out_callee(42), 43)
+ self.assertEqual(object_.method_str_arg_out_ret('hello'), ('HELLO', 5))
+
object_.method_with_default_implementation(42)
self.assertEqual(object_.props.int, 84)
@@ -2302,8 +2359,16 @@ class TestOverrides(unittest.TestCase):
self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))
def test_module_name(self):
+ # overridden types
self.assertEqual(GIMarshallingTests.OverridesStruct.__module__, 'gi.overrides.GIMarshallingTests')
- self.assertEqual(GObject.InitiallyUnowned.__module__, 'gi.repository.GObject')
+ self.assertEqual(GIMarshallingTests.OverridesObject.__module__, 'gi.overrides.GIMarshallingTests')
+ self.assertEqual(GObject.Object.__module__, 'gi.overrides.GObject')
+
+ # not overridden
+ self.assertEqual(GIMarshallingTests.SubObject.__module__, 'gi.repository.GIMarshallingTests')
+ # FIXME: does not work with TEST_NAMES='test_thread test_gi.TestOverrides',
+ # it is importlib._bootstrap then
+ #self.assertEqual(GObject.InitiallyUnowned.__module__, 'gi.repository.GObject')
class TestDir(unittest.TestCase):