@@ -350,9 +350,9 @@ def test_to_csv_string_with_lf(self):
350
350
}
351
351
df = pd .DataFrame (data )
352
352
353
- os_linesep = os .linesep .encode ('utf-8' )
354
-
355
353
with tm .ensure_clean ('lf_test.csv' ) as path :
354
+ # case 1: The default line terminator(=os.linesep)(PR 21406)
355
+ os_linesep = os .linesep .encode ('utf-8' )
356
356
expected_noarg = (
357
357
b'int,str_lf' + os_linesep +
358
358
b'1,abc' + os_linesep +
@@ -364,6 +364,8 @@ def test_to_csv_string_with_lf(self):
364
364
with open (path , 'rb' ) as f :
365
365
assert f .read () == expected_noarg
366
366
367
+ with tm .ensure_clean ('lf_test.csv' ) as path :
368
+ # case 2: LF as line terminator
367
369
expected_lf = (
368
370
b'int,str_lf\n '
369
371
b'1,abc\n '
@@ -375,6 +377,8 @@ def test_to_csv_string_with_lf(self):
375
377
with open (path , 'rb' ) as f :
376
378
assert f .read () == expected_lf
377
379
380
+ with tm .ensure_clean ('lf_test.csv' ) as path :
381
+ # case 3: CRLF as line terminator
378
382
# 'line_terminator' should not change inner element
379
383
expected_crlf = (
380
384
b'int,str_lf\r \n '
@@ -395,9 +399,9 @@ def test_to_csv_string_with_crlf(self):
395
399
}
396
400
df = pd .DataFrame (data )
397
401
398
- os_linesep = os .linesep .encode ('utf-8' )
399
-
400
402
with tm .ensure_clean ('crlf_test.csv' ) as path :
403
+ # case 1: The default line terminator(=os.linesep)(PR 21406)
404
+ os_linesep = os .linesep .encode ('utf-8' )
401
405
expected_noarg = (
402
406
b'int,str_crlf' + os_linesep +
403
407
b'1,abc' + os_linesep +
@@ -409,6 +413,8 @@ def test_to_csv_string_with_crlf(self):
409
413
with open (path , 'rb' ) as f :
410
414
assert f .read () == expected_noarg
411
415
416
+ with tm .ensure_clean ('crlf_test.csv' ) as path :
417
+ # case 2: LF as line terminator
412
418
expected_lf = (
413
419
b'int,str_crlf\n '
414
420
b'1,abc\n '
@@ -420,6 +426,9 @@ def test_to_csv_string_with_crlf(self):
420
426
with open (path , 'rb' ) as f :
421
427
assert f .read () == expected_lf
422
428
429
+ with tm .ensure_clean ('crlf_test.csv' ) as path :
430
+ # case 3: CRLF as line terminator
431
+ # 'line_terminator' should not change inner element
423
432
expected_crlf = (
424
433
b'int,str_crlf\r \n '
425
434
b'1,abc\r \n '
@@ -446,7 +455,7 @@ def test_to_csv_stdout_file(self):
446
455
assert not sys .stdout .closed
447
456
448
457
@pytest .mark .xfail (
449
- os . name == 'nt' ,
458
+ compat . is_platform_windows () ,
450
459
reason = ("Especially in Windows, file stream should not be passed"
451
460
"to csv writer without newline='' option."
452
461
"(https://docs.python.org/3.6/library/csv.html#csv.writer)" ))
0 commit comments