From 793f680e269d27fcfe70bd516816b38ddee5a80a Mon Sep 17 00:00:00 2001 From: github actions Date: Sun, 14 Apr 2024 20:35:14 +0000 Subject: [PATCH] d updated markdown snippets --- approvaltests/inline/parse.py | 6 ++++-- approvaltests/inline/parse2.py | 1 - approvaltests/inline/parse3.py | 6 +++++- approvaltests/inline/types.py | 2 +- tests/test_parse_inputs.py | 13 ++++++++----- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/approvaltests/inline/parse.py b/approvaltests/inline/parse.py index 9b017ac..140ed28 100644 --- a/approvaltests/inline/parse.py +++ b/approvaltests/inline/parse.py @@ -60,10 +60,12 @@ def transformer(s: str) -> Tuple[T1, T2]: # 'int1' is not used, let's start use it # add in callable # done: verify_all signature is incorrect - def transform3(self, transform1: Callable[[str], T1], transform2: Callable[[str], T2], int1) -> "Parse3[T1, int, int]": + def transform3( + self, transform1: Callable[[str], T1], transform2: Callable[[str], T2], int1 + ) -> "Parse3[T1, int, int]": def transformer(s: str) -> Tuple[T1, T2, int]: parts = s.split(",") parts = list(map(lambda p: p.strip(), parts)) return (transform1(parts[0]), transform2(parts[1]), int1(parts[2])) - + return Parse3(self.text, transformer, self.options) diff --git a/approvaltests/inline/parse2.py b/approvaltests/inline/parse2.py index 78b1cfc..9a1411b 100644 --- a/approvaltests/inline/parse2.py +++ b/approvaltests/inline/parse2.py @@ -12,7 +12,6 @@ def __init__( self._transformer = transformer self.options = options - def verify_all(self, transform: Callable[[T1, T2], Any]): from approvaltests.inline.parse import Parse diff --git a/approvaltests/inline/parse3.py b/approvaltests/inline/parse3.py index 1d63146..91e013f 100644 --- a/approvaltests/inline/parse3.py +++ b/approvaltests/inline/parse3.py @@ -3,6 +3,7 @@ from approvaltests import verify_all from approvaltests.inline.types import T1, T2, T3, NT1, NT2, NT3 + class Parse3(Generic[T1, T2, T3]): def __init__( self, text: str, transformer: Callable[[str], Tuple[T1, T2, T3]], options @@ -22,7 +23,10 @@ def verify_all(self, transform: Callable[[T1, T2, T3], Any]): ) def transform3( - self, transform1: Callable[[T1], NT1], transform2: Callable[[T2], NT2], transform3: Callable[[T3], NT3] + self, + transform1: Callable[[T1], NT1], + transform2: Callable[[T2], NT2], + transform3: Callable[[T3], NT3], ) -> "Parse3[NT1, NT2, NT3]": def transformer(s: str) -> Tuple[NT1, NT2, NT3]: t1, t2, t3 = self._transformer(s) diff --git a/approvaltests/inline/types.py b/approvaltests/inline/types.py index 392484c..c31d740 100644 --- a/approvaltests/inline/types.py +++ b/approvaltests/inline/types.py @@ -3,7 +3,7 @@ T = TypeVar("T") T1 = TypeVar("T1") T2 = TypeVar("T2") -T3 = TypeVar("T3") +T3 = TypeVar("T3") NT1 = TypeVar("NT1") NT2 = TypeVar("NT2") NT3 = TypeVar("NT3") diff --git a/tests/test_parse_inputs.py b/tests/test_parse_inputs.py index d5c952d..4ebba43 100644 --- a/tests/test_parse_inputs.py +++ b/tests/test_parse_inputs.py @@ -116,27 +116,30 @@ def test_with_two_parameters(): # end-snippet + # long-term intention: get the test to fail, randomSauce is incorrect def test_with_3_parameters(): """ a, 3, 1 -> aaaa """ - counter = 0 + def to(tin: type, tout: type): def wrapped(input): nonlocal counter counter += 1 assert type(input) is tin return tout(input) + return wrapped parse = Parse.doc_string(auto_approve=True) - parse.transform3( to(str, str), to(str, str), to(str, str))\ - .transform3( to(str, str), to(str, int), to(str, int))\ - .verify_all(lambda a, b, c: to(str, str)(a) * (to(int, int)(b) + to(int, int)(c))) - + parse.transform3(to(str, str), to(str, str), to(str, str)).transform3( + to(str, str), to(str, int), to(str, int) + ).verify_all(lambda a, b, c: to(str, str)(a) * (to(int, int)(b) + to(int, int)(c))) + assert counter == 9 + # assert on all the paramaters