Author: cito
Date: Sun Nov 22 07:38:27 2015
New Revision: 596
Log:
Use the default repr method for all objects
Our custom repr methods were not any better.
Modified:
trunk/module/TEST_PyGreSQL_classic_connection.py
trunk/module/TEST_PyGreSQL_classic_largeobj.py
trunk/module/pgmodule.c
Modified: trunk/module/TEST_PyGreSQL_classic_connection.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_connection.py Sun Nov 22 07:16:56
2015 (r595)
+++ trunk/module/TEST_PyGreSQL_classic_connection.py Sun Nov 22 07:38:27
2015 (r596)
@@ -243,6 +243,21 @@
def tearDown(self):
self.c.close()
+ def testStr(self):
+ q = ("select 1 as a, 'hello' as h, 'w' as world"
+ " union select 2, 'xyz', 'uvw'")
+ r = self.c.query(q)
+ self.assertEqual(str(r),
+ 'a| h |world\n'
+ '-+-----+-----\n'
+ '1|hello|w \n'
+ '2|xyz |uvw \n'
+ '(2 rows)')
+
+ def testRepr(self):
+ r = repr(self.c.query("select 1"))
+ self.assertTrue(r.startswith('<pgqueryobject object'), r)
+
def testSelect0(self):
q = "select 0"
self.c.query(q)
@@ -492,17 +507,6 @@
self.assertEqual(r, '5')
query("drop table test_table")
- def testStr(self):
- q = ("select 1 as a, 'hello' as h, 'w' as world"
- " union select 2, 'xyz', 'uvw'")
- r = self.c.query(q)
- self.assertEqual(str(r),
- 'a| h |world\n'
- '-+-----+-----\n'
- '1|hello|w \n'
- '2|xyz |uvw \n'
- '(2 rows)')
-
class TestParamQueries(unittest.TestCase):
""""Test queries with parameters via a basic pg connection."""
Modified: trunk/module/TEST_PyGreSQL_classic_largeobj.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_largeobj.py Sun Nov 22 07:16:56
2015 (r595)
+++ trunk/module/TEST_PyGreSQL_classic_largeobj.py Sun Nov 22 07:38:27
2015 (r596)
@@ -175,6 +175,21 @@
self.assertIsInstance(self.obj.error, str)
self.assertEqual(self.obj.error, '')
+ def testStr(self):
+ self.obj.open(pg.INV_WRITE)
+ data = b'some object to be printed'
+ self.obj.write(data)
+ oid = self.obj.oid
+ r = str(self.obj)
+ self.assertEqual(r, 'Opened large object, oid %d' % oid)
+ self.obj.close()
+ r = str(self.obj)
+ self.assertEqual(r, 'Closed large object, oid %d' % oid)
+
+ def testRepr(self):
+ r = repr(self.obj)
+ self.assertTrue(r.startswith('<pglarge object'), r)
+
def testOpen(self):
open = self.obj.open
# testing with invalid parameters
@@ -380,17 +395,6 @@
self.assertIsInstance(r, bytes)
self.assertEqual(r, data)
- def testStr(self):
- self.obj.open(pg.INV_WRITE)
- data = b'some object to be printed'
- self.obj.write(data)
- oid = self.obj.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__':
unittest.main()
Modified: trunk/module/pgmodule.c
==============================================================================
--- trunk/module/pgmodule.c Sun Nov 22 07:16:56 2015 (r595)
+++ trunk/module/pgmodule.c Sun Nov 22 07:38:27 2015 (r596)
@@ -964,7 +964,7 @@
return PyObject_GenericGetAttr((PyObject *) self, nameobj);
}
-/* output large object as string */
+/* return large object as string in human readable form */
static PyObject *
largeStr(largeObject *self)
{
@@ -1403,13 +1403,7 @@
}
#endif /* DIRECT_ACCESS */
-static PyObject *
-queryRepr(queryObject *self)
-{
- return PyStr_FromString("<pg query result>");
-}
-
-/* output query as string */
+/* return query as string in human readable form */
static PyObject *
queryStr(queryObject *self)
{
@@ -2931,14 +2925,7 @@
return -1;
}
-static PyObject *
-sourceRepr(sourceObject *self)
-{
- return PyStr_FromString("<pg source object>");
-}
-
-/* returns source object as string in human readable format */
-
+/* return source object as string in human readable form */
static PyObject *
sourceStr(sourceObject *self)
{
@@ -2969,7 +2956,7 @@
0, /*
tp_getattr */
(setattrfunc) sourceSetAttr, /* tp_setattr */
0, /*
tp_compare */
- (reprfunc) sourceRepr, /* tp_repr */
+ 0, /*
tp_repr */
0, /*
tp_as_number */
0, /*
tp_as_sequence */
0, /*
tp_as_mapping */
@@ -3593,7 +3580,7 @@
return PyObject_GenericGetAttr((PyObject *) self, nameobj);
}
-/* output notice as string */
+/* return notice as string in human readable form */
static PyObject *
noticeStr(noticeObject *self)
{
@@ -3682,7 +3669,7 @@
0, /*
tp_getattr */
0, /*
tp_setattr */
0, /*
tp_compare */
- (reprfunc) queryRepr, /* tp_repr */
+ 0, /*
tp_repr */
0, /*
tp_as_number */
0, /*
tp_as_sequence */
0, /*
tp_as_mapping */
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql