Title: [996] trunk: Better error messages in inserttable() method
- Revision
- 996
- Author
- cito
- Date
- 2019-04-25 12:43:45 -0400 (Thu, 25 Apr 2019)
Log Message
Better error messages in inserttable() method
Modified Paths
Diff
Modified: trunk/conn.c (995 => 996)
--- trunk/conn.c 2019-04-25 14:10:20 UTC (rev 995)
+++ trunk/conn.c 2019-04-25 16:43:45 UTC (rev 996)
@@ -620,18 +620,18 @@
}
/* checks list type */
- if (PyTuple_Check(list)) {
+ if (PyList_Check(list)) {
+ m = PyList_Size(list);
+ getitem = PyList_GetItem;
+ }
+ else if (PyTuple_Check(list)) {
m = PyTuple_Size(list);
getitem = PyTuple_GetItem;
}
- else if (PyList_Check(list)) {
- m = PyList_Size(list);
- getitem = PyList_GetItem;
- }
else {
PyErr_SetString(
PyExc_TypeError,
- "Method inserttable() expects some kind of array"
+ "Method inserttable() expects a list or a tuple"
" as second argument");
return NULL;
}
@@ -673,7 +673,7 @@
else {
PyErr_SetString(
PyExc_TypeError,
- "Second arg must contain some kind of arrays");
+ "The second argument must contain a tuple or a list");
return NULL;
}
if (i) {
Modified: trunk/tests/test_classic_connection.py (995 => 996)
--- trunk/tests/test_classic_connection.py 2019-04-25 14:10:20 UTC (rev 995)
+++ trunk/tests/test_classic_connection.py 2019-04-25 16:43:45 UTC (rev 996)
@@ -1641,6 +1641,31 @@
self.c.inserttable('test', data)
self.assertEqual(self.get_back(), data)
+ def testInserttableFromTupleOfLists(self):
+ data = "" for row in self.data)
+ self.c.inserttable('test', data)
+ self.assertEqual(self.get_back(), self.data)
+
+ def testInserttableFromSetofTuples(self):
+ data = "" for row in self.data)
+ try:
+ self.c.inserttable('test', data)
+ except TypeError as e:
+ r = str(e)
+ else:
+ r = 'this is fine'
+ self.assertIn('list or a tuple as second argument', r)
+
+ def testInserttableFromListOfSets(self):
+ data = "" for row in self.data]
+ try:
+ self.c.inserttable('test', data)
+ except TypeError as e:
+ r = str(e)
+ else:
+ r = 'this is fine'
+ self.assertIn('second argument must contain a tuple or a list', r)
+
def testInserttableMultipleRows(self):
num_rows = 100
data = "" * num_rows
@@ -1706,7 +1731,6 @@
self.assertEqual(self.get_back(), data)
def testInserttableUnicodeLatin1(self):
-
try:
self.c.query("set client_encoding=latin1")
self.c.query("select '¥'")
_______________________________________________
PyGreSQL mailing list
PyGreSQL@Vex.Net
https://mail.vex.net/mailman/listinfo/pygresql