From 4239f466f80576b508b20a19538adfa8dc7f68fe Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 5 Aug 2022 10:55:04 +0200 Subject: [PATCH] Fix random_ascii behavior : it was in fact returning a string with 2*length ... --- moulinette/utils/text.py | 4 ++-- test/test_text.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/moulinette/utils/text.py b/moulinette/utils/text.py index 2da101a5..edaa4d24 100644 --- a/moulinette/utils/text.py +++ b/moulinette/utils/text.py @@ -65,6 +65,6 @@ def prependlines(text, prepend): # Randomize ------------------------------------------------------------ -def random_ascii(length=20): +def random_ascii(length=40): """Return a random ascii string""" - return binascii.hexlify(os.urandom(length)).decode("ascii") + return binascii.hexlify(os.urandom(length)).decode("ascii")[:length] diff --git a/test/test_text.py b/test/test_text.py index 1bf1f896..4c31f292 100644 --- a/test/test_text.py +++ b/test/test_text.py @@ -20,3 +20,4 @@ def test_prependlines(): def test_random_ascii(): assert isinstance(random_ascii(length=2), str) + assert len(random_ascii(length=10)) == 10