Changeset 559


Ignore:
Timestamp:
Nov 20, 2015, 11:09:28 AM (4 years ago)
Author:
cito
Message:

Add test for printing large objects

Again, note that the print function does not work with StringIO.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.x/module/TEST_PyGreSQL_classic_connection.py

    r552 r559  
    1717    import unittest
    1818import sys
     19import tempfile
    1920import threading
    2021import time
     
    2728except ImportError:  # Python < 2.6
    2829    namedtuple = None
    29 
    30 from StringIO import StringIO
    3130
    3231# We need a database to test against.  If LOCAL_PyGreSQL.py exists we will
     
    473472            " union select 2, 'xyz', 'uvw'")
    474473        r = self.c.query(q)
    475         s = StringIO()
    476         stdout, sys.stdout = sys.stdout, s
     474        f = tempfile.TemporaryFile()
     475        stdout, sys.stdout = sys.stdout, f
    477476        try:
    478477            print r
     
    481480        finally:
    482481            sys.stdout = stdout
    483         r = s.getvalue()
    484         s.close()
     482        f.seek(0)
     483        r = f.read()
     484        f.close()
    485485        self.assertEqual(r,
    486486            'a|  h  |world\n'
  • branches/4.x/module/TEST_PyGreSQL_classic_largeobj.py

    r552 r559  
    1616except ImportError:
    1717    import unittest
     18import sys
    1819import tempfile
    1920
     
    366367        self.assertEqual(r, data)
    367368
     369    def testPrint(self):
     370        self.obj.open(pg.INV_WRITE)
     371        data = 'some object to be printed'
     372        self.obj.write(data)
     373        f = tempfile.TemporaryFile()
     374        stdout, sys.stdout = sys.stdout, f
     375        try:
     376            print self.obj
     377            self.obj.close()
     378            print self.obj
     379        except Exception:
     380            pass
     381        finally:
     382            sys.stdout = stdout
     383        f.seek(0)
     384        r = f.read()
     385        f.close()
     386        oid = self.obj.oid
     387        self.assertEqual(r,
     388            'Opened large object, oid %d\n'
     389            'Closed large object, oid %d\n' % (oid, oid))
     390
    368391
    369392if __name__ == '__main__':
  • trunk/module/TEST_PyGreSQL_classic_connection.py

    r558 r559  
    1818except ImportError:
    1919    import unittest
    20 
    2120import sys
     21import tempfile
    2222import threading
    2323import time
    24 import tempfile
    2524
    2625import pg  # the module under test
  • trunk/module/TEST_PyGreSQL_classic_largeobj.py

    r553 r559  
    1616except ImportError:
    1717    import unittest
    18 
     18import sys
    1919import tempfile
    2020
     
    367367        self.assertEqual(r, data)
    368368
     369    def testPrint(self):
     370        self.obj.open(pg.INV_WRITE)
     371        data = 'some object to be printed'
     372        self.obj.write(data)
     373        f = tempfile.TemporaryFile()
     374        stdout, sys.stdout = sys.stdout, f
     375        try:
     376            print(self.obj)
     377            self.obj.close()
     378            print(self.obj)
     379        except Exception:
     380            pass
     381        finally:
     382            sys.stdout = stdout
     383        f.seek(0)
     384        r = f.read()
     385        f.close()
     386        oid = self.obj.oid
     387        self.assertEqual(r,
     388            'Opened large object, oid %d\n'
     389            'Closed large object, oid %d\n' % (oid, oid))
     390
    369391
    370392if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.