Skip to content

Commit 1d18e70

Browse files
webknjazJakuje
authored andcommitted
Optimize the large_payload fixture
1 parent c2e0cb1 commit 1d18e70

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

tests/unit/scp_test.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66
import random
7+
import string
78
import uuid
89

910
import pytest
@@ -94,16 +95,12 @@ def test_get_existing_local(pre_existing_file_path, src_path, ssh_scp, transmit_
9495

9596
@pytest.fixture
9697
def large_payload():
97-
"""Generate a large test payload."""
98-
# buffer of random 1024 bytes -- just printable ones for easier debugging
99-
rands = []
100-
for _ in range(1024):
101-
rnd = chr(random.randint(ord(' '), ord('~')))
102-
rands.append(rnd)
103-
rand = ''.join(rands)
104-
# .. repeated 65 times
105-
repeat = 65
106-
return ''.join(rand for _ in range(repeat)).encode()
98+
"""Generate a large 65537 byte (64kB+1B) test payload."""
99+
random_char_kilobyte = [ord(random.choice(string.printable)) for _ in range(1024)]
100+
full_bytes_number = 64
101+
a_64kB_chunk = bytes(random_char_kilobyte * full_bytes_number)
102+
the_last_byte = random.choice(random_char_kilobyte).to_bytes(length=1, byteorder='big')
103+
return a_64kB_chunk + the_last_byte
107104

108105

109106
@pytest.fixture

0 commit comments

Comments
 (0)