Author: cito
Date: Fri Nov 27 11:03:01 2015
New Revision: 647

Log:
Make tests compatible with Python 2.5

Modified:
   branches/4.x/module/tests/test_classic.py
   branches/4.x/module/tests/test_classic_connection.py
   branches/4.x/module/tests/test_classic_functions.py

Modified: branches/4.x/module/tests/test_classic.py
==============================================================================
--- branches/4.x/module/tests/test_classic.py   Fri Nov 27 10:35:07 2015        
(r646)
+++ branches/4.x/module/tests/test_classic.py   Fri Nov 27 11:03:01 2015        
(r647)
@@ -308,7 +308,7 @@
             self.assertFalse(target.listening)
         finally:
             target.close()
-            if thread.is_alive():
+            if thread.isAlive():
                 thread.join(5)
 
     def test_notify_other_options(self):

Modified: branches/4.x/module/tests/test_classic_connection.py
==============================================================================
--- branches/4.x/module/tests/test_classic_connection.py        Fri Nov 27 
10:35:07 2015        (r646)
+++ branches/4.x/module/tests/test_classic_connection.py        Fri Nov 27 
11:03:01 2015        (r647)
@@ -204,7 +204,7 @@
         thread.start()  # run the query
         while 1:  # make sure the query is really running
             time.sleep(0.1)
-            if thread.is_alive() or time.time() - t1 > 5:
+            if thread.isAlive() or time.time() - t1 > 5:
                 break
         r = self.connection.cancel()  # cancel the running query
         thread.join()  # wait for the thread to end
@@ -1193,6 +1193,7 @@
         self.assertIsInstance(r, str)
         self.assertIs(r, 't')
 
+    @unittest.skipUnless(namedtuple, 'Named tuples not available')
     def testGetNamedresult(self):
         namedresult = pg.get_namedresult()
         # error if a parameter is passed

Modified: branches/4.x/module/tests/test_classic_functions.py
==============================================================================
--- branches/4.x/module/tests/test_classic_functions.py Fri Nov 27 10:35:07 
2015        (r646)
+++ branches/4.x/module/tests/test_classic_functions.py Fri Nov 27 11:03:01 
2015        (r647)
@@ -21,6 +21,11 @@
 
 import pg  # the module under test
 
+try:
+    from collections import namedtuple
+except ImportError:  # Python < 2.6
+    namedtuple = None
+
 
 class TestAuxiliaryFunctions(unittest.TestCase):
     """Test the auxiliary functions external to the connection class."""
@@ -341,14 +346,23 @@
 
     def testGetNamedresult(self):
         r = pg.get_namedresult()
-        self.assertIs(r, pg._namedresult)
+        if namedtuple:
+            self.assertTrue(callable(r))
+            self.assertIs(r, pg._namedresult)
+        else:
+            self.assertIsNone(r)
 
     def testSetNamedresult(self):
         namedresult = pg.get_namedresult()
+        self.assertRaises(TypeError, pg.set_namedresult)
+        self.assertRaises(TypeError, pg.set_namedresult, None)
         f = lambda q: q.getresult()
         pg.set_namedresult(f)
         r = pg.get_namedresult()
-        pg.set_namedresult(namedresult)
+        if namedtuple or namedresult is not None:
+            pg.set_namedresult(namedresult)
+        else:
+            namedresult = f
         self.assertIs(r, f)
         r = pg.get_namedresult()
         self.assertIs(r, namedresult)
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql

Reply via email to