Author: cito
Date: Sun Nov 22 07:16:56 2015
New Revision: 595
Log:
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.
Modified:
trunk/module/TEST_PyGreSQL_classic_connection.py
trunk/module/TEST_PyGreSQL_classic_largeobj.py
Modified: trunk/module/TEST_PyGreSQL_classic_connection.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_connection.py Sun Nov 22 07:05:24
2015 (r594)
+++ trunk/module/TEST_PyGreSQL_classic_connection.py Sun Nov 22 07:16:56
2015 (r595)
@@ -17,8 +17,6 @@
import unittest2 as unittest # for Python < 2.7
except ImportError:
import unittest
-import sys
-import tempfile
import threading
import time
@@ -494,27 +492,16 @@
self.assertEqual(r, '5')
query("drop table test_table")
- def testPrint(self):
+ def testStr(self):
q = ("select 1 as a, 'hello' as h, 'w' as world"
" union select 2, 'xyz', 'uvw'")
r = self.c.query(q)
- f = tempfile.TemporaryFile('r+')
- stdout, sys.stdout = sys.stdout, f
- try:
- print(r)
- except Exception:
- pass
- finally:
- sys.stdout = stdout
- f.seek(0)
- r = f.read()
- f.close()
- self.assertEqual(r,
+ self.assertEqual(str(r),
'a| h |world\n'
'-+-----+-----\n'
'1|hello|w \n'
'2|xyz |uvw \n'
- '(2 rows)\n')
+ '(2 rows)')
class TestParamQueries(unittest.TestCase):
Modified: trunk/module/TEST_PyGreSQL_classic_largeobj.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_largeobj.py Sun Nov 22 07:05:24
2015 (r594)
+++ trunk/module/TEST_PyGreSQL_classic_largeobj.py Sun Nov 22 07:16:56
2015 (r595)
@@ -15,7 +15,6 @@
import unittest2 as unittest # for Python < 2.7
except ImportError:
import unittest
-import sys
import tempfile
import pg # the module under test
@@ -381,27 +380,16 @@
self.assertIsInstance(r, bytes)
self.assertEqual(r, data)
- def testPrint(self):
+ def testStr(self):
self.obj.open(pg.INV_WRITE)
data = b'some object to be printed'
self.obj.write(data)
- f = tempfile.TemporaryFile('r+')
- stdout, sys.stdout = sys.stdout, f
- try:
- print(self.obj)
- self.obj.close()
- print(self.obj)
- except Exception:
- pass
- finally:
- sys.stdout = stdout
- f.seek(0)
- r = f.read()
- f.close()
oid = self.obj.oid
- self.assertEqual(r,
- 'Opened large object, oid %d\n'
- 'Closed large object, oid %d\n' % (oid, oid))
+ self.assertEqual(str(self.obj),
+ 'Opened large object, oid %d' % oid)
+ self.obj.close()
+ self.assertEqual(str(self.obj),
+ 'Closed large object, oid %d' % oid)
if __name__ == '__main__':
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql