This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: doctest: allow custom matchers for testing if got==want
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: edloper Nosy List: edloper, loewis
Priority: normal Keywords: patch

Created on 2004-04-10 19:57 by edloper, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
doctest_matcher.diff edloper, 2004-04-10 19:57 Diff against doctest.py
Messages (4)
msg45738 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-10 19:57
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
msg45739 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-10 20:00
Logged In: YES 
user_id=195958

If this patch looks good, I'd be happy to write a patch for 
the docs & test cases.
msg45740 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-05-31 19:04
Logged In: YES 
user_id=21627

Please resubmit the patch using unified diffs. You might
just as well include test cases and documentation right away.
msg45741 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-10-02 15:22
Logged In: YES 
user_id=195958

The desired functionality was included in the new 
implementation of doctest.  In particular, the user can 
customize the comparison between want & got using doctest 
option directives; and using a custom OutputChecker object.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40138
2004-04-10 19:57:49edlopercreate