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

Method test_close_error_on_close

Lib/test/test_io/test_textio.py:944–962  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

942 txt.flush = lambda: None # break reference loop
943
944 def test_close_error_on_close(self):
945 buffer = self.BytesIO(self.testdata)
946 def bad_flush():
947 raise OSError('flush')
948 def bad_close():
949 raise OSError('close')
950 buffer.close = bad_close
951 txt = self.TextIOWrapper(buffer, encoding="ascii")
952 txt.flush = bad_flush
953 with self.assertRaises(OSError) as err: # exception not swallowed
954 txt.close()
955 self.assertEqual(err.exception.args, ('close',))
956 self.assertIsInstance(err.exception.__context__, OSError)
957 self.assertEqual(err.exception.__context__.args, ('flush',))
958 self.assertFalse(txt.closed)
959
960 # Silence destructor error
961 buffer.close = lambda: None
962 txt.flush = lambda: None
963
964 def test_nonnormalized_close_error_on_close(self):
965 # Issue #21677

Callers

nothing calls this directly

Calls 5

closeMethod · 0.95
assertIsInstanceMethod · 0.80
assertFalseMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected