MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_io_on_closed_object

Method test_io_on_closed_object

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

Source from the content-addressed store, hash-verified

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