Skip to content

Commit 6984637

Browse files
author
Edgar Y. Walker
committed
Add len to Fetch and add test case for Fetch repr
1 parent 37bbe10 commit 6984637

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

datajoint/fetch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ def __repr__(self):
174174
repr_string += ' '.join(['+' + '-' * (width - 2) + '+' for _ in columns]) + '\n'
175175
for tup in rel.fetch(limit=limit):
176176
repr_string += ' '.join([template % column for column in tup]) + '\n'
177-
if len(self._relation) > limit:
177+
if len(rel) > limit:
178178
repr_string += '...\n'
179-
repr_string += ' (%d tuples)\n' % len(self._relation)
179+
repr_string += ' (%d tuples)\n' % len(rel)
180180
return repr_string
181181

182+
def __len__(self):
183+
return len(self._relation)
182184

183185
class Fetch1:
184186
def __init__(self, relation):

tests/test_fetch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,11 @@ def test_copy(self):
125125
f2 = f.order_by('name')
126126
assert_true(f.behavior['order_by'] is None and len(f2.behavior['order_by']) == 1, 'Object was not copied')
127127

128+
def test_repr(self):
129+
"""Test string representation of fetch, returning table preview"""
130+
repr = self.subject.fetch.__repr__()
131+
n = len(repr.strip().split('\n'))
132+
limit = dj.config['display.limit']
133+
# 3 lines are used for headers (2) and summary statement (1)
134+
assert_true(n - 3 <= limit)
135+

0 commit comments

Comments
 (0)