summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2022-08-29 00:43:32 (GMT)
committerGitHub <noreply@github.com>2022-08-29 00:43:32 (GMT)
commit1c01bd28a0ec7e46e570a07d970c590b1809f8f1 (patch)
treee122ba679acad21a3cc56d033d295edb188fa92b
parent3d3a86ed40626471b2c9e7f1336b228eb0dd0879 (diff)
downloadcpython-1c01bd28a0ec7e46e570a07d970c590b1809f8f1.zip
cpython-1c01bd28a0ec7e46e570a07d970c590b1809f8f1.tar.gz
cpython-1c01bd28a0ec7e46e570a07d970c590b1809f8f1.tar.bz2
gh-95950: Add a test for both `csv.Dialect` and `kwargs` (#95951)
-rw-r--r--Lib/test/test_csv.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index 51ca1f2..a2b0043 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -448,6 +448,34 @@ class TestDialectRegistry(unittest.TestCase):
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"