Skip to content

gh-151526: Add csv writer tests for quote style edge cases - #151527

Closed
doma17 wants to merge 2 commits into
python:mainfrom
doma17:gh-csv-quote-style-coverage
Closed

gh-151526: Add csv writer tests for quote style edge cases#151527
doma17 wants to merge 2 commits into
python:mainfrom
doma17:gh-csv-quote-style-coverage

Conversation

@doma17

@doma17 doma17 commented Jun 16, 2026

Copy link
Copy Markdown

Adds focused csv.writer coverage for QUOTE_STRINGS and QUOTE_NOTNULL.

The existing test_csv coverage already checks basic output for these quote styles. This adds narrower edge-case coverage for:

  • rejecting quotechar=None when those quote styles enable quoting
  • preserving quote/escape handling with escapechar and doublequote=False

This helps lock down behavior around the newer quoting modes and gives alternative implementations more precise regression coverage.

Testing:

  • ./python.exe -m test test_csv -v
  • ./python.exe -m test test_csv -q

@python-cla-bot

python-cla-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Jun 16, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@aisk aisk added the skip news label Jun 16, 2026

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quotechar=None check in Modules/_csv.c is:

cpython/Modules/_csv.c

Lines 542 to 546 in 228b1bf

if (self->quoting != QUOTE_NONE && self->quotechar == NOT_SET) {
PyErr_SetString(PyExc_TypeError,
"quotechar must be set if quoting enabled");
goto err;
}

so it's mode-agnostic (looping over three quoting modes tests the same branch three times).

The escapechar/doublequote handling in join_append_data is likewise shared by every mode other than QUOTE_NONE:

cpython/Modules/_csv.c

Lines 1219 to 1232 in 228b1bf

if (dialect->quoting == QUOTE_NONE)
want_escape = 1;
else {
if (c == dialect->quotechar) {
if (dialect->doublequote)
ADDCH(dialect->quotechar);
else
want_escape = 1;
}
else if (c == dialect->escapechar) {
want_escape = 1;
}
if (!want_escape)
*quoted = 1;

so test_write_quote_styles_escape doesn't exercise anything specific to QUOTE_STRINGS/QUOTE_NOTNULL either. The only mode-specific behaviour is the initial quoted flag set in csv_writerow_lock_held, and that's already covered by the existing ['a','',None,1] cases in test_write_arg_valid.

Seeing as this adds no new coverage, I'm closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants