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

Method test_zstdfile_flush

Lib/test/test_zstd.py:2410–2443  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2408 self.assertEqual(b''.join(lst), THIS_FILE_BYTES*5)
2409
2410 def test_zstdfile_flush(self):
2411 # closed
2412 f = ZstdFile(io.BytesIO(), 'w')
2413 f.close()
2414 with self.assertRaises(ValueError):
2415 f.flush()
2416
2417 # read
2418 with ZstdFile(io.BytesIO(), 'r') as f:
2419 # does nothing for read-only stream
2420 f.flush()
2421
2422 # write
2423 DAT = b'abcd'
2424 bi = io.BytesIO()
2425 with ZstdFile(bi, 'w') as f:
2426 self.assertEqual(f.write(DAT), len(DAT))
2427 self.assertEqual(f.tell(), len(DAT))
2428 self.assertEqual(bi.tell(), 0) # not enough for a block
2429
2430 self.assertEqual(f.flush(), None)
2431 self.assertEqual(f.tell(), len(DAT))
2432 self.assertGreater(bi.tell(), 0) # flushed
2433
2434 # write, no .flush() method
2435 class C:
2436 def write(self, b):
2437 return len(b)
2438 with ZstdFile(C(), 'w') as f:
2439 self.assertEqual(f.write(DAT), len(DAT))
2440 self.assertEqual(f.tell(), len(DAT))
2441
2442 self.assertEqual(f.flush(), None)
2443 self.assertEqual(f.tell(), len(DAT))
2444
2445 def test_zstdfile_flush_mode(self):
2446 self.assertEqual(ZstdFile.FLUSH_BLOCK, ZstdCompressor.FLUSH_BLOCK)

Callers

nothing calls this directly

Calls 10

closeMethod · 0.95
flushMethod · 0.95
writeMethod · 0.95
tellMethod · 0.95
tellMethod · 0.95
ZstdFileClass · 0.90
assertGreaterMethod · 0.80
CClass · 0.70
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected