##// END OF EJS Templates
Add testing function check_pairs to check input/output pairs against a function, and produce useful failure messages.
Thomas Kluyver -
Show More
@@ -281,3 +281,29 b' class TempFileMixin(object):'
281 281 # delete it. I have no clue why
282 282 pass
283 283
284 pair_fail_msg = ("Testing function {0}\n\n"
285 "In:\n"
286 " {1!r}\n"
287 "Expected:\n"
288 " {2!r}\n"
289 "Got:\n"
290 " {3!r}\n")
291 def check_pairs(func, pairs):
292 """Utility function for the common case of checking a function with a
293 sequence of input/output pairs.
294
295 Parameters
296 ----------
297 func : callable
298 The function to be tested. Should accept a single argument.
299 pairs : iterable
300 A list of (input, expected_output) tuples.
301
302 Returns
303 -------
304 None. Raises an AssertionError if any output does not match the expected
305 value.
306 """
307 for inp, expected in pairs:
308 out = func(inp)
309 assert out == expected, pair_fail_msg.format(func.func_name, inp, expected, out)
General Comments 0
You need to be logged in to leave comments. Login now