diff --git a/HISTORY.rst b/HISTORY.rst index 537f471..5d2ba1e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,10 +1,16 @@ History ======= +0.6.2 (2010-09-13) +------------------ +* Fixed Dataset.append() error on empty dataset. +* Updated Dataset.headers property w/ validation. +* Added Testing Fixtures. + 0.6.1 (2010-09-12) ------------------ -* Packaging hotfixes +* Packaging hotfixes. 0.6.0 (2010-09-11) diff --git a/README.rst b/README.rst index fed8f77..3e9e09f 100644 --- a/README.rst +++ b/README.rst @@ -127,6 +127,7 @@ If you'd like to contribute, simply fork `the repository`_, commit your changes, Roadmap ------- +- Add ability to add/remove full columns - Import datasets from CSV, JSON, YAML - Release CLI Interface - Auto-detect import format diff --git a/setup.py b/setup.py index 72fefee..5670078 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ if sys.argv[-1] == "publish": setup( name='tablib', - version='0.6.1', + version='0.6.2', description='Format agnostic tabular data library (XLS, JSON, YAML, CSV)', long_description=open('README.rst').read() + '\n\n' + open('HISTORY.rst').read(), diff --git a/tablib/core.py b/tablib/core.py index 91dcac4..c387031 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -18,7 +18,7 @@ import yaml from helpers import * -__all__ = ['Dataset', 'DataBook'] +# __all__ = ['Dataset', 'DataBook'] __name__ = 'tablib' __version__ = '0.6.1' @@ -36,6 +36,7 @@ class Dataset(object): self._saved_file = None self._saved_format = None self._data = list(args) + self.__headers = None try: self.headers = kwargs['headers'] @@ -118,9 +119,23 @@ class Dataset(object): """Returns the width of the Dataset.""" try: return len(self._data[0]) - except KeyError, why: - return 0 + except IndexError, why: + try: + return len(self.headers) + except TypeError, e: + return 0 + + @property + def headers(self): + """Headers property.""" + return self.__headers + @headers.setter + def headers(self, collection): + """Validating headers setter.""" + self._validate(collection) + self.__headers = collection + @property def dict(self): """Returns python dict of Dataset.""" diff --git a/test_tablib.py b/test_tablib.py new file mode 100644 index 0000000..cea6d24 --- /dev/null +++ b/test_tablib.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import unittest + +import tablib + +class TablibTestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + def test_empty_append(self): + + data = tablib.Dataset() + + new_row = (1,2,3) + data.append(new_row) + + self.assertTrue(data.width == len(new_row)) + + + 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_adding_header with (self): + + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file