Skip to content

Commit 8f34e6c

Browse files
committed
fix: rerurn formatter
1 parent c0e3871 commit 8f34e6c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/assertionengine/formatter.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import re
2+
from abc import ABC, abstractmethod
3+
4+
5+
def _strip(value: str) -> str:
6+
return value.strip()
7+
8+
9+
def _normalize_spaces(value: str) -> str:
10+
return re.sub(r"\s+", " ", value)
11+
12+
13+
def _apply_to_expected(value: str) -> str:
14+
return value
15+
16+
17+
def _case_insensitive(value: str) -> str:
18+
return value.lower()
19+
20+
21+
FormatRules = {
22+
"normalize spaces": _normalize_spaces,
23+
"strip": _strip,
24+
"apply to expected": _apply_to_expected,
25+
"case insensitive": _case_insensitive,
26+
}
27+
28+
29+
class Formatter(ABC):
30+
@abstractmethod
31+
def get_formatter(self, keyword): ...
32+
33+
@abstractmethod
34+
def set_formatter(self, keyword, formatter): ...
35+
36+
def normalize_keyword(self, name: str):
37+
return name.lower().replace(" ", "_")
38+
39+
def formatters_to_method(self, kw_formatter: list) -> list:
40+
return [FormatRules[formatter.lower()] for formatter in kw_formatter]

0 commit comments

Comments
 (0)