Coverage for src/toolbox_pyspark/utils/whitespaces.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-25 23:08 +0000

1# ## Python StdLib Imports ---- 

2from dataclasses import dataclass, field 

3from typing import List, Literal, Optional, Tuple, Union 

4 

5 

6@dataclass 

7class WhitespaceChatacter: 

8 name: str 

9 unicode: str 

10 ascii: int 

11 chr: str = field(init=False) 

12 

13 def __post_init__(self) -> None: 

14 self.chr = chr(self.ascii) 

15 

16 def __getitem__( 

17 self, attribute: Literal["name", "unicode", "ascii", "chr"] 

18 ) -> Union[str, int]: 

19 return getattr(self, attribute) 

20 

21 

22@dataclass 

23class WhitespaceCharacters: 

24 characters: Union[ 

25 List[WhitespaceChatacter], 

26 Tuple[WhitespaceChatacter], 

27 ] 

28 

29 def __iter__(self): 

30 yield from self.characters 

31 

32 def to_list( 

33 self, 

34 attr: Optional[Literal["name", "unicode", "ascii", "chr"]] = None, 

35 ) -> List[Union[str, int, WhitespaceChatacter]]: 

36 return [char if attr is None else char[attr] for char in self]