Kill the surviving mutants of the compressor, its CLI and the report copy's time bounds
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import errno
|
||||
import gzip
|
||||
import os
|
||||
import pathlib
|
||||
@@ -21,9 +22,25 @@ class Compress(unittest.TestCase):
|
||||
self.assertIsNone(compressed.compress(plain))
|
||||
self.assertFalse(plain.exists())
|
||||
packed = pathlib.Path(root, "t.jsonl.gz")
|
||||
self.assertEqual(gzip.decompress(packed.read_bytes()), b'{"a": 1}\n')
|
||||
# A gzip header's own time is 0, so compressing the same bytes twice writes the same file.
|
||||
self.assertEqual(packed.read_bytes(), gzip.compress(b'{"a": 1}\n', mtime=0))
|
||||
self.assertEqual(packed.stat().st_mtime, 2000)
|
||||
|
||||
def test_a_gzip_it_cannot_write_keeps_the_original_and_says_why(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
plain = pathlib.Path(root, "t.jsonl")
|
||||
plain.write_bytes(b"kept\n")
|
||||
with mock.patch.object(compressed, "replace_file", return_value=Failure("disk full")):
|
||||
self.assertEqual(compressed.compress(plain), Failure(f"could not compress {plain}: disk full"))
|
||||
self.assertEqual(plain.read_bytes(), b"kept\n")
|
||||
|
||||
def test_a_file_it_cannot_read_fails_naming_it(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = pathlib.Path(root, "t.jsonl")
|
||||
folder.mkdir()
|
||||
failed = compressed.compress(folder)
|
||||
self.assertTrue(failed.reason.startswith(f"could not compress {folder}: [Errno {errno.EISDIR}]"), failed.reason)
|
||||
|
||||
def test_a_copy_that_reads_back_other_bytes_keeps_the_original_and_fails(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
plain = pathlib.Path(root, "t.jsonl")
|
||||
@@ -61,8 +78,9 @@ class Read(unittest.TestCase):
|
||||
self.assertEqual(compressed.read_stored(pathlib.Path(root, "b.jsonl")), b"b\n")
|
||||
self.assertEqual(compressed.stored(pathlib.Path(root, "b.jsonl")), pathlib.Path(root, "b.jsonl.gz"))
|
||||
self.assertIsNone(compressed.stored(pathlib.Path(root, "c.jsonl")))
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
with self.assertRaises(FileNotFoundError) as raised:
|
||||
compressed.read_stored(pathlib.Path(root, "c.jsonl"))
|
||||
self.assertEqual((raised.exception.errno, raised.exception.strerror, raised.exception.filename), (errno.ENOENT, "No such file or directory", str(pathlib.Path(root, "c.jsonl"))))
|
||||
|
||||
def test_the_plain_file_wins_over_an_older_gzip_beside_it(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
@@ -73,8 +91,10 @@ class Read(unittest.TestCase):
|
||||
def test_a_truncated_gzip_fails_as_an_os_error(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
pathlib.Path(root, "a.jsonl.gz").write_bytes(gzip.compress(b"a\n" * 100)[:20])
|
||||
with self.assertRaises(OSError):
|
||||
with self.assertRaises(OSError) as raised:
|
||||
compressed.read_stored(pathlib.Path(root, "a.jsonl"))
|
||||
self.assertEqual((raised.exception.errno, raised.exception.filename), (errno.EIO, str(pathlib.Path(root, "a.jsonl.gz"))))
|
||||
self.assertTrue(raised.exception.strerror.startswith("not a whole gzip: "), raised.exception.strerror)
|
||||
|
||||
def test_globs_each_file_once_by_its_plain_name(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
|
||||
Reference in New Issue
Block a user