Allow dialect-describing keywords to be supplied to register_dialect,

record objects of internal dialect type, rather than instances of
python objects.
This commit is contained in:
Andrew McNamara 2005-01-11 01:28:33 +00:00
parent 91b97463cd
commit 86625972a1
2 changed files with 21 additions and 28 deletions

View file

@ -272,13 +272,22 @@ class TestDialectRegistry(unittest.TestCase):
expected_dialects.sort()
csv.register_dialect(name, myexceltsv)
try:
self.failUnless(isinstance(csv.get_dialect(name), myexceltsv))
self.failUnless(csv.get_dialect(name).delimiter, '\t')
got_dialects = csv.list_dialects()
got_dialects.sort()
self.assertEqual(expected_dialects, got_dialects)
finally:
csv.unregister_dialect(name)
def test_register_kwargs(self):
name = 'fedcba'
csv.register_dialect(name, delimiter=';')
try:
self.failUnless(csv.get_dialect(name).delimiter, '\t')
self.failUnless(list(csv.reader('X;Y;Z', name)), ['X', 'Y', 'Z'])
finally:
csv.unregister_dialect(name)
def test_incomplete_dialect(self):
class myexceltsv(csv.Dialect):
delimiter = "\t"