Skip to content

Add a test for csv.register_dialect with both Dialect and kwargs #95950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sobolevn opened this issue Aug 13, 2022 · 1 comment
Closed

Add a test for csv.register_dialect with both Dialect and kwargs #95950

sobolevn opened this issue Aug 13, 2022 · 1 comment
Assignees
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes tests Tests in the Lib/test dir

Comments

@sobolevn
Copy link
Member

Feature or enhancement

Python docs state:

csv.register_dialect(name[, dialect[, **fmtparams]])

    Associate dialect with name. name must be a string. The dialect can be specified either by passing a sub-class of [Dialect](https://docs.python.org/3/library/csv.html#csv.Dialect), or by fmtparams keyword arguments, or both, with keyword arguments overriding parameters of the dialect. For full details about dialects and formatting parameters, see section [Dialects and Formatting Parameters](https://docs.python.org/3/library/csv.html#csv-fmt-params).

Notice this part:

or both, with keyword arguments overriding parameters of the dialect

But, this is not ever tested in test_csv.
Link:

def test_registry(self):
class myexceltsv(csv.excel):
delimiter = "\t"
name = "myexceltsv"
expected_dialects = csv.list_dialects() + [name]
expected_dialects.sort()
csv.register_dialect(name, myexceltsv)
self.addCleanup(csv.unregister_dialect, name)
self.assertEqual(csv.get_dialect(name).delimiter, '\t')
got_dialects = sorted(csv.list_dialects())
self.assertEqual(expected_dialects, got_dialects)
def test_register_kwargs(self):
name = 'fedcba'
csv.register_dialect(name, delimiter=';')
self.addCleanup(csv.unregister_dialect, name)
self.assertEqual(csv.get_dialect(name).delimiter, ';')
self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))

Pitch

Let's add a test that ensures that register_dialect do work as documented.

@sobolevn sobolevn added tests Tests in the Lib/test dir 3.11 only security fixes 3.10 only security fixes 3.12 only security fixes labels Aug 13, 2022
@sobolevn sobolevn self-assigned this Aug 13, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Aug 13, 2022
@JelleZijlstra JelleZijlstra self-assigned this Aug 29, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 29, 2022
…nGH-95951)

(cherry picked from commit 1c01bd2)

Co-authored-by: Nikita Sobolev <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 29, 2022
…nGH-95951)

(cherry picked from commit 1c01bd2)

Co-authored-by: Nikita Sobolev <[email protected]>
miss-islington added a commit that referenced this issue Aug 29, 2022
(cherry picked from commit 1c01bd2)

Co-authored-by: Nikita Sobolev <[email protected]>
miss-islington added a commit that referenced this issue Sep 21, 2022
(cherry picked from commit 1c01bd2)

Co-authored-by: Nikita Sobolev <[email protected]>
@JelleZijlstra
Copy link
Member

PRs were merged, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes tests Tests in the Lib/test dir
Projects
None yet
Development

No branches or pull requests

2 participants