mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Extensively testing
This commit is contained in:
+9
-3
@@ -15,7 +15,6 @@ import simplejson as json
|
||||
import xlwt
|
||||
import yaml
|
||||
|
||||
import showme
|
||||
from helpers import *
|
||||
|
||||
|
||||
@@ -141,7 +140,14 @@ class Dataset(object):
|
||||
def headers(self, collection):
|
||||
"""Validating headers setter."""
|
||||
self._validate(collection)
|
||||
self.__headers = collection
|
||||
if collection:
|
||||
try:
|
||||
self.__headers = list(collection)
|
||||
except TypeError, why:
|
||||
raise TypeError
|
||||
else:
|
||||
self.__headers = None
|
||||
|
||||
|
||||
|
||||
@property
|
||||
@@ -188,7 +194,7 @@ class Dataset(object):
|
||||
wb.save(stream)
|
||||
return stream.getvalue()
|
||||
|
||||
# @showme.trace
|
||||
|
||||
def append(self, row=None, col=None):
|
||||
"""Adds a row to the end of Dataset"""
|
||||
if row:
|
||||
|
||||
+55
-8
@@ -7,15 +7,14 @@ import tablib
|
||||
|
||||
class TablibTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
global data
|
||||
data = tablib.Dataset()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_empty_append(self):
|
||||
|
||||
data = tablib.Dataset()
|
||||
|
||||
new_row = (1,2,3)
|
||||
data.append(new_row)
|
||||
|
||||
@@ -24,17 +23,65 @@ class TablibTestCase(unittest.TestCase):
|
||||
|
||||
def test_empty_append_with_headers(self):
|
||||
|
||||
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_adding_header with (self):
|
||||
|
||||
|
||||
|
||||
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))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user