summaryrefslogtreecommitdiff
path: root/test_tablib.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_tablib.py')
-rwxr-xr-xtest_tablib.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/test_tablib.py b/test_tablib.py
index 67b693d..ebad061 100755
--- a/test_tablib.py
+++ b/test_tablib.py
@@ -102,6 +102,13 @@ class TablibTestCase(unittest.TestCase):
self.assertRaises(tablib.InvalidDimensions, data.append, col=new_col)
+ def test_add_callable_column(self):
+ """Verify adding column with values specified as callable."""
+ new_col = ['first_again', lambda x: x[0]]
+ self.founders.append(col=new_col)
+
+ self.assertTrue(map(lambda x: x[0] == x[-1], self.founders))
+
def test_header_slicing(self):
"""Verify slicing by headers."""
@@ -261,6 +268,58 @@ class TablibTestCase(unittest.TestCase):
self.assertEqual(_csv, data.csv)
+ def test_csv_format_detect(self):
+ """Test CSV format detection."""
+
+ _csv = (
+ '1,2,3\n'
+ '4,5,6\n'
+ '7,8,9\n'
+ )
+ _bunk = (
+ '¡¡¡¡¡¡¡¡£™∞¢£§∞§¶•¶ª∞¶•ªº••ª–º§•†•§º¶•†¥ª–º•§ƒø¥¨©πƒø†ˆ¥ç©¨√øˆ¥≈†ƒ¥ç©ø¨çˆ¥ƒçø¶'
+ )
+
+ self.assertTrue(tablib.formats.csv.detect(_csv))
+ self.assertFalse(tablib.formats.csv.detect(_bunk))
+
+ def test_json_format_detect(self):
+ """Test JSON format detection."""
+
+ _json = '[{"last_name": "Adams","age": 90,"first_name": "John"}]'
+ _bunk = (
+ '¡¡¡¡¡¡¡¡£™∞¢£§∞§¶•¶ª∞¶•ªº••ª–º§•†•§º¶•†¥ª–º•§ƒø¥¨©πƒø†ˆ¥ç©¨√øˆ¥≈†ƒ¥ç©ø¨çˆ¥ƒçø¶'
+ )
+
+ self.assertTrue(tablib.formats.json.detect(_json))
+ self.assertFalse(tablib.formats.json.detect(_bunk))
+
+
+ def test_yaml_format_detect(self):
+ """Test YAML format detection."""
+
+ _yaml = '- {age: 90, first_name: John, last_name: Adams}'
+ _bunk = (
+ '¡¡¡¡¡¡---///\n\n\n¡¡£™∞¢£§∞§¶•¶ª∞¶•ªº••ª–º§•†•§º¶•†¥ª–º•§ƒø¥¨©πƒø†ˆ¥ç©¨√øˆ¥≈†ƒ¥ç©ø¨çˆ¥ƒçø¶'
+ )
+
+ self.assertTrue(tablib.formats.yaml.detect(_yaml))
+ 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."""