Author: cito
Date: Sat Nov 21 09:19:33 2015
New Revision: 571

Log:
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.

Modified:
   trunk/module/TEST_PyGreSQL_classic_connection.py
   trunk/module/TEST_PyGreSQL_classic_dbwrapper.py
   trunk/module/TEST_PyGreSQL_classic_functions.py

Modified: trunk/module/TEST_PyGreSQL_classic_connection.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_connection.py    Sat Nov 21 09:16:44 
2015        (r570)
+++ trunk/module/TEST_PyGreSQL_classic_connection.py    Sat Nov 21 09:19:33 
2015        (r571)
@@ -26,6 +26,11 @@
 
 from decimal import Decimal
 
+try:
+    long
+except NameError:  # Python >= 3.0
+    long = int
+
 # We need a database to test against.  If LOCAL_PyGreSQL.py exists we will
 # get our information from that.  Otherwise we use the defaults.
 dbname = 'unittest'
@@ -253,12 +258,20 @@
         self.assertEqual(r, result)
 
     def testGetresultLong(self):
-        q = "select 1234567890123456790"
-        result = 1234567890123456790L
+        q = "select 9876543210"
+        result = long(9876543210)
+        self.assertIsInstance(result, long)
         v = self.c.query(q).getresult()[0][0]
         self.assertIsInstance(v, long)
         self.assertEqual(v, result)
 
+    def testGetresultDecimal(self):
+        q = "select 98765432109876543210"
+        result = Decimal(98765432109876543210)
+        v = self.c.query(q).getresult()[0][0]
+        self.assertIsInstance(v, Decimal)
+        self.assertEqual(v, result)
+
     def testGetresultString(self):
         result = 'Hello, world!'
         q = "select '%s'" % result
@@ -277,12 +290,20 @@
         self.assertEqual(r, result)
 
     def testDictresultLong(self):
-        q = "select 1234567890123456790 as longjohnsilver"
-        result = 1234567890123456790L
+        q = "select 9876543210 as longjohnsilver"
+        result = long(9876543210)
+        self.assertIsInstance(result, long)
         v = self.c.query(q).dictresult()[0]['longjohnsilver']
         self.assertIsInstance(v, long)
         self.assertEqual(v, result)
 
+    def testDictresultDecimal(self):
+        q = "select 98765432109876543210 as longjohnsilver"
+        result = Decimal(98765432109876543210)
+        v = self.c.query(q).dictresult()[0]['longjohnsilver']
+        self.assertIsInstance(v, Decimal)
+        self.assertEqual(v, result)
+
     def testDictresultString(self):
         result = 'Hello, world!'
         q = "select '%s' as greeting" % result
@@ -644,13 +665,13 @@
         self.c.close()
 
     data = [
-        (-1, -1, -1L, True, '1492-10-12', '08:30:00',
+        (-1, -1, long(-1), True, '1492-10-12', '08:30:00',
             -1.2345, -1.75, -1.875, '-1.25', '-', 'r?', '!u', 'xyz'),
-        (0, 0, 0L, False, '1607-04-14', '09:00:00',
+        (0, 0, long(0), False, '1607-04-14', '09:00:00',
             0.0, 0.0, 0.0, '0.0', ' ', '0123', '4567', '890'),
-        (1, 1, 1L, True, '1801-03-04', '03:45:00',
+        (1, 1, long(1), True, '1801-03-04', '03:45:00',
             1.23456, 1.75, 1.875, '1.25', 'x', 'bc', 'cdef', 'g'),
-        (2, 2, 2L, False, '1903-12-17', '11:22:00',
+        (2, 2, long(2), False, '1903-12-17', '11:22:00',
             2.345678, 2.25, 2.125, '2.75', 'y', 'q', 'ijk', 'mnop\nstux!')]
 
     def get_back(self):
@@ -944,7 +965,7 @@
         r = query("select 3425::numeric").getresult()[0][0]
         self.assertNotIsInstance(r, d)
         self.assertIsInstance(r, long)
-        self.assertEqual(r, 3425L)
+        self.assertEqual(r, long(3425))
         pg.set_decimal(d)
 
     def testSetNamedresult(self):

Modified: trunk/module/TEST_PyGreSQL_classic_dbwrapper.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_dbwrapper.py     Sat Nov 21 09:16:44 
2015        (r570)
+++ trunk/module/TEST_PyGreSQL_classic_dbwrapper.py     Sat Nov 21 09:19:33 
2015        (r571)
@@ -20,6 +20,11 @@
 
 from decimal import Decimal
 
+try:
+    long
+except NameError:  # Python >= 3.0
+    long = int
+
 # We need a database to test against.  If LOCAL_PyGreSQL.py exists we will
 # get our information from that.  Otherwise we use the defaults.
 # The current user must have create schema privilege on the database.
@@ -840,9 +845,10 @@
             r['a'] = r['n'] = 1
             r['d'] = r['t'] = 'x'
             r['b'] = 't'
-            r['oid'] = 1L
+            r['oid'] = long(1)
             r = clear(table, r)
-            result = {'a': 1, 'n': 0, 'b': 'f', 'd': '', 't': '', 'oid': 1L}
+            result = {'a': 1, 'n': 0, 'b': 'f', 'd': '', 't': '',
+                'oid': long(1)}
             self.assertEqual(r, result)
             query('drop table "%s"' % table)
 

Modified: trunk/module/TEST_PyGreSQL_classic_functions.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_functions.py     Sat Nov 21 09:16:44 
2015        (r570)
+++ trunk/module/TEST_PyGreSQL_classic_functions.py     Sat Nov 21 09:19:33 
2015        (r571)
@@ -17,6 +17,11 @@
 except ImportError:
     import unittest
 
+try:
+    long
+except NameError:  # Python >= 3.0
+    long = int
+
 import re
 
 import pg  # the module under test
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql

Reply via email to