mirror of
https://github.com/python/cpython
synced 2024-09-04 15:56:13 +00:00
gh-95950: Add a test for both csv.Dialect
and kwargs
(#95951)
This commit is contained in:
parent
3d3a86ed40
commit
1c01bd28a0
|
@ -448,6 +448,34 @@ def test_register_kwargs(self):
|
|||
self.assertEqual(csv.get_dialect(name).delimiter, ';')
|
||||
self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))
|
||||
|
||||
def test_register_kwargs_override(self):
|
||||
class mydialect(csv.Dialect):
|
||||
delimiter = "\t"
|
||||
quotechar = '"'
|
||||
doublequote = True
|
||||
skipinitialspace = False
|
||||
lineterminator = '\r\n'
|
||||
quoting = csv.QUOTE_MINIMAL
|
||||
|
||||
name = 'test_dialect'
|
||||
csv.register_dialect(name, mydialect,
|
||||
delimiter=';',
|
||||
quotechar="'",
|
||||
doublequote=False,
|
||||
skipinitialspace=True,
|
||||
lineterminator='\n',
|
||||
quoting=csv.QUOTE_ALL)
|
||||
self.addCleanup(csv.unregister_dialect, name)
|
||||
|
||||
# Ensure that kwargs do override attributes of a dialect class:
|
||||
dialect = csv.get_dialect(name)
|
||||
self.assertEqual(dialect.delimiter, ';')
|
||||
self.assertEqual(dialect.quotechar, "'")
|
||||
self.assertEqual(dialect.doublequote, False)
|
||||
self.assertEqual(dialect.skipinitialspace, True)
|
||||
self.assertEqual(dialect.lineterminator, '\n')
|
||||
self.assertEqual(dialect.quoting, csv.QUOTE_ALL)
|
||||
|
||||
def test_incomplete_dialect(self):
|
||||
class myexceltsv(csv.Dialect):
|
||||
delimiter = "\t"
|
||||
|
|
Loading…
Reference in a new issue