mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Added simple test for slicing by headers
This commit is contained in:
@@ -26,7 +26,9 @@ class TablibTestCase(unittest.TestCase):
|
||||
new_row = (1, 2, 3)
|
||||
data.append(new_row)
|
||||
|
||||
# Verify width/data
|
||||
self.assertTrue(data.width == len(new_row))
|
||||
self.assertTrue(data[0] == new_row)
|
||||
|
||||
def test_empty_append_with_headers(self):
|
||||
"""Verify append() correctly detects mismatch of number of
|
||||
@@ -39,6 +41,23 @@ class TablibTestCase(unittest.TestCase):
|
||||
|
||||
self.assertRaises(tablib.InvalidDimensions, data.append, new_row)
|
||||
|
||||
def test_header_slicing(self):
|
||||
"""Verify slicing by headers"""
|
||||
|
||||
headers = ('first_name', 'last_name', 'gpa')
|
||||
|
||||
data = [
|
||||
('John', 'Adams', 90),
|
||||
('George', 'Washington', 67)
|
||||
]
|
||||
|
||||
data = tablib.Dataset(*data, headers=headers)
|
||||
|
||||
# Slice by headers
|
||||
self.assertEqual(data['first_name'], ['John', 'George'])
|
||||
self.assertEqual(data['last_name'], ['Adams', 'Washington'])
|
||||
self.assertEqual(data['gpa'], [90, 67])
|
||||
|
||||
# def test_adding_header with (self):
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user