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

Method test_io_on_closed_object

Lib/test/test_gzip.py:186–212  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

184 self.assertEqual(f.read(size), data1)
185
186 def test_io_on_closed_object(self):
187 # Test that I/O operations on closed GzipFile objects raise a
188 # ValueError, just like the corresponding functions on file objects.
189
190 # Write to a file, open it for reading, then close it.
191 self.test_write()
192 f = gzip.GzipFile(self.filename, 'r')
193 fileobj = f.fileobj
194 self.assertFalse(fileobj.closed)
195 f.close()
196 self.assertTrue(fileobj.closed)
197 with self.assertRaises(ValueError):
198 f.read(1)
199 with self.assertRaises(ValueError):
200 f.seek(0)
201 with self.assertRaises(ValueError):
202 f.tell()
203 # Open the file for writing, then close it.
204 f = gzip.GzipFile(self.filename, 'w')
205 fileobj = f.fileobj
206 self.assertFalse(fileobj.closed)
207 f.close()
208 self.assertTrue(fileobj.closed)
209 with self.assertRaises(ValueError):
210 f.write(b'')
211 with self.assertRaises(ValueError):
212 f.flush()
213
214 def test_append(self):
215 self.test_write()

Callers

nothing calls this directly

Calls 10

test_writeMethod · 0.95
closeMethod · 0.95
readMethod · 0.95
seekMethod · 0.95
tellMethod · 0.95
writeMethod · 0.95
flushMethod · 0.95
assertFalseMethod · 0.80
assertTrueMethod · 0.80
assertRaisesMethod · 0.45

Tested by

no test coverage detected