11import io
2- import pytest
3- import sys
42import os
3+ import sys
4+
5+ import pytest
6+
57from stdlib import csv
68
79# Add src directory to PYTHONPATH to allow direct import of stdlib
@@ -230,7 +232,8 @@ def test_embedded_newlines_in_quoted_fields(self):
230232 # Let's assume strict=True for this test.
231233 with pytest .raises (csv .Error , match = "unclosed quote" ):
232234 list (csv .reader (io .StringIO ('a,"b\n c",d' ), strict = True ))
233- # If not strict, it might yield `[['a', 'b']]` or `[['a', '"b']]` for `a,"b\n`. The current reader's unclosed quote error isn't bypassed by non-strict mode.
235+ # If not strict, it might yield `[['a', 'b']]` or `[['a', '"b']]` for `a,"b\n`.
236+ # The current reader's unclosed quote error isn't bypassed by non-strict mode.
234237
235238 def test_empty_lines_and_whitespace_lines (self ):
236239 data = "\r \n \r \n val1,val2\r \n \r \n " # Empty line, whitespace line, data, empty line
@@ -283,6 +286,7 @@ def test_reader_error_unclosed_quote(self):
283286 with pytest .raises (csv .Error , match = "unclosed quote" ):
284287 list (csv .reader (sio )) # Test with default strictness
285288
289+ sio .seek (0 ) # Reset position for second test
286290 with pytest .raises (csv .Error , match = "unclosed quote" ):
287291 list (csv .reader (sio , strict = True ))
288292
@@ -297,13 +301,16 @@ def test_reader_error_unexpected_chars_after_quotes_strict(self):
297301 # So it always raises an error, but message might differ or behavior could be refined for non-strict.
298302 # For now, let's assume strict=True in the dialect for this test.
299303 with pytest .raises (
300- csv .Error , match = "'b' found after quoted field "
301- ): # Or similar, based on exact error msg
304+ csv .Error , match = "delimiter expected after"
305+ ): # Our error message pattern
302306 list (csv .reader (sio , strict = True ))
303307
304308 # Test default strictness (False) - still expect error from current code
309+ sio2 = io .StringIO (
310+ data
311+ ) # Need a fresh StringIO since the first one was consumed
305312 with pytest .raises (csv .Error , match = "malformed CSV row" ):
306- list (csv .reader (sio ))
313+ list (csv .reader (sio2 ))
307314
308315 def test_field_size_limit_reader (self ):
309316 original_limit = csv .field_size_limit ()
@@ -372,7 +379,7 @@ def test_writerows(self):
372379 # Assuming the goal is to fix the E501 on the line that was *originally* here at 322.
373380 # The current `read_files` shows the problematic line.
374381 # Shortened comment. Note: This assertion itself is debated in the test.
375- assert sio .getvalue () == ' a,b\r \n 1,2\r \n "x","" \r \n '
382+ assert sio .getvalue () == " a,b\r \n 1,2\r \n x, \r \n "
376383 # Correction for writerows output:
377384 # If x is simple string, and "" is empty string due to None:
378385 # 'a,b\r\n1,2\r\nx,\r\n' (If empty string doesn't get quoted by default)
@@ -431,7 +438,7 @@ def test_quoting_nonnumeric_writer(self):
431438 sio3 = io .StringIO () # Numeric that contains delimiter
432439 w3 = csv .writer (sio3 , quoting = csv .QUOTE_NONNUMERIC , delimiter = "." )
433440 w3 .writerow ([1 , 2.3 ]) # 2.3 -> "2.3" which contains '.', so it will be quoted
434- assert sio3 .getvalue () == '1, "2.3"\r \n '
441+ assert sio3 .getvalue () == '1. "2.3"\r \n '
435442
436443 def test_quoting_none_writer_with_escapechar (self ):
437444 sio = io .StringIO ()
@@ -572,7 +579,7 @@ def test_dialect_properties_validation(self):
572579 ):
573580 csv .Dialect (delimiter = "long" )
574581 with pytest .raises (TypeError , match = "doublequote must be a boolean" ):
575- csv .Dialect (doublequote = True ) # Changed "true" to True
582+ csv .Dialect (doublequote = "true" ) # Invalid type - should be boolean
576583 # ... other validation checks in Dialect.__init__ can be tested similarly
577584
578585 def test_predefined_dialects_exist (self ):
0 commit comments