Fix wrong test code in test_csv (#10602)

This commit is contained in:
Éric Araujo 2010-12-02 22:16:19 +00:00
parent 98338227a7
commit 5137d648cd
1 changed files with 7 additions and 12 deletions

View File

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