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

Method test_zstdfile_flush

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected