Cleanup
authorJakob Cornell <jakob+gpg@jcornell.net>
Sat, 13 Nov 2021 05:25:23 +0000 (23:25 -0600)
committerJakob Cornell <jakob+gpg@jcornell.net>
Sat, 13 Nov 2021 05:25:23 +0000 (23:25 -0600)
src/disk_jumble/tests/test_verify.py

index facd67e631a5ab5f62e59d7d63f50efc624665f4..538f5fb1229e94e6e301fd0ca864ae7ea507af2c 100644 (file)
@@ -30,13 +30,12 @@ from disk_jumble.verify import do_verify
 _BUF_SIZE = 16 * 1024 ** 2  # in bytes
 
 
-def _random_file(size: int) -> tempfile.NamedTemporaryFile:
-       r = Random(0)
+def _random_file(size: int, rand_src: Random) -> tempfile.NamedTemporaryFile:
        f = tempfile.NamedTemporaryFile(buffering = _BUF_SIZE)
        try:
                while f.tell() < size:
                        write_size = min(size - f.tell(), _BUF_SIZE)
-                       f.write(bytes(r.getrandbits(8) for _ in range(write_size)))
+                       f.write(bytes(rand_src.getrandbits(8) for _ in range(write_size)))
                f.seek(0)
                return f
        except Exception:
@@ -46,7 +45,6 @@ def _random_file(size: int) -> tempfile.NamedTemporaryFile:
 
 class Tests(unittest.TestCase):
        _SCHEMAS = {"public", "diskjumble", "bittorrent"}
-       _BUF_SIZE = 16 * 1024 ** 2  # in bytes
 
        def _basic_fresh_verify_helper(self, read_size):
                sector_size = 32
@@ -54,7 +52,7 @@ class Tests(unittest.TestCase):
 
                torrent_len = 3 * piece_size
                disk = self._write_disk(sector_size, torrent_len // sector_size)
-               with _random_file(torrent_len) as torrent_file:
+               with _random_file(torrent_len, Random(0)) as torrent_file:
                        torrent = _Torrent(torrent_file, piece_size)
                        torrent_file.seek(0)
                        self._write_torrent(torrent)