Utility function for the common case of checking a function with a sequence of input/output pairs. Parameters ---------- func : callable The function to be tested. Should accept a single argument. pairs : iterable A list of (input, expected_output) tuples. Retur
(func, pairs)
| 305 | "Got:\n" |
| 306 | " {3!r}\n") |
| 307 | def check_pairs(func, pairs): |
| 308 | """Utility function for the common case of checking a function with a |
| 309 | sequence of input/output pairs. |
| 310 | |
| 311 | Parameters |
| 312 | ---------- |
| 313 | func : callable |
| 314 | The function to be tested. Should accept a single argument. |
| 315 | pairs : iterable |
| 316 | A list of (input, expected_output) tuples. |
| 317 | |
| 318 | Returns |
| 319 | ------- |
| 320 | None. Raises an AssertionError if any output does not match the expected |
| 321 | value. |
| 322 | """ |
| 323 | name = getattr(func, "func_name", getattr(func, "__name__", "<unknown>")) |
| 324 | for inp, expected in pairs: |
| 325 | out = func(inp) |
| 326 | assert out == expected, pair_fail_msg.format(name, inp, expected, out) |
| 327 | |
| 328 | |
| 329 | MyStringIO = StringIO |