|
5 | 5 |
|
6 | 6 | import typing |
7 | 7 | from ..fun import curry |
8 | | -from ..dispatch import generic, augment, typed |
| 8 | +from ..dispatch import generic, augment, typed, format_methods |
9 | 9 |
|
10 | 10 | @generic |
11 | 11 | def zorblify(x: int, y: int): |
@@ -238,6 +238,23 @@ def instmeth(self, x: float): |
238 | 238 | test[jack("foo") == "foo"] |
239 | 239 | test_raises[TypeError, jack(3.14)] # jack only accepts int or str |
240 | 240 |
|
| 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 | + |
241 | 258 | with testset("error cases"): |
242 | 259 | with test_raises[TypeError, "@typed should only accept a single method"]: |
243 | 260 | @typed |
|
0 commit comments