(self)
| 2443 | self.assertEqual(f.tell(), len(DAT)) |
| 2444 | |
| 2445 | def test_zstdfile_flush_mode(self): |
| 2446 | self.assertEqual(ZstdFile.FLUSH_BLOCK, ZstdCompressor.FLUSH_BLOCK) |
| 2447 | self.assertEqual(ZstdFile.FLUSH_FRAME, ZstdCompressor.FLUSH_FRAME) |
| 2448 | with self.assertRaises(AttributeError): |
| 2449 | ZstdFile.CONTINUE |
| 2450 | |
| 2451 | bo = io.BytesIO() |
| 2452 | with ZstdFile(bo, 'w') as f: |
| 2453 | # flush block |
| 2454 | self.assertEqual(f.write(b'123'), 3) |
| 2455 | self.assertIsNone(f.flush(f.FLUSH_BLOCK)) |
| 2456 | p1 = bo.tell() |
| 2457 | # mode == .last_mode, should return |
| 2458 | self.assertIsNone(f.flush()) |
| 2459 | p2 = bo.tell() |
| 2460 | self.assertEqual(p1, p2) |
| 2461 | # flush frame |
| 2462 | self.assertEqual(f.write(b'456'), 3) |
| 2463 | self.assertIsNone(f.flush(mode=f.FLUSH_FRAME)) |
| 2464 | # flush frame |
| 2465 | self.assertEqual(f.write(b'789'), 3) |
| 2466 | self.assertIsNone(f.flush(f.FLUSH_FRAME)) |
| 2467 | p1 = bo.tell() |
| 2468 | # mode == .last_mode, should return |
| 2469 | self.assertIsNone(f.flush(f.FLUSH_FRAME)) |
| 2470 | p2 = bo.tell() |
| 2471 | self.assertEqual(p1, p2) |
| 2472 | self.assertEqual(decompress(bo.getvalue()), b'123456789') |
| 2473 | |
| 2474 | bo = io.BytesIO() |
| 2475 | with ZstdFile(bo, 'w') as f: |
| 2476 | f.write(b'123') |
| 2477 | with self.assertRaisesRegex(ValueError, r'\.FLUSH_.*?\.FLUSH_'): |
| 2478 | f.flush(ZstdCompressor.CONTINUE) |
| 2479 | with self.assertRaises(ValueError): |
| 2480 | f.flush(-1) |
| 2481 | with self.assertRaises(ValueError): |
| 2482 | f.flush(123456) |
| 2483 | with self.assertRaises(TypeError): |
| 2484 | f.flush(node=ZstdCompressor.CONTINUE) |
| 2485 | with self.assertRaises((TypeError, ValueError)): |
| 2486 | f.flush('FLUSH_FRAME') |
| 2487 | with self.assertRaises(TypeError): |
| 2488 | f.flush(b'456', f.FLUSH_BLOCK) |
| 2489 | |
| 2490 | def test_zstdfile_truncate(self): |
| 2491 | with ZstdFile(io.BytesIO(), 'w') as f: |
nothing calls this directly
no test coverage detected