MCPcopy Create free account
hub / github.com/ipython/ipython / check_pairs

Function check_pairs

IPython/testing/tools.py:307–326  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

305 "Got:\n"
306 " {3!r}\n")
307def 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
329MyStringIO = StringIO

Callers

nothing calls this directly

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected