Commit e8bd2535 authored by John (J5) Palmieri's avatar John (J5) Palmieri

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
parent f312e6a4
...@@ -1372,14 +1372,13 @@ _pygi_argument_to_object (GArgument *arg, ...@@ -1372,14 +1372,13 @@ _pygi_argument_to_object (GArgument *arg,
gsize i, item_size; gsize i, item_size;
if (arg->v_pointer == NULL) { if (arg->v_pointer == NULL) {
object = Py_None; object = PyList_New (0);
Py_INCREF (object);
break; break;
} }
array = arg->v_pointer; array = arg->v_pointer;
object = PyTuple_New (array->len); object = PyList_New (array->len);
if (object == NULL) { if (object == NULL) {
break; break;
} }
...@@ -1421,7 +1420,7 @@ _pygi_argument_to_object (GArgument *arg, ...@@ -1421,7 +1420,7 @@ _pygi_argument_to_object (GArgument *arg,
break; break;
} }
PyTuple_SET_ITEM (object, i, py_item); PyList_SET_ITEM (object, i, py_item);
} }
g_base_info_unref ( (GIBaseInfo *) item_type_info); g_base_info_unref ( (GIBaseInfo *) item_type_info);
......
...@@ -92,9 +92,12 @@ class TestNullableArgs(unittest.TestCase): ...@@ -92,9 +92,12 @@ class TestNullableArgs(unittest.TestCase):
def test_in_nullable_list(self): def test_in_nullable_list(self):
Everything.test_gslist_null_in(None) Everything.test_gslist_null_in(None)
Everything.test_glist_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): def test_in_nullable_array(self):
Everything.test_array_int_null_in(None) Everything.test_array_int_null_in(None)
Everything.test_array_int_null_in([])
def test_in_nullable_string(self): def test_in_nullable_string(self):
Everything.test_utf8_null_in(None) Everything.test_utf8_null_in(None)
...@@ -110,7 +113,7 @@ class TestNullableArgs(unittest.TestCase): ...@@ -110,7 +113,7 @@ class TestNullableArgs(unittest.TestCase):
self.assertEqual([], Everything.test_glist_null_out()) self.assertEqual([], Everything.test_glist_null_out())
def test_out_nullable_array(self): 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): def test_out_nullable_string(self):
self.assertEqual(None, Everything.test_utf8_null_out()) self.assertEqual(None, Everything.test_utf8_null_out())
......
...@@ -660,56 +660,56 @@ class TestUtf8(unittest.TestCase): ...@@ -660,56 +660,56 @@ class TestUtf8(unittest.TestCase):
class TestArray(unittest.TestCase): class TestArray(unittest.TestCase):
def test_array_fixed_int_return(self): 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): 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): 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, 42)
self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, None) self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, None)
def test_array_fixed_short_in(self): 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): 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): 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): 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): 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): 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): 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): def test_method_array_in(self):
object_ = GIMarshallingTests.Object() 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): def test_method_array_out(self):
object_ = GIMarshallingTests.Object() 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): def test_method_array_inout(self):
object_ = GIMarshallingTests.Object() 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): def test_method_array_return(self):
object_ = GIMarshallingTests.Object() 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): def test_array_fixed_out_struct(self):
struct1, struct2 = GIMarshallingTests.array_fixed_out_struct() struct1, struct2 = GIMarshallingTests.array_fixed_out_struct()
...@@ -720,84 +720,84 @@ class TestArray(unittest.TestCase): ...@@ -720,84 +720,84 @@ class TestArray(unittest.TestCase):
self.assertEquals(7, struct2.int8) self.assertEquals(7, struct2.int8)
def test_array_zero_terminated_return(self): 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): 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): 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): 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): 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): 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): def test_gstrv_in(self):
GIMarshallingTests.gstrv_in(Sequence(('0', '1', '2'))) GIMarshallingTests.gstrv_in(Sequence(['0', '1', '2']))
def test_gstrv_out(self): 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): 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): 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): class TestGArray(unittest.TestCase):
def test_garray_int_none_return(self): 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): 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): 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): 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): 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, 42)
self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, None) self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, None)
def test_garray_utf8_none_in(self): 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): 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): 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): 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): 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): 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): 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): 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): 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): class TestGList(unittest.TestCase):
...@@ -1208,7 +1208,7 @@ class TestStructure(unittest.TestCase): ...@@ -1208,7 +1208,7 @@ class TestStructure(unittest.TestCase):
self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct)) self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
self.assertEquals(0, struct.long_) self.assertEquals(0, struct.long_)
self.assertEquals(None, struct.g_strv) self.assertEquals([], struct.g_strv)
del struct del struct
...@@ -1232,7 +1232,7 @@ class TestStructure(unittest.TestCase): ...@@ -1232,7 +1232,7 @@ class TestStructure(unittest.TestCase):
self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct)) self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
self.assertEquals(42, struct.long_) self.assertEquals(42, struct.long_)
self.assertEquals(('0', '1', '2'), struct.g_strv) self.assertEquals(['0', '1', '2'], struct.g_strv)
del struct del struct
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment