Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def testEOFError(self):
def testDecompress4G(self, size):
# "Test BZ2Decompressor.decompress() with >4GiB input"
blocksize = 10 * 1024 * 1024
block = random.getrandbits(blocksize * 8).to_bytes(blocksize, 'little')
block = random.randbytes(blocksize)
try:
data = block * (size // blocksize + 1)
compressed = bz2.compress(data)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def test_compressor_bigmem(self, size):
def test_decompressor_bigmem(self, size):
lzd = LZMADecompressor()
blocksize = 10 * 1024 * 1024
block = random.getrandbits(blocksize * 8).to_bytes(blocksize, "little")
block = random.randbytes(blocksize)
try:
input = block * (size // blocksize + 1)
cdata = lzma.compress(input)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def test_null_tarfile(self):
def test_ignore_zeros(self):
# Test TarFile's ignore_zeros option.
# generate 512 pseudorandom bytes
data = Random(0).getrandbits(512*8).to_bytes(512, 'big')
data = Random(0).randbytes(512)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use the global randbytes().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses a seed of 0. I would prefer to use a temporary instance, rather than modifying random._inst.

for char in (b'\0', b'a'):
# Test if EOFHeaderError ('\0') and InvalidHeaderError ('a')
# are ignored correctly.
Expand Down
11 changes: 4 additions & 7 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


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,
Expand All @@ -33,9 +33,6 @@
('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:
Expand Down Expand Up @@ -324,7 +321,7 @@ def test_read_return_size(self):
# 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:
Expand Down Expand Up @@ -2423,8 +2420,8 @@ def test_open_write(self):
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
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_zlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ def check_big_compress_buffer(self, size, compress_func):
# Generate 10 MiB worth of random, and expand it by repeating it.
# The assumption is that zlib's memory is not big enough to exploit
# such spread out redundancy.
data = b''.join([random.getrandbits(8 * _1M).to_bytes(_1M, 'little')
for i in range(10)])
data = random.randbytes(_1M * 10)
data = data * (size // len(data) + 1)
try:
compress_func(data)
Expand Down