summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2003-04-25 14:43:14 (GMT)
committerSkip Montanaro <skip@pobox.com>2003-04-25 14:43:14 (GMT)
commit48816c6f041ea28079ba54ff6bf2ba5124a528a4 (patch)
treebfc3ef550656594cf80f0bfd33fd9efb0999c9c4 /Lib
parent2726fcd4b6d006476a9d7b908fceaac7b935eee4 (diff)
downloadcpython-48816c6f041ea28079ba54ff6bf2ba5124a528a4.zip
cpython-48816c6f041ea28079ba54ff6bf2ba5124a528a4.tar.gz
cpython-48816c6f041ea28079ba54ff6bf2ba5124a528a4.tar.bz2
some sniffer tests
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_csv.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index 3545893..c4d1a03 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -533,6 +533,40 @@ class TestDialectValidity(unittest.TestCase):
self.assertRaises(csv.Error, mydialect)
+class TestSniffer(unittest.TestCase):
+ sample1 = """\
+Harry's, Arlington Heights, IL, 2/1/03, Kimi Hayes
+Shark City, Glendale Heights, IL, 12/28/02, Prezence
+Tommy's Place, Blue Island, IL, 12/28/02, Blue Sunday/White Crow
+Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back
+"""
+ sample2 = """\
+'Harry''s':'Arlington Heights':'IL':'2/1/03':'Kimi Hayes'
+'Shark City':'Glendale Heights':'IL':'12/28/02':'Prezence'
+'Tommy''s Place':'Blue Island':'IL':'12/28/02':'Blue Sunday/White Crow'
+'Stonecutters Seafood and Chop House':'Lemont':'IL':'12/19/02':'Week Back'
+"""
+
+ header = '''\
+"venue","city","state","date","performers"
+'''
+ def test_has_header(self):
+ sniffer = csv.Sniffer()
+ self.assertEqual(sniffer.has_header(self.sample1), False)
+ self.assertEqual(sniffer.has_header(self.header+self.sample1), True)
+
+ def test_sniff(self):
+ sniffer = csv.Sniffer()
+ dialect = sniffer.sniff(self.sample1)
+ self.assertEqual(dialect.delimiter, ",")
+ self.assertEqual(dialect.quotechar, '"')
+ self.assertEqual(dialect.skipinitialspace, True)
+
+ dialect = sniffer.sniff(self.sample2)
+ self.assertEqual(dialect.delimiter, ":")
+ self.assertEqual(dialect.quotechar, "'")
+ self.assertEqual(dialect.skipinitialspace, False)
+
if not hasattr(sys, "gettotalrefcount"):
if verbose: print "*** skipping leakage tests ***"
else: