[pygobject] return PyList instead of PyTuple for array, return empty list for NULL arrays



commit e8bd25355fbe7de38a28b7a0583167a2c0ffc31f
Author: John (J5) Palmieri <johnp redhat com>
Date:   Tue Jun 22 15:03:08 2010 -0400

    return PyList instead of PyTuple for array, return empty list for NULL arrays
    
    * returns an empty list when a NULL array (empty array) is encountered
    * fix tests to check for lists instead of tuples or None
    * test the ability to send in both None and empty list for arrays and lists

 gi/pygi-argument.c       |    7 ++--
 tests/test_everything.py |    5 ++-
 tests/test_gi.py         |   84 +++++++++++++++++++++++-----------------------
 3 files changed, 49 insertions(+), 47 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 76fa58d..9533805 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1372,14 +1372,13 @@ _pygi_argument_to_object (GArgument  *arg,
             gsize i, item_size;
 
             if (arg->v_pointer == NULL) {
-                object = Py_None;
-                Py_INCREF (object);
+                object = PyList_New (0);
                 break;
             }
 
             array = arg->v_pointer;
 
-            object = PyTuple_New (array->len);
+            object = PyList_New (array->len);
             if (object == NULL) {
                 break;
             }
@@ -1421,7 +1420,7 @@ _pygi_argument_to_object (GArgument  *arg,
                     break;
                 }
 
-                PyTuple_SET_ITEM (object, i, py_item);
+                PyList_SET_ITEM (object, i, py_item);
             }
 
             g_base_info_unref ( (GIBaseInfo *) item_type_info);
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 36de1e3..c7c0385 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -92,9 +92,12 @@ class TestNullableArgs(unittest.TestCase):
     def test_in_nullable_list(self):
         Everything.test_gslist_null_in(None)
         Everything.test_glist_null_in(None)
+        Everything.test_gslist_null_in([])
+        Everything.test_glist_null_in([])
 
     def test_in_nullable_array(self):
         Everything.test_array_int_null_in(None)
+        Everything.test_array_int_null_in([])
 
     def test_in_nullable_string(self):
         Everything.test_utf8_null_in(None)
@@ -110,7 +113,7 @@ class TestNullableArgs(unittest.TestCase):
         self.assertEqual([], Everything.test_glist_null_out())
 
     def test_out_nullable_array(self):
-        self.assertEqual(None, Everything.test_array_int_null_out())
+        self.assertEqual([], Everything.test_array_int_null_out())
 
     def test_out_nullable_string(self):
         self.assertEqual(None, Everything.test_utf8_null_out())
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 2541c2d..924d9e5 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -660,56 +660,56 @@ class TestUtf8(unittest.TestCase):
 class TestArray(unittest.TestCase):
 
     def test_array_fixed_int_return(self):
-        self.assertEquals((-1, 0, 1, 2), GIMarshallingTests.array_fixed_int_return())
+        self.assertEquals([-1, 0, 1, 2], GIMarshallingTests.array_fixed_int_return())
 
     def test_array_fixed_short_return(self):
-        self.assertEquals((-1, 0, 1, 2), GIMarshallingTests.array_fixed_short_return())
+        self.assertEquals([-1, 0, 1, 2], GIMarshallingTests.array_fixed_short_return())
 
     def test_array_fixed_int_in(self):
-        GIMarshallingTests.array_fixed_int_in(Sequence((-1, 0, 1, 2)))
+        GIMarshallingTests.array_fixed_int_in(Sequence([-1, 0, 1, 2]))
 
-        self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, Sequence((-1, '0', 1, 2)))
+        self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, Sequence([-1, '0', 1, 2]))
 
         self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, 42)
         self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, None)
 
     def test_array_fixed_short_in(self):
-        GIMarshallingTests.array_fixed_short_in(Sequence((-1, 0, 1, 2)))
+        GIMarshallingTests.array_fixed_short_in(Sequence([-1, 0, 1, 2]))
 
     def test_array_fixed_out(self):
-        self.assertEquals((-1, 0, 1, 2), GIMarshallingTests.array_fixed_out())
+        self.assertEquals([-1, 0, 1, 2], GIMarshallingTests.array_fixed_out())
 
     def test_array_fixed_inout(self):
-        self.assertEquals((2, 1, 0, -1), GIMarshallingTests.array_fixed_inout((-1, 0, 1, 2)))
+        self.assertEquals([2, 1, 0, -1], GIMarshallingTests.array_fixed_inout([-1, 0, 1, 2]))
 
 
     def test_array_return(self):
-        self.assertEquals((-1, 0, 1, 2), GIMarshallingTests.array_return())
+        self.assertEquals([-1, 0, 1, 2], GIMarshallingTests.array_return())
 
     def test_array_in(self):
-        GIMarshallingTests.array_in(Sequence((-1, 0, 1, 2)))
+        GIMarshallingTests.array_in(Sequence([-1, 0, 1, 2]))
 
     def test_array_out(self):
-        self.assertEquals((-1, 0, 1, 2), GIMarshallingTests.array_out())
+        self.assertEquals([-1, 0, 1, 2], GIMarshallingTests.array_out())
 
     def test_array_inout(self):
-        self.assertEquals((-2, -1, 0, 1, 2), GIMarshallingTests.array_inout(Sequence((-1, 0, 1, 2))))
+        self.assertEquals([-2, -1, 0, 1, 2], GIMarshallingTests.array_inout(Sequence([-1, 0, 1, 2])))
 
     def test_method_array_in(self):
         object_ = GIMarshallingTests.Object()
-        object_.method_array_in(Sequence((-1, 0, 1, 2)))
+        object_.method_array_in(Sequence([-1, 0, 1, 2]))
 
     def test_method_array_out(self):
         object_ = GIMarshallingTests.Object()
-        self.assertEquals((-1, 0, 1, 2), object_.method_array_out())
+        self.assertEquals([-1, 0, 1, 2], object_.method_array_out())
 
     def test_method_array_inout(self):
         object_ = GIMarshallingTests.Object()
-        self.assertEquals((-2, -1, 0, 1, 2), object_.method_array_inout(Sequence((-1, 0, 1, 2))))
+        self.assertEquals([-2, -1, 0, 1, 2], object_.method_array_inout(Sequence([-1, 0, 1, 2])))
 
     def test_method_array_return(self):
         object_ = GIMarshallingTests.Object()
-        self.assertEquals((-1, 0, 1, 2), object_.method_array_return())
+        self.assertEquals([-1, 0, 1, 2], object_.method_array_return())
 
     def test_array_fixed_out_struct(self):
         struct1, struct2 = GIMarshallingTests.array_fixed_out_struct()
@@ -720,84 +720,84 @@ class TestArray(unittest.TestCase):
         self.assertEquals(7, struct2.int8)
 
     def test_array_zero_terminated_return(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.array_zero_terminated_return())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_return())
 
     def test_array_zero_terminated_in(self):
-        GIMarshallingTests.array_zero_terminated_in(Sequence(('0', '1', '2')))
+        GIMarshallingTests.array_zero_terminated_in(Sequence(['0', '1', '2']))
 
     def test_array_zero_terminated_out(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.array_zero_terminated_out())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_out())
 
     def test_array_zero_terminated_out(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.array_zero_terminated_out())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_out())
 
     def test_array_zero_terminated_inout(self):
-        self.assertEquals(('-1', '0', '1', '2'), GIMarshallingTests.array_zero_terminated_inout(('0', '1', '2')))
+        self.assertEquals(['-1', '0', '1', '2'], GIMarshallingTests.array_zero_terminated_inout(['0', '1', '2']))
 
     def test_gstrv_return(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.gstrv_return())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.gstrv_return())
 
     def test_gstrv_in(self):
-        GIMarshallingTests.gstrv_in(Sequence(('0', '1', '2')))
+        GIMarshallingTests.gstrv_in(Sequence(['0', '1', '2']))
 
     def test_gstrv_out(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.gstrv_out())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.gstrv_out())
 
     def test_gstrv_out(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.gstrv_out())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.gstrv_out())
 
     def test_gstrv_inout(self):
-        self.assertEquals(('-1', '0', '1', '2'), GIMarshallingTests.gstrv_inout(('0', '1', '2')))
+        self.assertEquals(['-1', '0', '1', '2'], GIMarshallingTests.gstrv_inout(['0', '1', '2']))
 
 
 class TestGArray(unittest.TestCase):
 
     def test_garray_int_none_return(self):
-        self.assertEquals((-1, 0, 1, 2), GIMarshallingTests.garray_int_none_return())
+        self.assertEquals([-1, 0, 1, 2], GIMarshallingTests.garray_int_none_return())
 
     def test_garray_utf8_none_return(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_none_return())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.garray_utf8_none_return())
 
     def test_garray_utf8_container_return(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_container_return())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.garray_utf8_container_return())
 
     def test_garray_utf8_full_return(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_full_return())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.garray_utf8_full_return())
 
     def test_garray_int_none_in(self):
-        GIMarshallingTests.garray_int_none_in(Sequence((-1, 0, 1, 2)))
+        GIMarshallingTests.garray_int_none_in(Sequence([-1, 0, 1, 2]))
 
-        self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, Sequence((-1, '0', 1, 2)))
+        self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, Sequence([-1, '0', 1, 2]))
 
         self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, 42)
         self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, None)
 
     def test_garray_utf8_none_in(self):
-        GIMarshallingTests.garray_utf8_none_in(Sequence(('0', '1', '2')))
+        GIMarshallingTests.garray_utf8_none_in(Sequence(['0', '1', '2']))
 
     def test_garray_utf8_container_in(self):
-        GIMarshallingTests.garray_utf8_container_in(Sequence(('0', '1', '2')))
+        GIMarshallingTests.garray_utf8_container_in(Sequence(['0', '1', '2']))
 
     def test_garray_utf8_full_in(self):
-        GIMarshallingTests.garray_utf8_full_in(Sequence(('0', '1', '2')))
+        GIMarshallingTests.garray_utf8_full_in(Sequence(['0', '1', '2']))
 
     def test_garray_utf8_none_out(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_none_out())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.garray_utf8_none_out())
 
     def test_garray_utf8_container_out(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_container_out())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.garray_utf8_container_out())
 
     def test_garray_utf8_full_out(self):
-        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_full_out())
+        self.assertEquals(['0', '1', '2'], GIMarshallingTests.garray_utf8_full_out())
 
     def test_garray_utf8_none_inout(self):
-        self.assertEquals(('-2', '-1', '0', '1'), GIMarshallingTests.garray_utf8_none_inout(Sequence(('0', '1', '2'))))
+        self.assertEquals(['-2', '-1', '0', '1'], GIMarshallingTests.garray_utf8_none_inout(Sequence(('0', '1', '2'))))
 
     def test_garray_utf8_container_inout(self):
-        self.assertEquals(('-2', '-1','0', '1'), GIMarshallingTests.garray_utf8_container_inout(('0', '1', '2')))
+        self.assertEquals(['-2', '-1','0', '1'], GIMarshallingTests.garray_utf8_container_inout(['0', '1', '2']))
 
     def test_garray_utf8_full_inout(self):
-        self.assertEquals(('-2', '-1','0', '1'), GIMarshallingTests.garray_utf8_full_inout(('0', '1', '2')))
+        self.assertEquals(['-2', '-1','0', '1'], GIMarshallingTests.garray_utf8_full_inout(['0', '1', '2']))
 
 
 class TestGList(unittest.TestCase):
@@ -1208,7 +1208,7 @@ class TestStructure(unittest.TestCase):
         self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
 
         self.assertEquals(0, struct.long_)
-        self.assertEquals(None, struct.g_strv)
+        self.assertEquals([], struct.g_strv)
 
         del struct
 
@@ -1232,7 +1232,7 @@ class TestStructure(unittest.TestCase):
 
         self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
         self.assertEquals(42, struct.long_)
-        self.assertEquals(('0', '1', '2'), struct.g_strv)
+        self.assertEquals(['0', '1', '2'], struct.g_strv)
 
         del struct
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]