Coverage for src/common/utils.py: 46%

13 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-09-21 16:24 +0300

1import re 

2 

3class ChoicesMaxLengthMixin: 

4 

5 @classmethod 

6 def max_length(cls): 

7 """ 

8 Calculate the maximum length needed for storing choice values. 

9 """ 

10 # Use a generator expression to find the maximum length 

11 # len(choice.value) gets the length of each choice's value 

12 # max() finds the largest length among all choices 

13 

14 return max(len(choice.value) for choice in cls) 

15 

16 

17def convert_to_lower_case(text): 

18 if not text or not isinstance(text, str): 

19 return "" 

20 

21 # Replace common separators with spaces 

22 text = re.sub(r'[-_]+', ' ', text) 

23 

24 # Handle camelCase by inserting spaces before uppercase letters 

25 text = re.sub(r'(?<!^)(?=[A-Z])', ' ', text) 

26 

27 # Split into words and filter out empty strings 

28 words = [word for word in text.split() if word] 

29 

30 # Convert each word: first letter uppercase, rest lowercase 

31 lower_words = [word.lower() for word in words] 

32 

33 return ''.join(lower_words)