# HG changeset patch # User Pierre-Yves David # Date 1275930081 -7200 # Node ID 3ea39709b50eaf53e0899b2088f38cc198480382 # Parent bbb89ba88b691518f7f1eec41fe24a3b4b69ffef [rset] Add a line break the first result in repr of multiple rows rset Improve readability of rset while debugging by aligning the first value with the others if the rset have multiple row. This first line was usually not read as it' was on the same line that the first part of the repr (", (%i rows) ...") diff -r bbb89ba88b69 -r 3ea39709b50e rset.py --- a/rset.py Mon Jun 07 18:50:24 2010 +0200 +++ b/rset.py Mon Jun 07 19:01:21 2010 +0200 @@ -76,10 +76,16 @@ rows = self.rows if len(rows) > 10: rows = rows[:10] + ['...'] + if len(rows) > 1: + # add a line break before first entity if more that one. + pattern = '' + else: + pattern = '' + if not self.description: - return '' % (self.rql, len(self.rows), + return pattern % (self.rql, len(self.rows), '\n'.join(str(r) for r in rows)) - return '' % (self.rql, len(self.rows), + return pattern % (self.rql, len(self.rows), '\n'.join('%s (%s)' % (r, d) for r, d in zip(rows, self.description))) diff -r bbb89ba88b69 -r 3ea39709b50e test/unittest_rset.py --- a/test/unittest_rset.py Mon Jun 07 18:50:24 2010 +0200 +++ b/test/unittest_rset.py Mon Jun 07 19:01:21 2010 +0200 @@ -401,5 +401,19 @@ rset = self.execute('Any D, COUNT(U) GROUPBY D WHERE U is CWUser, U creation_date D') self.assertEquals(rset.related_entity(0,0), (None, None)) + def test_str(self): + rset = self.execute('(Any X,N WHERE X is CWGroup, X name N)') + self.assertIsInstance(str(rset), basestring) + self.assertEquals(len(str(rset).splitlines()), 1) + + def test_repr(self): + rset = self.execute('(Any X,N WHERE X is CWGroup, X name N)') + self.assertIsInstance(repr(rset), basestring) + self.assertTrue(len(repr(rset).splitlines()) > 1) + + rset = self.execute('(Any X WHERE X is CWGroup, X name "managers")') + self.assertIsInstance(str(rset), basestring) + self.assertEquals(len(str(rset).splitlines()), 1) + if __name__ == '__main__': unittest_main()