Skip to content

Commit

Permalink
Add str and repr for afw Record
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Aug 2, 2017
1 parent 7296eb9 commit 5c8238e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/lsst/afw/table/base/baseContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ def extract(self, *patterns, **kwds):
d[name] = self.get(schemaItem.key)
return d

def __str__(self):
return '\n'.join("%s: %s"%(x.field.getName(), self.extract("*")[x.field.getName()])
for x in self.schema)

def __repr__(self):
return "%s\n%s" % (type(self), str(self))


class Catalog(with_metaclass(TemplateMeta, object)):

Expand Down
13 changes: 13 additions & 0 deletions tests/test_sourceTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,19 @@ def testStrNonContiguous(self):
for field in ('id', 'coord_ra', 'coord_dec'):
self.assertIn(field, string)

def testRecordStr(self):
"""Test that str(record) contains expected things."""
string = str(self.catalog[0])
for field in ('id: 50', 'coord_ra: nan', 'coord_dec: nan'):
self.assertIn(field, string)

def testRecordRepr(self):
"""Test that repr(record) contains expected things."""
string = repr(self.catalog[0])
self.assertIn(str(type(self.catalog[0])), string)
for field in ('id: 50', 'coord_ra: nan', 'coord_dec: nan'):
self.assertIn(field, string)


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass
Expand Down

0 comments on commit 5c8238e

Please sign in to comment.