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 Jul 6, 2017
1 parent 0e7662f commit e268fb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 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,14 @@ def extract(self, *patterns, **kwds):
d[name] = self.get(schemaItem.key)
return d

def __str__(self):
# import os; print(os.getpid()); import ipdb; ipdb.set_trace()
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 e268fb2

Please sign in to comment.