Changeset 996 for trunk


Ignore:
Timestamp:
Apr 25, 2019, 12:43:45 PM (3 months ago)
Author:
cito
Message:

Better error messages in inserttable() method

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/conn.c

    r991 r996  
    621621
    622622    /* checks list type */
    623     if (PyTuple_Check(list)) {
     623    if (PyList_Check(list)) {
     624        m = PyList_Size(list);
     625        getitem = PyList_GetItem;
     626    }
     627    else if (PyTuple_Check(list)) {
    624628        m = PyTuple_Size(list);
    625629        getitem = PyTuple_GetItem;
    626     }
    627     else if (PyList_Check(list)) {
    628         m = PyList_Size(list);
    629         getitem = PyList_GetItem;
    630630    }
    631631    else {
    632632        PyErr_SetString(
    633633            PyExc_TypeError,
    634             "Method inserttable() expects some kind of array"
     634            "Method inserttable() expects a list or a tuple"
    635635            " as second argument");
    636636        return NULL;
     
    674674            PyErr_SetString(
    675675                PyExc_TypeError,
    676                 "Second arg must contain some kind of arrays");
     676                "The second argument must contain a tuple or a list");
    677677            return NULL;
    678678        }
  • trunk/tests/test_classic_connection.py

    r991 r996  
    16421642        self.assertEqual(self.get_back(), data)
    16431643
     1644    def testInserttableFromTupleOfLists(self):
     1645        data = tuple(list(row) for row in self.data)
     1646        self.c.inserttable('test', data)
     1647        self.assertEqual(self.get_back(), self.data)
     1648
     1649    def testInserttableFromSetofTuples(self):
     1650        data = set(row for row in self.data)
     1651        try:
     1652            self.c.inserttable('test', data)
     1653        except TypeError as e:
     1654            r = str(e)
     1655        else:
     1656            r = 'this is fine'
     1657        self.assertIn('list or a tuple as second argument', r)
     1658
     1659    def testInserttableFromListOfSets(self):
     1660        data = [set(row) for row in self.data]
     1661        try:
     1662            self.c.inserttable('test', data)
     1663        except TypeError as e:
     1664            r = str(e)
     1665        else:
     1666            r = 'this is fine'
     1667        self.assertIn('second argument must contain a tuple or a list', r)
     1668
    16441669    def testInserttableMultipleRows(self):
    16451670        num_rows = 100
     
    17071732
    17081733    def testInserttableUnicodeLatin1(self):
    1709 
    17101734        try:
    17111735            self.c.query("set client_encoding=latin1")
Note: See TracChangeset for help on using the changeset viewer.