Changeset 595


Ignore:
Timestamp:
Nov 22, 2015, 7:16:56 AM (4 years ago)
Author:
cito
Message:

Simplify tests for printing objects

Now that we use tp_str instead of tp_print (since Python 3 does not
support tp_print), we can simply check the result of str() instead
of capturing the print out.

Location:
trunk/module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/TEST_PyGreSQL_classic_connection.py

    r588 r595  
    1818except ImportError:
    1919    import unittest
    20 import sys
    21 import tempfile
    2220import threading
    2321import time
     
    495493        query("drop table test_table")
    496494
    497     def testPrint(self):
     495    def testStr(self):
    498496        q = ("select 1 as a, 'hello' as h, 'w' as world"
    499497            " union select 2, 'xyz', 'uvw'")
    500498        r = self.c.query(q)
    501         f = tempfile.TemporaryFile('r+')
    502         stdout, sys.stdout = sys.stdout, f
    503         try:
    504             print(r)
    505         except Exception:
    506             pass
    507         finally:
    508             sys.stdout = stdout
    509         f.seek(0)
    510         r = f.read()
    511         f.close()
    512         self.assertEqual(r,
     499        self.assertEqual(str(r),
    513500            'a|  h  |world\n'
    514501            '-+-----+-----\n'
    515502            '1|hello|w    \n'
    516503            '2|xyz  |uvw  \n'
    517             '(2 rows)\n')
     504            '(2 rows)')
    518505
    519506
  • trunk/module/TEST_PyGreSQL_classic_largeobj.py

    r593 r595  
    1616except ImportError:
    1717    import unittest
    18 import sys
    1918import tempfile
    2019
     
    382381        self.assertEqual(r, data)
    383382
    384     def testPrint(self):
     383    def testStr(self):
    385384        self.obj.open(pg.INV_WRITE)
    386385        data = b'some object to be printed'
    387386        self.obj.write(data)
    388         f = tempfile.TemporaryFile('r+')
    389         stdout, sys.stdout = sys.stdout, f
    390         try:
    391             print(self.obj)
    392             self.obj.close()
    393             print(self.obj)
    394         except Exception:
    395             pass
    396         finally:
    397             sys.stdout = stdout
    398         f.seek(0)
    399         r = f.read()
    400         f.close()
    401387        oid = self.obj.oid
    402         self.assertEqual(r,
    403             'Opened large object, oid %d\n'
    404             'Closed large object, oid %d\n' % (oid, oid))
     388        self.assertEqual(str(self.obj),
     389            'Opened large object, oid %d' % oid)
     390        self.obj.close()
     391        self.assertEqual(str(self.obj),
     392            'Closed large object, oid %d' % oid)
    405393
    406394
Note: See TracChangeset for help on using the changeset viewer.