Skip to content

Commit 1468d25

Browse files
committed
TST: Add test for default line_terminator argument
1 parent 9179e63 commit 1468d25

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/io/formats/test_to_csv.py

+20
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,23 @@ def test_to_csv_compression(self, compression_only,
563563
result = pd.read_csv(path, index_col=0,
564564
compression=read_compression)
565565
tm.assert_frame_equal(result, df)
566+
567+
568+
569+
def test_csv_formatter_line_terminator_default(monkeypatch):
570+
# see GH #23608
571+
# ensure default line_terminator used is os.linesep
572+
df = tm.makeDataFrame()
573+
574+
with monkeypatch.context() as m:
575+
# fake default os.linesep to look like windows
576+
m.setattr(os, 'linesep', '\r\n')
577+
assert os.linesep == '\r\n'
578+
# import within this context so it uses the patched os.linesep
579+
from pandas.io.formats.csvs import CSVFormatter
580+
581+
formatter_with_argument = CSVFormatter(df, line_terminator='\r')
582+
assert formatter_with_argument.line_terminator == '\r'
583+
584+
formatter_with_default = CSVFormatter(df)
585+
assert formatter_with_default.line_terminator == os.linesep

0 commit comments

Comments
 (0)