Fix random_ascii behavior : it was in fact returning a string with 2*length ...

This commit is contained in:
Alexandre Aubin 2022-08-05 10:55:04 +02:00
parent b20b1af116
commit 4239f466f8
2 changed files with 3 additions and 2 deletions

View file

@ -65,6 +65,6 @@ def prependlines(text, prepend):
# Randomize ------------------------------------------------------------ # Randomize ------------------------------------------------------------
def random_ascii(length=20): def random_ascii(length=40):
"""Return a random ascii string""" """Return a random ascii string"""
return binascii.hexlify(os.urandom(length)).decode("ascii") return binascii.hexlify(os.urandom(length)).decode("ascii")[:length]

View file

@ -20,3 +20,4 @@ def test_prependlines():
def test_random_ascii(): def test_random_ascii():
assert isinstance(random_ascii(length=2), str) assert isinstance(random_ascii(length=2), str)
assert len(random_ascii(length=10)) == 10