mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Attempt at merging upstream develop branch
- Kept the slicing tests in tact by leaving their setup info. in the main setup - Moved around some of the test methods to organize them a bit by functionality
This commit is contained in:
+57
-8
@@ -13,6 +13,9 @@ class TablibTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Create simple data set with headers"""
|
||||
global data
|
||||
data = tablib.Dataset()
|
||||
|
||||
headers = ('first_name', 'last_name', 'gpa')
|
||||
self.john = ('John', 'Adams', 90)
|
||||
self.george = ('George', 'Washington', 67)
|
||||
@@ -29,9 +32,7 @@ class TablibTestCase(unittest.TestCase):
|
||||
|
||||
def test_empty_append(self):
|
||||
"""Verify append() correctly adds tuple with no headers"""
|
||||
data = tablib.Dataset()
|
||||
|
||||
new_row = (1, 2, 3)
|
||||
new_row = (1,2,3)
|
||||
data.append(new_row)
|
||||
|
||||
# Verify width/data
|
||||
@@ -42,13 +43,63 @@ class TablibTestCase(unittest.TestCase):
|
||||
"""Verify append() correctly detects mismatch of number of
|
||||
headers and data
|
||||
"""
|
||||
data = tablib.Dataset()
|
||||
|
||||
data.headers = ['first', 'second']
|
||||
new_row = (1, 2, 3, 4)
|
||||
|
||||
self.assertRaises(tablib.InvalidDimensions, data.append, new_row)
|
||||
|
||||
|
||||
def test_add_column(self):
|
||||
# No Headers
|
||||
|
||||
data.append(['kenneth'])
|
||||
data.append(['bessie'])
|
||||
|
||||
new_col = ['reitz', 'monke']
|
||||
|
||||
data.append(col=new_col)
|
||||
|
||||
self.assertEquals(data[0], ('kenneth', 'reitz'))
|
||||
self.assertEquals(data.width, 2)
|
||||
|
||||
# With Headers
|
||||
data.headers = ('fname', 'lname')
|
||||
new_col = ['age', 21, 22]
|
||||
data.append(col=new_col)
|
||||
|
||||
self.assertEquals(data[new_col[0]], new_col[1:])
|
||||
|
||||
def test_add_column_no_data_no_headers(self):
|
||||
|
||||
# no headers
|
||||
|
||||
new_col = ('reitz', 'monke')
|
||||
|
||||
data.append(col=new_col)
|
||||
|
||||
self.assertEquals(data[0], tuple([new_col[0]]))
|
||||
self.assertEquals(data.width, 1)
|
||||
self.assertEquals(data.height, len(new_col))
|
||||
|
||||
def test_add_column_no_data_with_headers(self):
|
||||
|
||||
# no headers
|
||||
|
||||
data.headers = ('first', 'last')
|
||||
|
||||
new_col = ('age',)
|
||||
data.append(col=new_col)
|
||||
|
||||
self.assertEquals(len(data.headers), 3)
|
||||
self.assertEquals(data.width, 3)
|
||||
|
||||
new_col = ('foo', 'bar')
|
||||
|
||||
self.assertRaises(tablib.InvalidDimensions, data.append, col=new_col)
|
||||
|
||||
def tuple_check(self):
|
||||
data.append(col=(1,2,3))
|
||||
|
||||
def test_header_slicing(self):
|
||||
"""Verify slicing by headers"""
|
||||
|
||||
@@ -75,8 +126,6 @@ class TablibTestCase(unittest.TestCase):
|
||||
self.assertEqual(self.founders[1:3], [self.george, self.tom])
|
||||
self.assertEqual(self.founders[2:], [self.tom])
|
||||
|
||||
# def test_adding_header with (self):
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user