summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-17 20:54:38 (GMT)
committerGitHub <noreply@github.com>2020-04-17 20:54:38 (GMT)
commit87502ddd710eb1f030b8ff5a60b05becea3f474f (patch)
tree695a6abbaa45adf48766011f144050ce9b6b3780 /Lib/test/test_zipfile.py
parent223221b290db00ca1042c77103efcbc072f29c90 (diff)
downloadcpython-87502ddd710eb1f030b8ff5a60b05becea3f474f.zip
cpython-87502ddd710eb1f030b8ff5a60b05becea3f474f.tar.gz
cpython-87502ddd710eb1f030b8ff5a60b05becea3f474f.tar.bz2
bpo-40286: Use random.randbytes() in tests (GH-19575)
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 643c5b4..29d98c8 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -16,7 +16,7 @@ import zipfile
from tempfile import TemporaryFile
-from random import randint, random, getrandbits
+from random import randint, random, randbytes
from test.support import script_helper
from test.support import (TESTFN, findfile, unlink, rmtree, temp_dir, temp_cwd,
@@ -33,9 +33,6 @@ SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'),
('ziptest2dir/ziptest3dir/_ziptest3', 'azsxdcfvgb'),
('ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3', '6y7u8i9o0p')]
-def getrandbytes(size):
- return getrandbits(8 * size).to_bytes(size, 'little')
-
def get_files(test):
yield TESTFN2
with TemporaryFile() as f:
@@ -324,7 +321,7 @@ class AbstractTestsWithSourceFile:
# than requested.
for test_size in (1, 4095, 4096, 4097, 16384):
file_size = test_size + 1
- junk = getrandbytes(file_size)
+ junk = randbytes(file_size)
with zipfile.ZipFile(io.BytesIO(), "w", self.compression) as zipf:
zipf.writestr('foo', junk)
with zipf.open('foo', 'r') as fp:
@@ -2423,8 +2420,8 @@ class UnseekableTests(unittest.TestCase):
class TestsWithMultipleOpens(unittest.TestCase):
@classmethod
def setUpClass(cls):
- cls.data1 = b'111' + getrandbytes(10000)
- cls.data2 = b'222' + getrandbytes(10000)
+ cls.data1 = b'111' + randbytes(10000)
+ cls.data2 = b'222' + randbytes(10000)
def make_test_archive(self, f):
# Create the ZIP archive