MCPcopy Index your code
hub / github.com/python/cpython / test_tofromfile

Method test_tofromfile

Lib/test/test_array.py:502–522  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

500 )
501
502 def test_tofromfile(self):
503 a = array.array(self.typecode, 2*self.example)
504 self.assertRaises(TypeError, a.tofile)
505 os_helper.unlink(os_helper.TESTFN)
506 f = open(os_helper.TESTFN, 'wb')
507 try:
508 a.tofile(f)
509 f.close()
510 b = array.array(self.typecode)
511 f = open(os_helper.TESTFN, 'rb')
512 self.assertRaises(TypeError, b.fromfile)
513 b.fromfile(f, len(self.example))
514 self.assertEqual(b, array.array(self.typecode, self.example))
515 self.assertNotEqual(a, b)
516 self.assertRaises(EOFError, b.fromfile, f, len(self.example)+1)
517 self.assertEqual(a, b)
518 f.close()
519 finally:
520 if not f.closed:
521 f.close()
522 os_helper.unlink(os_helper.TESTFN)
523
524 def test_fromfile_ioerror(self):
525 # Issue #5395: Check if fromfile raises a proper OSError

Callers

nothing calls this directly

Calls 7

assertRaisesMethod · 0.95
fromfileMethod · 0.80
assertNotEqualMethod · 0.80
openFunction · 0.50
unlinkMethod · 0.45
closeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected