Changeset 571


Ignore:
Timestamp:
Nov 21, 2015, 9:19:33 AM (4 years ago)
Author:
cito
Message:

Adapt tests for long ints under Python 3

We need to make some small adaptations to the tests, because the
"L" suffix for longs and the long type itself are no longer there.

Location:
trunk/module
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/TEST_PyGreSQL_classic_connection.py

    r568 r571  
    2626
    2727from decimal import Decimal
     28
     29try:
     30    long
     31except NameError:  # Python >= 3.0
     32    long = int
    2833
    2934# We need a database to test against.  If LOCAL_PyGreSQL.py exists we will
     
    254259
    255260    def testGetresultLong(self):
    256         q = "select 1234567890123456790"
    257         result = 1234567890123456790L
     261        q = "select 9876543210"
     262        result = long(9876543210)
     263        self.assertIsInstance(result, long)
    258264        v = self.c.query(q).getresult()[0][0]
    259265        self.assertIsInstance(v, long)
     266        self.assertEqual(v, result)
     267
     268    def testGetresultDecimal(self):
     269        q = "select 98765432109876543210"
     270        result = Decimal(98765432109876543210)
     271        v = self.c.query(q).getresult()[0][0]
     272        self.assertIsInstance(v, Decimal)
    260273        self.assertEqual(v, result)
    261274
     
    278291
    279292    def testDictresultLong(self):
    280         q = "select 1234567890123456790 as longjohnsilver"
    281         result = 1234567890123456790L
     293        q = "select 9876543210 as longjohnsilver"
     294        result = long(9876543210)
     295        self.assertIsInstance(result, long)
    282296        v = self.c.query(q).dictresult()[0]['longjohnsilver']
    283297        self.assertIsInstance(v, long)
     298        self.assertEqual(v, result)
     299
     300    def testDictresultDecimal(self):
     301        q = "select 98765432109876543210 as longjohnsilver"
     302        result = Decimal(98765432109876543210)
     303        v = self.c.query(q).dictresult()[0]['longjohnsilver']
     304        self.assertIsInstance(v, Decimal)
    284305        self.assertEqual(v, result)
    285306
     
    645666
    646667    data = [
    647         (-1, -1, -1L, True, '1492-10-12', '08:30:00',
     668        (-1, -1, long(-1), True, '1492-10-12', '08:30:00',
    648669            -1.2345, -1.75, -1.875, '-1.25', '-', 'r?', '!u', 'xyz'),
    649         (0, 0, 0L, False, '1607-04-14', '09:00:00',
     670        (0, 0, long(0), False, '1607-04-14', '09:00:00',
    650671            0.0, 0.0, 0.0, '0.0', ' ', '0123', '4567', '890'),
    651         (1, 1, 1L, True, '1801-03-04', '03:45:00',
     672        (1, 1, long(1), True, '1801-03-04', '03:45:00',
    652673            1.23456, 1.75, 1.875, '1.25', 'x', 'bc', 'cdef', 'g'),
    653         (2, 2, 2L, False, '1903-12-17', '11:22:00',
     674        (2, 2, long(2), False, '1903-12-17', '11:22:00',
    654675            2.345678, 2.25, 2.125, '2.75', 'y', 'q', 'ijk', 'mnop\nstux!')]
    655676
     
    945966        self.assertNotIsInstance(r, d)
    946967        self.assertIsInstance(r, long)
    947         self.assertEqual(r, 3425L)
     968        self.assertEqual(r, long(3425))
    948969        pg.set_decimal(d)
    949970
  • trunk/module/TEST_PyGreSQL_classic_dbwrapper.py

    r556 r571  
    2020
    2121from decimal import Decimal
     22
     23try:
     24    long
     25except NameError:  # Python >= 3.0
     26    long = int
    2227
    2328# We need a database to test against.  If LOCAL_PyGreSQL.py exists we will
     
    841846            r['d'] = r['t'] = 'x'
    842847            r['b'] = 't'
    843             r['oid'] = 1L
     848            r['oid'] = long(1)
    844849            r = clear(table, r)
    845             result = {'a': 1, 'n': 0, 'b': 'f', 'd': '', 't': '', 'oid': 1L}
     850            result = {'a': 1, 'n': 0, 'b': 'f', 'd': '', 't': '',
     851                'oid': long(1)}
    846852            self.assertEqual(r, result)
    847853            query('drop table "%s"' % table)
  • trunk/module/TEST_PyGreSQL_classic_functions.py

    r569 r571  
    1717except ImportError:
    1818    import unittest
     19
     20try:
     21    long
     22except NameError:  # Python >= 3.0
     23    long = int
    1924
    2025import re
Note: See TracChangeset for help on using the changeset viewer.