Issue 932935: doctest: allow custom matchers for testing if got==want (original) (raw)
To determine the success of a doctest example, doctest compares the actual output to the expected output. The test succeeds if the two match exactly.
This patch gives the user the ability to supply a custom "matcher" function, which will be used instead of string equality to test whether the test succeeds. This function should take two string parameters, "got" and "want", which will contain the actual and expected output, respectively; and it should return True if they should be considered to match (i.e., test succeeds), and False if they should not (i.e., test fails).
Two sample matcher functions are provided, as well:
match_ignoring_whitespace returns true if the actual output and expected output are equal, ignoring differences in amount of whitespace (eg 2 spaces vs 1).
match_ignoring_trailing_blanklines returns true if the actual output and expected output are equal, once any trailing blank lines are discarded. This can be useful with the END_WITH_DEDENT option, suggested in patch #932933 [1]
The patch was made avainst revision 1.33 of doctest.py.
[1] http://sourceforge.net/tracker/index.php? func=detail&aid=932933&group_id=5470&atid=3054 70