Changeset 878 for trunk/tests


Ignore:
Timestamp:
Jul 21, 2016, 12:57:25 PM (3 years ago)
Author:
cito
Message:

Allow extra keys in params to query_formatted()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/test_classic_dbwrapper.py

    r876 r878  
    894894        f = self.db.query_formatted
    895895        t = True if pg.get_bool() else 't'
     896        # test with tuple
    896897        q = f("select %s::int, %s::real, %s::text, %s::bool",
    897898              (3, 2.5, 'hello', True))
    898899        r = q.getresult()[0]
    899900        self.assertEqual(r, (3, 2.5, 'hello', t))
     901        # test with tuple, inline
    900902        q = f("select %s, %s, %s, %s", (3, 2.5, 'hello', True), inline=True)
    901903        r = q.getresult()[0]
     
    906908            r = tuple(r)
    907909        self.assertEqual(r, (3, 2.5, 'hello', t))
     910        # test with dict
     911        q = f("select %(a)s::int, %(b)s::real, %(c)s::text, %(d)s::bool",
     912              dict(a=3, b=2.5, c='hello', d=True))
     913        r = q.getresult()[0]
     914        self.assertEqual(r, (3, 2.5, 'hello', t))
     915        # test with dict, inline
     916        q = f("select %(a)s, %(b)s, %(c)s, %(d)s",
     917              dict(a=3, b=2.5, c='hello', d=True), inline=True)
     918        r = q.getresult()[0]
     919        if isinstance(r[1], Decimal):
     920            # Python 2.6 cannot compare float and Decimal
     921            r = list(r)
     922            r[1] = float(r[1])
     923            r = tuple(r)
     924        self.assertEqual(r, (3, 2.5, 'hello', t))
     925        # test with dict and extra values
     926        q = f("select %(a)s||%(b)s||%(c)s||%(d)s||'epsilon'",
     927              dict(a='alpha', b='beta', c='gamma', d='delta', e='extra'))
     928        r = q.getresult()[0][0]
     929        self.assertEqual(r, 'alphabetagammadeltaepsilon')
     930
     931
    908932
    909933    def testPkey(self):
Note: See TracChangeset for help on using the changeset viewer.