Skip to content

Commit 6536694

Browse files
committed
add tests for format_methods
1 parent 820f480 commit 6536694

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

unpythonic/tests/test_dispatch.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import typing
77
from ..fun import curry
8-
from ..dispatch import generic, augment, typed
8+
from ..dispatch import generic, augment, typed, format_methods
99

1010
@generic
1111
def zorblify(x: int, y: int):
@@ -238,6 +238,23 @@ def instmeth(self, x: float):
238238
test[jack("foo") == "foo"]
239239
test_raises[TypeError, jack(3.14)] # jack only accepts int or str
240240

241+
with testset("list_methods"):
242+
def check_formatted_multimethods(result, expected):
243+
result_list = result.split("\n")
244+
human_readable_header, *multimethod_descriptions = result_list
245+
multimethod_descriptions = [x.strip() for x in multimethod_descriptions]
246+
test[the[len(multimethod_descriptions)] == the[len(expected)]]
247+
for r, e in zip(multimethod_descriptions, expected):
248+
test[the[r].startswith(the[e])]
249+
# @generic
250+
check_formatted_multimethods(format_methods(example2),
251+
["example2(start: int, step: int, stop: int)",
252+
"example2(start: int, stop: int)",
253+
"example2(stop: int)"])
254+
# @typed
255+
check_formatted_multimethods(format_methods(blubnify),
256+
["blubnify(x: int, y: float)"])
257+
241258
with testset("error cases"):
242259
with test_raises[TypeError, "@typed should only accept a single method"]:
243260
@typed

0 commit comments

Comments
 (0)