Merge branch 'joshmerge' into develop

This commit is contained in:
Kenneth Reitz
2010-10-01 17:56:31 -04:00
2 changed files with 18 additions and 2 deletions
+11 -2
View File
@@ -173,10 +173,19 @@ class Dataset(object):
def append(self, row=None, col=None):
"""Adds a row to the end of Dataset"""
if row:
if row is not None:
self._validate(row)
self._data.append(tuple(row))
elif col:
elif col is not None:
col = list(col)
if self.headers:
header = [col.pop(0)]
else:
header = []
if len(col) == 1 and callable(col[0]):
col = map(col[0], self._data)
col = tuple(header + col)
self._validate(col=col)
if self.headers:
+7
View File
@@ -102,6 +102,13 @@ class TablibTestCase(unittest.TestCase):
self.assertRaises(tablib.InvalidDimensions, data.append, col=new_col)
def test_add_callable_column(self):
"""Verify adding column with values specified as callable."""
new_col = ['first_again', lambda x: x[0]]
self.founders.append(col=new_col)
self.assertTrue(map(lambda x: x[0] == x[-1], self.founders))
def test_header_slicing(self):
"""Verify slicing by headers."""