From 187d12cffc5cb3b46f0ce6333cf0f5f407d3a949 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 25 Sep 2010 18:09:44 -0400 Subject: [PATCH] Format Auto-detection in place. Test suite updated. --- tablib/__init__.py | 2 +- test_tablib.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tablib/__init__.py b/tablib/__init__.py index fadd8dd..e9bdf69 100644 --- a/tablib/__init__.py +++ b/tablib/__init__.py @@ -2,7 +2,7 @@ """ from tablib.core import ( - Databook, Dataset, InvalidDatasetType, + Databook, Dataset, detect, InvalidDatasetType, InvalidDimensions, UnsupportedFormat ) diff --git a/test_tablib.py b/test_tablib.py index 3f8ee37..4843117 100755 --- a/test_tablib.py +++ b/test_tablib.py @@ -307,6 +307,21 @@ class TablibTestCase(unittest.TestCase): self.assertFalse(tablib.formats.yaml.detect(_bunk)) + def test_auto_format_detect(self): + """Test auto format detection.""" + + _yaml = '- {age: 90, first_name: John, last_name: Adams}' + _json = '[{"last_name": "Adams","age": 90,"first_name": "John"}]' + _csv = '1,2,3\n4,5,6\n7,8,9\n' + _bunk = '¡¡¡¡¡¡---///\n\n\n¡¡£™∞¢£§∞§¶•¶ª∞¶•ªº••ª–º§•†•§º¶•†¥ª–º•§ƒø¥¨©πƒø†ˆ¥ç©¨√øˆ¥≈†ƒ¥ç©ø¨çˆ¥ƒçø¶' + + self.assertEqual(tablib.detect(_yaml)[0], tablib.formats.yaml) + self.assertEqual(tablib.detect(_csv)[0], tablib.formats.csv) + self.assertEqual(tablib.detect(_json)[0], tablib.formats.json) + self.assertEqual(tablib.detect(_bunk)[0], None) + + + def test_wipe(self): """Purge a dataset."""