8000 Update test_io.py to set newlines for header/footer. · numpy/numpy@da587c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit da587c5

Browse files
authored
Update test_io.py to set newlines for header/footer.
1 parent b83afd1 commit da587c5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

numpy/lib/tests/test_io.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,34 +488,38 @@ def test_header_footer(self):
488488

489489
c = BytesIO()
490490
a = np.array([(1, 2), (3, 4)], dtype=int)
491+
a_txt = '1 2' + os.linesep + '3 4' + os.linesep
491492
test_header_footer = 'Test header / footer'
492493
# Test the header keyword argument
493494
np.savetxt(c, a, fmt='%1d', header=test_header_footer)
494495
c.seek(0)
495496
assert_equal(c.read(),
496-
asbytes('# ' + test_header_footer + '\n1 2\n3 4\n'))
497+
asbytes('# ' + test_header_footer + os.linesep
498+
+ a_txt))
497499
# Test the footer keyword argument
498500
c = BytesIO()
499501
np.savetxt(c, a, fmt='%1d', footer=test_header_footer)
500502
c.seek(0)
501503
assert_equal(c.read(),
502-
asbytes('1 2\n3 4\n# ' + test_header_footer + '\n'))
504+
asbytes(a_txt + '# ' + test_header_footer + os.linesep))
503505
# Test the commentstr keyword argument used on the header
504506
c = BytesIO()
505507
commentstr = '% '
506508
np.savetxt(c, a, fmt='%1d',
507509
header=test_header_footer, comments=commentstr)
508510
c.seek(0)
509511
assert_equal(c.read(),
510-
asbytes(commentstr + test_header_footer + '\n' + '1 2\n3 4\n'))
512+
asbytes(commentstr + test_header_footer + os.linesep
513+
+ a_txt))
511514
# Test the commentstr keyword argument used on the footer
512515
c = BytesIO()
513516
commentstr = '% '
514517
np.savetxt(c, a, fmt='%1d',
515518
footer=test_header_footer, comments=commentstr)
516519
c.seek(0)
517520
assert_equal(c.read(),
518-
asbytes('1 2\n3 4\n' + commentstr + test_header_footer + '\n'))
521+
asbytes(a_txt + commentstr + test_header_footer
522+
+ os.linesep))
519523

520524
def test_file_roundtrip(self):
521525
with temppath() as name:
@@ -623,15 +627,15 @@ def test_unicode_bytestream(self):
623627
s = BytesIO()
624628
np.savetxt(s, a, fmt=['%s'], encoding='UTF-8')
625629
s.seek(0)
626-
assert_equal(s.read().decode('UTF-8'), utf8 + '\n')
630+
assert_equal(s.read().decode('UTF-8'), utf8 + os.linesep)
627631

628632
def test_unicode_stringstream(self):
629633
utf8 = b'\xcf\x96'.decode('UTF-8')
630634
a = np.array([utf8], dtype=np.str_)
631635
s = StringIO()
632636
np.savetxt(s, a, fmt=['%s'], encoding='UTF-8')
633637
s.seek(0)
634-
assert_equal(s.read(), utf8 + '\n')
638+
assert_equal(s.read(), utf8 + os.linesep)
635639

636640
@pytest.mark.parametrize("fmt", ["%f", b"%f"])
637641
@pytest.mark.parametrize("iotype", [StringIO, BytesIO])
@@ -642,9 +646,9 @@ def test_unicode_and_bytes_fmt(self, fmt, iotype):
642646
np.savetxt(s, a, fmt=fmt)
643647
s.seek(0)
644648
if iotype is StringIO:
645-
assert_equal(s.read(), "%f\n" % 1.)
649+
assert_equal(s.read(), "%f%s" % (1., os.linesep))
646650
5701 else:
647-
assert_equal(s.read(), b"%f\n" % 1.)
651+
assert_equal(s.read(), b"%f%s" % (1., os.linesep))
648652

649653
@pytest.mark.skipif(sys.platform=='win32', reason="files>4GB may not work")
650654
@pytest.mark.slow

0 commit comments

Comments
 (0)
0