MCPcopy Index your code
hub / github.com/numpy/numpy / test_header_footer

Method test_header_footer

numpy/lib/tests/test_io.py:456–488  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

454 assert_raises(ValueError, np.savetxt, c, a, fmt=99)
455
456 def test_header_footer(self):
457 # Test the functionality of the header and footer keyword argument.
458
459 c = BytesIO()
460 a = np.array([(1, 2), (3, 4)], dtype=int)
461 test_header_footer = 'Test header / footer'
462 # Test the header keyword argument
463 np.savetxt(c, a, fmt='%1d', header=test_header_footer)
464 c.seek(0)
465 assert_equal(c.read(),
466 asbytes('# ' + test_header_footer + '\n1 2\n3 4\n'))
467 # Test the footer keyword argument
468 c = BytesIO()
469 np.savetxt(c, a, fmt='%1d', footer=test_header_footer)
470 c.seek(0)
471 assert_equal(c.read(),
472 asbytes('1 2\n3 4\n# ' + test_header_footer + '\n'))
473 # Test the commentstr keyword argument used on the header
474 c = BytesIO()
475 commentstr = '% '
476 np.savetxt(c, a, fmt='%1d',
477 header=test_header_footer, comments=commentstr)
478 c.seek(0)
479 assert_equal(c.read(),
480 asbytes(commentstr + test_header_footer + '\n' + '1 2\n3 4\n'))
481 # Test the commentstr keyword argument used on the footer
482 c = BytesIO()
483 commentstr = '% '
484 np.savetxt(c, a, fmt='%1d',
485 footer=test_header_footer, comments=commentstr)
486 c.seek(0)
487 assert_equal(c.read(),
488 asbytes('1 2\n3 4\n' + commentstr + test_header_footer + '\n'))
489
490 @pytest.mark.parametrize("filename_type", [Path, str])
491 def test_file_roundtrip(self, filename_type):

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
asbytesFunction · 0.90
seekMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected