Skip to content

Commit

Permalink
d updated markdown snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Apr 14, 2024
1 parent 5ce10a4 commit 793f680
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions approvaltests/inline/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion approvaltests/inline/parse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion approvaltests/inline/parse3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion approvaltests/inline/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
13 changes: 8 additions & 5 deletions tests/test_parse_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 793f680

Please sign in to comment.