Skip to content

Add csv writer tests for QUOTE_STRINGS and QUOTE_NOTNULL edge cases #151526

@doma17

Description

@doma17

Bug description

Lib/test/test_csv.py already covers the basic writer behavior for csv.QUOTE_STRINGS and csv.QUOTE_NOTNULL, but it does not explicitly exercise a couple of edge cases for these newer quoting modes:

  • quotechar=None should be rejected when quoting is enabled for QUOTE_STRINGS and QUOTE_NOTNULL, just like QUOTE_ALL.
  • quoted fields using these modes should continue to handle embedded quote characters and escape characters correctly, including the doublequote=False path.

These are small conformance checks for behavior already implemented in _csv, and they help alternative Python implementations catch regressions around the newer quote styles.

Reproducer / expected behavior

import csv
from io import StringIO

for quoting in (csv.QUOTE_STRINGS, csv.QUOTE_NOTNULL):
    try:
        csv.writer(StringIO(), quoting=quoting, quotechar=None)
    except TypeError:
        pass
    else:
        raise AssertionError("quotechar=None should be rejected")

csv.writer should also preserve the existing escaping behavior for QUOTE_STRINGS and QUOTE_NOTNULL when escapechar is configured and doublequote is toggled.

CPython versions tested on

  • CPython main branch

Operating systems tested on

  • macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dir
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions