Commit Graph

172 Commits

Author SHA1 Message Date
Tim Peters b7e99b642f SF patch 1167316: doctest.py fails self-test if run directly.
Patch by Ilya Sandler.

Bugfix candidate.
2005-03-28 23:50:54 +00:00
Fred Drake 7c404a4bf7 add __file__ to the globals available for tests loaded via DocFileSuite;
this is useful for locating supporting data files, just as it is in Python
modules
2004-12-21 23:46:34 +00:00
Tim Peters 7960bf9c00 And delete a useless comment. 2004-11-08 22:31:09 +00:00
Tim Peters d7bbbbc594 _OutputRedirectingPdb.trace_dispatch(): Return the base class's
trace_dispatch() result in a more obvious, and more robust way.
2004-11-08 22:30:28 +00:00
Tim Peters 50c6bdb1d6 test_doctest.py test_pdb_set_trace_nested(): A new test from Jim Fulton
showing that doctest's pdb.set_trace() support was dramatically broken.

doctest.py _OutputRedirectingPdb.trace_dispatch():  Return a local trace
function instead of (implicitly) None.  Else interaction with pdb was
bizarre, noticing only 'call' events.  Amazingly, the existing set_trace()
tests didn't care.
2004-11-08 22:07:37 +00:00
Jim Fulton 7d428788e1 Fixed a small bug. doctest didn't handle unicode docstrings containing
non-ascii characters.
2004-10-13 14:15:32 +00:00
Edward Loper 7d88a58e85 Reverted the addition of a NORMALIZE_NUMBERS option, per Tim Peter's
request.  Tim says that "correct 'fuzzy' comparison of floats cannot
be automated."  (The motivation behind adding the new option
was verifying interactive examples in Python's latex documentation;
several such examples use numbers that don't print consistently on
different platforms.)
2004-09-28 05:50:57 +00:00
Edward Loper aec3c9b54f Added a new NORMALIZE_NUMBERS option, which causes number literals in
the expected output to match corresponding number literals in the
actual output if their values are equal (to ten digits of precision).
2004-09-28 04:29:57 +00:00
Edward Loper 498a1868e7 - Added a "parser" option to testfile() and DocFileTest(). 2004-09-27 03:42:58 +00:00
Tim Peters 3afaaf2487 Removed debug_script from the public API: no docs, not public. I'm in
the process of writing docs for the other "missing" debug support
functions.
2004-09-26 03:50:06 +00:00
Tim Peters 9d02a7cfa0 Add set_unittest_reportflags() to the public API. Docs will follow
"soon", after I repair the LaTeX I somehow damaged.
2004-09-26 01:50:24 +00:00
Tim Peters 261b28aac6 Removed two undocumented unittest support classes, and one undocumented
unittest support function, from the public interface.  If they're not
documented, they shouldn't be public.
2004-09-26 01:24:23 +00:00
Tim Peters 48983fc484 Removed most of the module docstring. There's too much to explain now,
and the LaTeX docs are in increasingly good shape.
2004-09-25 02:41:28 +00:00
Edward Loper a2fc7ec80a - Minor docstring fixes.
- Simplified code to find names for file-based tests.
2004-09-21 03:24:24 +00:00
Tim Peters bab3e99689 Whitespace normalization. 2004-09-20 19:52:34 +00:00
Edward Loper 052d0cd291 - Added "testfile" function, a simple function for running & verifying
all examples in a given text file. (analagous to "testmod")
- Minor docstring fixes.
- Added module_relative parameter to DocTestFile/DocTestSuite, which
  controls whether paths are module-relative & os-independent, or
  os-specific.
2004-09-19 17:19:33 +00:00
Edward Loper 0273f5b6b2 In DocFileTest:
- Fixed bug in handling of absolute paths.
  - If run from an interactive session, make paths relative to the
    directory containing sys.argv[0] (since __main__ doesn't have
    a __file__ attribute).
2004-09-18 20:27:04 +00:00
Tim Peters 958cc89037 exclude_empty: make the default True for DocTestFinder, and introduce it
with default False for testmod().  The real point of introducing this was
so that output from doctest.master.summarize() would be the same as in
2.3, and doctest.master in 2.4 is a backward-compatability hack used only
by testmod().
2004-09-13 14:53:28 +00:00
Edward Loper 32ddbf7fab Added new parameter exclude_empty to DocTestFinder.__init__, which
controls whether tests are included for objects with empty docstrings.
Defaults to True, to match the behavior of Python 2.3.
2004-09-13 05:47:24 +00:00
Tim Peters c56847878e DocTestFinder._find(): for tests derived from a module __test__ global,
doctest always promised to stick "__test__" in the name.  That got
broken.  Now it's fixed again.
2004-09-13 01:07:12 +00:00
Tim Peters 82076ef194 Reluctantly, rehabilitate doctest.master. 2004-09-13 00:52:51 +00:00
Tim Peters 9661f9ab4f Tester.run___test__(): This couldn't possibly work at all. I'm afraid
the "backward compatibility" here was a joke.
2004-09-12 22:45:17 +00:00
Tim Peters 4be7a92f7f Tester.__init__(): this couldn't possibly work when a module argument
was passed.
2004-09-12 22:39:46 +00:00
Tim Peters 1fbf9c5ec1 Added IGNORE_EXCEPTION_DETAIL comparison option. The need is explained
in the new docs.

DocTestRunner.__run:  Separate the determination of the example outcome
from reporting that outcome, to squash brittle code duplication and
excessive nesting.
2004-09-04 17:21:02 +00:00
Tim Peters ba6019691e Added a couple names to __all__. 2004-09-04 15:04:06 +00:00
Tim Peters 38330fe5ef The distinction between comparison flags and reporting flags isn't unique
to unittest, so make it official:  new module constants COMPARISON_FLAGS
and REPORTING_FLAGS, which are bitmasks or'ing together the relevant
individual option flags.

set_unittest_reportflags():  Reworked to use REPORTING_FLAGS, and
simplified overly complicated flag logic.

class FakeModule:  Removed this; neither documented nor used.
2004-08-30 16:19:24 +00:00
Tim Peters df7a208ff7 Whitespace normalization. 2004-08-29 00:38:17 +00:00
Jim Fulton f54bad4564 - setUp and tearDown functions are now passed the test object
- Added a set_unittest_reportflags to set default reporting flags used
  when running doctests under unittest control.
2004-08-28 14:57:56 +00:00
Edward Loper 12a4baf5a1 Remove unused method _OutputRedirectingPdb.resume 2004-08-27 04:29:23 +00:00
Edward Loper 2de91ba2ab - Removed redundant call to expandtabs in DocTestParesr.
- Improvements to interactive debugging support:
  - Changed the replacement pdb.set_trace to redirect stdout to the
    real stdout *only* during interactive debugging; stdout from code
    continues to go to the fake stdout.
  - When the interactive debugger gets to the end of an example,
    automatically continue.
  - Use a replacement linecache.getlines that will return source lines
    from doctest examples; this makes the source available to the
    debugger for interactive debugging.
- In test_doctest, use a specialized _FakeOutput class instead of a
  temporary file to fake stdin for the interactive interpreter.
2004-08-27 02:07:46 +00:00
Edward Loper 00f8da77e7 - Added DocTestParser.parse(), which parses a docstring into Examples
and intervening text strings.
- Removed DocTestParser.get_program(): use script_from_examples()
  instead.
- Fixed bug in DocTestParser._INDENT_RE
- Fixed bug in DocTestParser._min_indent
- Moved _want_comment() to the utility function section
2004-08-26 18:05:07 +00:00
Tim Peters e7edcb8e22 output_difference(): In fancy-diff cases, the way this split expected &
actual output into lines created spurious empty lines at the ends of
each.  Those matched, but the fancy diffs had surprising line counts (1
larger than expected), and tests kept having to slam <BLANKLINE> into the
expected output to account for this.  Using the splitlines() string method
with keepends=True instead accomplishes what was intended directly.
2004-08-26 05:44:27 +00:00
Tim Peters 5b799c1f3d _do_a_fancy_diff(): Pay no attention to the ellipses behind the curtain.
While a fancy diff can be confusing in the presence of ellipses, so far
I'm finding (2-0-0) that it's much more a major aid in narrowing down the
possibilities when an ellipsis-slinging test fails.  So we no longer
refuse to do a fancy diff just because of ellipses.

This isn't ideal; it's just better.
2004-08-26 05:21:59 +00:00
Edward Loper ca9111eef3 Changed OutputChecker.output_difference to expect an Example object,
rather than an expected output string.  This gives the
output_difference method access to more information, such as the
indentation of the example, which might be useful.
2004-08-26 03:00:24 +00:00
Edward Loper a89f88d53f Added REPORT_ONLY_FIRST_FAILURE flag, which supresses output after the
first failing example in each test.
2004-08-26 02:45:51 +00:00
Edward Loper 71f55af826 Renamed UNIFIED_DIFF->REPORT_UDIFF; CONTEXT_DIFF->REPORT_CDIFF; and
NDIFF_DIFF->REPORT_NDIFF.  This establishes the naming convention that
all reporting options should begin with "REPORT_" (since reporting
options are a different class from output comparison options; but they
are both set in optionflags).
2004-08-26 01:41:51 +00:00
Edward Loper 5662929a42 Shortened diff output for unified & context diffs 2004-08-26 01:31:56 +00:00
Edward Loper aacf083388 - Changed the output of report_start() and report_unexpected_exception()
to be more consistent with report_failure()
- If `want` or `got` is empty, then print "Expected nothing\n" or
  "Got nothing\n" rather than "Expected:\n" or "Got:\n"
- Got rid of _tag_msg
2004-08-26 01:19:50 +00:00
Edward Loper a6b68327b2 Added an "exc_msg" attribute to Example (containing the expected
exception message, or None if no exception is expected); and moved
exception parsing from DocTestRunner to DocTestParser.  This is
architecturally cleaner, since it moves all parsing work to
DocTestParser; and it should make it easier for code outside
DocTestRunner (notably debugging code) to properly handle expected
exceptions.
2004-08-26 00:05:43 +00:00
Edward Loper 19b1958730 Only recognize the expected output as an exception if it *starts* with
a traceback message.  I.e., examples that raise exceptions may no
longer generate pre-exception output.  This restores the behavior of
doctest in python 2.3.  The ability to check pre-exception output is
being removed because it makes the documentation simpler; and because
there are very few use cases for it.
2004-08-25 23:07:03 +00:00
Tim Peters dd50cb748a The attempt to shut up deprecation warnings for doctest's own use of
is_private in its tests failed if doctest.py was run directly.  Now
it works.
2004-08-23 22:42:55 +00:00
Tim Peters a7def72a08 Moved some test cases from doctest to test_doctest. 2004-08-23 22:13:22 +00:00
Tim Peters 3fa8c2079a Misc cleanups. 2004-08-23 21:43:39 +00:00
Tim Peters b6a04d687d debug_script(): I changed this in haste before to take out the use of
NamedTemporaryFile (which can't work for this function's purposes on
Windows).  Leaving temp files behind wasn't a great idea either, though,
so try to clean up.  At least the test suite no longer leaves any of
these guys behind now.
2004-08-23 21:37:56 +00:00
Tim Peters f82a9ded39 Start deferring to the LaTeX docs for details. I'd like to move the
docstrings toward being a lot shorter, and telling the whole truth in
the manual instead.  This change is an example:  the manual has detailed
explanations of the option names now, so it's Bad to repeat them in
the docstring (two detailed descriptions are certain to get out of synch).
Just listing the names has memory-jogging benefits, though, so that's
still helpful in the docstring.
2004-08-22 20:51:53 +00:00
Tim Peters c6cbab0db4 Added NDIFF_DIFF option. 2004-08-22 19:43:28 +00:00
Tim Peters 75dc5e14ea Type in docstring. 2004-08-22 17:50:45 +00:00
Tim Peters c50491591d _parse_example(): Simplified new code to preserve trailing spaces before
final newline.  Anything to get rid of "l" as a variable name <0.5 wink>.
2004-08-22 17:34:58 +00:00
Jim Fulton 07a349c4ee Bugs fixed:
- Test filenames sometimes had trailing .pyc or .pyo sufixes
    (when module __file__ did).

  - Trailing spaces spaces in expected output were dropped.

New default failure format:

  - Separation of examples from file info makes examples easier to see

  - More vertical separation, improving readability

  - Emacs-recognized file info (also closer to Python exception format)
2004-08-22 14:10:00 +00:00
Tim Peters e594bee535 _ellipsis_match(): Removed special-casing of "...\n". The semantics
are non-obvious either way because the newline character "is invisible",
but it's still there all the same, and it's easier to explain/predict
if that reality is left alone.
2004-08-22 01:47:51 +00:00
Tim Peters b0a04e1592 Gave _ellipsis_match() an attractive new leading underscore. 2004-08-20 02:08:04 +00:00
Edward Loper 3a3817f506 Got rid of nooutput() (was used by DocTestCase.debug())
It's redundant, since no output is written anyway: DebugRunner doesn't
generate any output for failures and unexpected exceptions, and since
verbose=False, it won't generate any output for non-failures either.
2004-08-19 19:26:06 +00:00
Edward Loper b7503ff631 Updated __all__ to include every non-underscored class, function, and
constant defined by the module (except the test*() functions, which
should be integrated into test/test_doctest.py, anyway).
2004-08-19 19:19:03 +00:00
Tim Peters dc5de3bab2 ellipsis_match(): Changed treatment of start- and end-of-string exact
matches to be symmetric.  This makes the algorithm easier to understand.
2004-08-19 14:06:20 +00:00
Tim Peters 26b3ebb515 Replaced the ELLIPSIS implementation with a worst-case linear-time one. 2004-08-19 08:10:08 +00:00
Tim Peters 1cf3aa6e66 ELLIPSIS implementation: an ellipsis couldn't match nothing if it
appeared at the end of a line.  Repaired that.  Also noted that it's
too easy to provoke this implementation into requiring exponential
time, and especially when a test fails.  I'll replace the implementation
with an always-efficient one later.
2004-08-19 06:49:33 +00:00
Edward Loper b51b23405b Fixed bug in line-number finding for examples (DocTestParser wasn't
updating line numbers correctly for bare prompts & examples containing
only comments).
2004-08-17 16:37:12 +00:00
Tim Peters 41a65ea7fe Doctest has new traceback gimmicks in 2.4. While trying to document
them (which they are now), I had to rewrite the code to understand
it.  This has got to be the most DWIM part of doctest -- but in context
is really necessary.
2004-08-13 03:55:05 +00:00
Tim Peters 7ea48ddd4f Nit in _IS_BLANK_OR_COMMENT comment -- it doesn't matter how this is
implemented, just what it does.
2004-08-13 01:52:59 +00:00
Edward Loper 68ba9a685d In output_difference(), replace blank lines in `want` with <BLANKLINE>
(rather than replacing <BLANKLINE> with blank lines in `got`).  This
makes it easier to see what's intended.
2004-08-12 02:43:49 +00:00
Edward Loper a5db6009fe - Changed output of DocTestParser.get_program() to make it easier to
visually distinguish the expected output from the comments (use
  "##" to mark expected outputs, and "#" to mark comments).
- If the string given to DocTestParser.get_program() is indented, then
  strip its indentation.  (In particular, find the min indentation of
  non-blank lines, and strip that indentation from all lines.)
2004-08-12 02:41:30 +00:00
Edward Loper 8e4a34ba09 - Added __docformat__
- Added comments for some regexps
- If the traceback type/message don't match, then still print full
  traceback in report_failure (not just the first & last lines)
- Renamed DocTestRunner.__failure_header -> _failure_header
2004-08-12 02:34:27 +00:00
Edward Loper 74bca7aa44 - Changed option directives to be example-specific. (i.e., they now
modify option flags for a single example; they do not turn options
  on or off.)
- Added "indent" and "options" attributes for Example
- Got rid of add_newlines param to DocTestParser._parse_example (it's
  no longer needed; Example's constructor now takes care of it).
- Added some docstrings
2004-08-12 02:27:44 +00:00
Edward Loper ac20f57c28 - Added a register_optionflag function (so users can add their own
option flags); and use it to define the existing optionflag
  constants.
2004-08-12 02:02:24 +00:00
Tim Peters c2388a2b9c Start rewriting doctest's LaTeX docs. Damn, this is slow going! 2004-08-10 01:41:28 +00:00
Tim Peters 6c542b731c Edward's latest checkins somehow managed to wipe out my previous latest
checkins.  Reapplying the latter changes.
2004-08-09 16:43:36 +00:00
Edward Loper a1ef6110ba - DocTest is now a simple container class; its constructor is no longer
responsible for parsing the string.
- Renamed Parser to DocTestParser
- DocTestParser.get_*() now accept the string & name as command-line
  arguments; the parser's constructor is now empty.
- Added DocTestParser.get_doctest() method
- Replaced "doctest_factory" argument to DocTestFinder with a "parser"
  argument (takes a DocTestParser).
- Changed _tag_msg to take an indentation string argument.
2004-08-09 16:14:41 +00:00
Tim Peters 413ced6c22 This started as a spelling and whitespace cleanup. The comment for
the set_trace fiddling didn't make sense to me, and I ended up reworking
that part of the code.  We really do want to save and restore
pdb.set_trace, so that each dynamically nested level of doctest gets
sys.stdout fiddled to what's appropriate for *it*.  The only "trick"
really needed is that these layers of set_trace wrappers each call the
original pdb.set_trace (instead of the current pdb.set_trace).
2004-08-09 15:43:47 +00:00
Jim Fulton 356fd19c31 Added support for pdb.set_trace. 2004-08-09 11:34:47 +00:00
Tim Peters 80e53141b9 Removed lots of stuff from the module docstring. My intent for 2.4 is
to put details in the LaTeX docs instead, and lots of stuff in the
module docstring wasn't useful anyway.
2004-08-09 04:34:45 +00:00
Tim Peters 208ca7075f Repair some out-of-date comments. 2004-08-09 04:12:36 +00:00
Tim Peters bb43147312 Drop the excruciating newline requirements on arguments to
Example.__init__.  The constructor now adds trailing newlines when
needed, and no longer distinguishes between multi- and single-line
cases for source.
2004-08-09 03:51:46 +00:00
Tim Peters dd0e475297 Give return stmts their own lines. 2004-08-09 03:31:56 +00:00
Tim Peters d40a92b3f0 Indent body of _EXAMPLE_RE for readability. _IS_BLANK_OR_COMMENT makes
more sense as a callable.
2004-08-09 03:28:45 +00:00
Edward Loper 78b58f38f1 Changed Parser.get_examples() to return a list of Example objects,
rather than a list of triples.
2004-08-09 02:56:02 +00:00
Edward Loper 34fcb14768 - Split DocTestRunner's check_output and output_difference methods off
into their own class, OutputChecker.
- Added optional OutputChecker arguments to DocTestRunner,
  DocTestCase, DocTestSuite.
2004-08-09 02:45:41 +00:00
Edward Loper 7c748469c7 Rewrote Parser, using regular expressions instead of walking though
the string one line at a time.  The resulting code is (in my opinion,
anyway), much easier to read.  In the process, I found and fixed a
bug in the orginal parser's line numbering in error messages (it was
inconsistant between 0-based and 1-based).  Also, check for missing
blank lines after the prompt on all prompt lines, not just PS1 lines
(test added).
2004-08-09 02:06:06 +00:00
Tim Peters f3f57473ed Get rid of the ignore_imports argument to DocTestFinder.find().
This got slammed in when find() was fixed to stop grabbing doctests
from modules imported *by* the module being tested.  Such tests cannot
be expected to succeed, since they'll be run with the current module's
globals.  Dozens of Zope3 doctests were failing because of that.

It wasn't clear why ignore_imports got added then.  Maybe it's because
some existing tests failed when the change was made.  Whatever, it's
a Bad Idea so it's gone now.

The only use of it was exceedingly obscure, in test_doctest's "Duplicate
Removal" test.  It was "needed" there because, as an artifact of running
a doctest inside a doctest, the func_globals of functions compiled in
the second-level doctest don't match the module globals, and so the
test-finder believed these functions were from a foreign module and
skipped them.  But that took a long time to figure out, and I actually
understand some of this stuff <0.9 wink>.

That problem was resolved by moving the source code for the second-level
doctest into an actual module (test/doctest_aliases.py).

The only remaining difficulty was that the test for the deprecated
Tester.rundict() then failed, because the test finder doesn't take
module=None at face value, trying to guess which module the user really
intended then.  Its guess wasn't appropriate for what Tester.rundict
needs when module=None is given to *it*, which is "no, there is no
module here, and I mean it".  So now passing module=False means exactly
that.  This is hokey, but ignore_imports=False was really a hack to worm
around that there was no way to tell the test-finder that module=None
*sometimes* means what it says.  There was no use case for the combination
of passing a real module with ignore_imports=False.
2004-08-08 06:11:48 +00:00
Tim Peters 161c963276 Type in docstring. 2004-08-08 03:38:33 +00:00
Tim Peters 3ddd60a83b Also deprecated the old Tester class, which is no longer used by anything
except internal tests.
2004-08-08 02:43:33 +00:00
Tim Peters bafb1fed51 Deprecate the doctest.is_private() function. 2004-08-08 01:52:57 +00:00
Tim Peters f727c6c2c7 Deprecated testmod's useless & confusing isprivate gimmick.
Ripped out the docs for the new DocTestFinder's namefilter argument,
and renamed it to _namefilter; this only existed to support isprivate.
Removed the new DocTestFinder's objfilter argument.  No point adding
more cruft to a broken filtering design.
2004-08-08 01:48:59 +00:00
Tim Peters d1b7827216 Whitespace normalization. 2004-08-07 06:03:09 +00:00
Tim Peters 19397e5ec5 Merging from tim-doctest-branch, which is now closed.
This primarily adds more powerful ways to work with unittest, including
spiffy support for building suites out of doctests in non-Python
"text files".
2004-08-06 22:02:59 +00:00
Tim Peters 9b625d3037 Example.__init__: this cannot use assert, because that fails to trigger
in a -O run, and so test_doctest was failing under -O.  Simple cause,
simple cure.
2004-08-04 20:04:32 +00:00
Tim Peters 8485b56216 Edward Loper's cool and massive refactoring of doctest.py, merged from
the tim-doctest-merge-24a2 tag on the the tim-doctest-branch branch.
We did development on the branch in case it wouldn't land in time for
2.4a2, but the branch looked good:  Edward's tests passed there, ditto
Python's tests, and ditto the Zope3 tests.  Together, those hit doctest
heavily.
2004-08-04 18:46:34 +00:00
Jim Fulton a643b658a7 Ported some features from zope:
- Fixed the display of tests in verbose output
- Allow setUp and tearDown functions to be provided for DocTestSuites.
2004-07-14 19:06:50 +00:00
Tim Peters 4e0e1b6a54 Whitespace normalization. 2004-07-07 20:54:48 +00:00
Martin v. Löwis 92816de18e Patch #932930: suggest the use of rawstrings for backslashes. 2004-05-31 19:01:00 +00:00
Walter Dörwald 70a6b49821 Replace backticks with repr() or "%r"
From SF patch #852334.
2004-02-12 17:35:32 +00:00
Raymond Hettinger 7a70ea4135 SF patch #806246: use basestring where possible
(Contributed by George Yoshida.)
2003-09-17 05:50:59 +00:00
Raymond Hettinger 5f8b0b1fd4 SF 798269: bug fix for doctest (sf bug id: 798254
(Contributed by Alexander Belopolsky.)

Doctest would crash when encountering unbound methods:
  class A:
    def f(self): pass

  class C(A):
    g = A.f
2003-09-02 02:09:05 +00:00
Raymond Hettinger 71adf7e9d8 Doctest now examines all docstrings by default. Previously, it would
skip over functions with private names (as indicated by the underscore
naming convention).  The old default created too much of a risk that
user tests were being skipped inadvertently.  Note, this change could
break code in the unlikely case that someone had intentionally put
failing tests in the docstrings of private functions.  The breakage
is easily fixable by specifying the old behavior when calling testmod()
or Tester().  The more likely case is that the silent failure was
unintended and that the user needed to be informed so the test could be
fixed.
2003-07-16 19:25:22 +00:00
Raymond Hettinger cc39a13d6d Expose the 'master' instance mentioned in the docs. 2003-07-11 22:36:52 +00:00
Tim Peters db3756dade Some nifty doctest extensions from Jim Fulton, currently used in Zope3.
I won't have time to write real docs, but spent a lot of time adding
comments to his code and fleshing out the exported functions' docstrings.
There's probably opportunity to consolidate how docstrings get extracted
too, and the new code for that is probably better than the old code for
that (which strained mightily to recover from 2.2's new class/type
gimmicks).
2003-06-29 05:30:48 +00:00
Tim Peters 275abbd525 Missed a spot where the new optional optionflags argument needed to get
passed on.
2003-06-29 03:11:20 +00:00
Tim Peters 6ebe61fa80 A hack to ease compatibility with pre-2.3 Pythons: by default, doctest
now accepts "True" when a test expects "1", and similarly for "False"
versus "0".  This is un-doctest-like, but on balance makes it much
more pleasant to write doctests that pass under 2.2 and 2.3.  I expect
it to go away again, when 2.2 is forgotten.  In the meantime, there's
a new doctest module constant that can be passed to a new optional
argument, if you want to turn this behavior off.

Note that this substitution is very simple-minded:  the expected and
actual outputs have to consist of single tokens.  No attempt is made,
e.g., to accept [True, False] when a test expects [1, 0].  This is a
simple hack for simple tests, and I intend to keep it that way.
2003-06-27 20:48:05 +00:00
Martin v. Löwis 4581cfa326 Patch #486438: Make module argument to testmod optional. 2002-11-22 08:23:09 +00:00
Raymond Hettinger 54f0222547 SF 563203. Replaced 'has_key()' with 'in'. 2002-06-01 14:18:47 +00:00
Guido van Rossum 77f6a65eb0 Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285.  Everything described in the PEP is here, and there is even
some documentation.  I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison.  I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.

Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.
2002-04-03 22:41:51 +00:00