Changeset 647 for branches/4.x


Ignore:
Timestamp:
Nov 27, 2015, 11:03:01 AM (4 years ago)
Author:
cito
Message:

Make tests compatible with Python 2.5

Location:
branches/4.x/module/tests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.x/module/tests/test_classic.py

    r640 r647  
    309309        finally:
    310310            target.close()
    311             if thread.is_alive():
     311            if thread.isAlive():
    312312                thread.join(5)
    313313
  • branches/4.x/module/tests/test_classic_connection.py

    r644 r647  
    205205        while 1:  # make sure the query is really running
    206206            time.sleep(0.1)
    207             if thread.is_alive() or time.time() - t1 > 5:
     207            if thread.isAlive() or time.time() - t1 > 5:
    208208                break
    209209        r = self.connection.cancel()  # cancel the running query
     
    11941194        self.assertIs(r, 't')
    11951195
     1196    @unittest.skipUnless(namedtuple, 'Named tuples not available')
    11961197    def testGetNamedresult(self):
    11971198        namedresult = pg.get_namedresult()
  • branches/4.x/module/tests/test_classic_functions.py

    r646 r647  
    2121
    2222import pg  # the module under test
     23
     24try:
     25    from collections import namedtuple
     26except ImportError:  # Python < 2.6
     27    namedtuple = None
    2328
    2429
     
    342347    def testGetNamedresult(self):
    343348        r = pg.get_namedresult()
    344         self.assertIs(r, pg._namedresult)
     349        if namedtuple:
     350            self.assertTrue(callable(r))
     351            self.assertIs(r, pg._namedresult)
     352        else:
     353            self.assertIsNone(r)
    345354
    346355    def testSetNamedresult(self):
    347356        namedresult = pg.get_namedresult()
     357        self.assertRaises(TypeError, pg.set_namedresult)
     358        self.assertRaises(TypeError, pg.set_namedresult, None)
    348359        f = lambda q: q.getresult()
    349360        pg.set_namedresult(f)
    350361        r = pg.get_namedresult()
    351         pg.set_namedresult(namedresult)
     362        if namedtuple or namedresult is not None:
     363            pg.set_namedresult(namedresult)
     364        else:
     365            namedresult = f
    352366        self.assertIs(r, f)
    353367        r = pg.get_namedresult()
Note: See TracChangeset for help on using the changeset viewer.