Coverage for audoma/example_generators.py: 64%

11 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-08-08 06:13 +0000

1import random 

2 

3import lorem 

4 

5 

6def generate_lorem_ipsum(min_length=20, max_length=80) -> str: 

7 """ 

8 This function generates a random string of lorem ipsum text. 

9 Args: 

10 min_length (int): The minimum length of the string. 

11 max_length (int): The maximum length of the string. 

12 

13 Returns: 

14 str: A random string of lorem ipsum text. 

15 """ 

16 random_lorem = lorem.text() 

17 if len(random_lorem) < min_length: 

18 random_lorem += lorem.text() 

19 if max_length < 20: 

20 max_length = max_length 

21 else: 

22 max_length = max([min([80, max_length]), min_length]) 

23 min_length = min([max([20, min_length]), max_length]) 

24 

25 return random_lorem[: random.randint(min_length, max_length)]