[Python-checkins] python/dist/src/Lib doctest.py,1.36.2.1,1.36.2.2
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Tue Aug 3 05:38:02 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2145/Lib
Modified Files:
Tag: tim-doctest-branch
doctest.py
Log Message:
Update attributions; whitespace normalization.
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.36.2.1
retrieving revision 1.36.2.2
diff -C2 -d -r1.36.2.1 -r1.36.2.2
*** doctest.py 2 Aug 2004 22:07:11 -0000 1.36.2.1
--- doctest.py 3 Aug 2004 03:37:59 -0000 1.36.2.2
***************
*** 1,5 ****
# Module doctest.
! # Released to the public domain 16-Jan-2001,
! # by Tim Peters (tim.one at home.com).
# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
--- 1,7 ----
# Module doctest.
! # Released to the public domain 16-Jan-2001, by Tim Peters (tim at python.org).
! # Significant enhancements by:
! # Jim Fulton
! # Edward Loper
# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
***************
*** 403,407 ****
# What string should we use to indent contents?
INDENT = ' '
!
# If the message doesn't end in a newline, then add one.
if msg[-1:] != '\n':
--- 405,409 ----
# What string should we use to indent contents?
INDENT = ' '
!
# If the message doesn't end in a newline, then add one.
if msg[-1:] != '\n':
***************
*** 435,445 ****
A single doctest example, consisting of source code and expected
output. Example defines the following attributes:
!
- source: The source code that should be run. It ends with a
newline iff the source spans more than one line.
!
- want: The expected output from running the source code. If
not empty, then this string ends with a newline.
!
- lineno: The line number within the DocTest string containing
this Example where the Example begins. This line number is
--- 437,447 ----
A single doctest example, consisting of source code and expected
output. Example defines the following attributes:
!
- source: The source code that should be run. It ends with a
newline iff the source spans more than one line.
!
- want: The expected output from running the source code. If
not empty, then this string ends with a newline.
!
- lineno: The line number within the DocTest string containing
this Example where the Example begins. This line number is
***************
*** 459,471 ****
A collection of doctest examples that should be run in a single
namespace. Each DocTest defines the following attributes:
!
- examples: the list of examples.
!
- name: A name identifying the DocTest (typically, the name of
the object whose docstring this DocTest was extracted from).
!
- filename: The name of the file that this DocTest was extracted
from.
!
- lineno: The line number within filename where this DocTest
begins. This line number is zero-based, with respect to the
--- 461,473 ----
A collection of doctest examples that should be run in a single
namespace. Each DocTest defines the following attributes:
!
- examples: the list of examples.
!
- name: A name identifying the DocTest (typically, the name of
the object whose docstring this DocTest was extracted from).
!
- filename: The name of the file that this DocTest was extracted
from.
!
- lineno: The line number within filename where this DocTest
begins. This line number is zero-based, with respect to the
***************
*** 513,517 ****
'blanks after %s: %r' %
(lineno, self.name, self._PS1, line))
!
j = j + 1
blanks = m.group(1)
--- 515,519 ----
'blanks after %s: %r' %
(lineno, self.name, self._PS1, line))
!
j = j + 1
blanks = m.group(1)
***************
*** 556,560 ****
examples.append(Example(source, want, lineno))
return examples
!
def __repr__(self):
if len(self.examples) == 0:
--- 558,562 ----
examples.append(Example(source, want, lineno))
return examples
!
def __repr__(self):
if len(self.examples) == 0:
***************
*** 566,570 ****
return ('<DocTest %s from %s:%s (%s)>' %
(self.name, self.filename, self.lineno, examples))
!
# This lets us sort tests by name:
--- 568,572 ----
return ('<DocTest %s from %s:%s (%s)>' %
(self.name, self.filename, self.lineno, examples))
!
# This lets us sort tests by name:
***************
*** 573,583 ****
return cmp((self.name, self.filename, self.lineno, id(self)),
(other.name, other.filename, other.lineno, id(other)))
!
######################################################################
## 3. DocTest Finder
######################################################################
!
class DocTestFinder:
! """
A class used to extract the DocTests that are relevant to a given
object, from its docstring and the docstrings of its contained
--- 575,585 ----
return cmp((self.name, self.filename, self.lineno, id(self)),
(other.name, other.filename, other.lineno, id(other)))
!
######################################################################
## 3. DocTest Finder
######################################################################
!
class DocTestFinder:
! """
A class used to extract the DocTests that are relevant to a given
object, from its docstring and the docstrings of its contained
***************
*** 599,603 ****
`__test__` dictionary. By default, no objects are ignored.
"""
!
def __init__(self, verbose=False, namefilter=None, objfilter=None,
recurse=True):
--- 601,605 ----
`__test__` dictionary. By default, no objects are ignored.
"""
!
def __init__(self, verbose=False, namefilter=None, objfilter=None,
recurse=True):
***************
*** 612,616 ****
self._objfilter = objfilter
self._recurse = recurse
!
def find(self, obj, name=None, module=None):
"""
--- 614,618 ----
self._objfilter = objfilter
self._recurse = recurse
!
def find(self, obj, name=None, module=None):
"""
***************
*** 644,648 ****
if module == '(None)':
module = None
!
# Read the module's source code. This is used by
# DocTestFinder._find_lineno to find the line number for a
--- 646,650 ----
if module == '(None)':
module = None
!
# Read the module's source code. This is used by
# DocTestFinder._find_lineno to find the line number for a
***************
*** 697,701 ****
if id(obj) in seen: return
seen[id(obj)] = 1
!
# Find a test for this object, and add it to the list of tests.
test = self._get_test(obj, name, module, source_lines)
--- 699,703 ----
if id(obj) in seen: return
seen[id(obj)] = 1
!
# Find a test for this object, and add it to the list of tests.
test = self._get_test(obj, name, module, source_lines)
***************
*** 731,735 ****
valname = '%s.%s' % (name, valname)
self._find(tests, val, valname, module, source_lines, seen)
!
# Look for tests in a class's contained objects.
if inspect.isclass(obj) and self._recurse:
--- 733,737 ----
valname = '%s.%s' % (name, valname)
self._find(tests, val, valname, module, source_lines, seen)
!
# Look for tests in a class's contained objects.
if inspect.isclass(obj) and self._recurse:
***************
*** 790,794 ****
if inspect.ismodule(obj):
lineno = 0
!
# Find the line number for classes.
# Note: this could be fooled if a class is defined multiple
--- 792,796 ----
if inspect.ismodule(obj):
lineno = 0
!
# Find the line number for classes.
# Note: this could be fooled if a class is defined multiple
***************
*** 825,829 ****
# We couldn't find the line number.
return None
!
######################################################################
## 4. DocTest Runner
--- 827,831 ----
# We couldn't find the line number.
return None
!
######################################################################
## 4. DocTest Runner
***************
*** 852,856 ****
have been run by the runner, and returns an aggregated `(f, t)`
tuple:
!
>>> runner.summarize(verbose=1)
4 items passed all tests:
--- 854,858 ----
have been run by the runner, and returns an aggregated `(f, t)`
tuple:
!
>>> runner.summarize(verbose=1)
4 items passed all tests:
***************
*** 935,942 ****
information about option flags.
"""
! # Handle the common case first, for efficiency:
# if they're string-identical, always return true.
if got == want: return True
!
# The values True and False replaced 1 and 0 as the return
# value for boolean comparisons in Python 2.3.
--- 937,944 ----
information about option flags.
"""
! # Handle the common case first, for efficiency:
# if they're string-identical, always return true.
if got == want: return True
!
# The values True and False replaced 1 and 0 as the return
# value for boolean comparisons in Python 2.3.
***************
*** 951,955 ****
'', want)
if got == want: return True
!
# This flag causes doctest to ignore any differences in the
# contents of whitespace strings. Note that this can be used
--- 953,957 ----
'', want)
if got == want: return True
!
# This flag causes doctest to ignore any differences in the
# contents of whitespace strings. Note that this can be used
***************
*** 959,963 ****
want = ' '.join(want.split())
if got == want: return True
!
# The ELLIPSIS flag says to let the sequence "..." in `want`
# match any substring in `got`. We implement this by
--- 961,965 ----
want = ' '.join(want.split())
if got == want: return True
!
# The ELLIPSIS flag says to let the sequence "..." in `want`
# match any substring in `got`. We implement this by
***************
*** 973,977 ****
# Check if the `want_re` regexp matches got.
if re.match(want_re, got): return True
!
# We didn't find any match; return false.
return False
--- 975,979 ----
# Check if the `want_re` regexp matches got.
if re.match(want_re, got): return True
!
# We didn't find any match; return false.
return False
***************
*** 981,985 ****
Return a string describing the differences between the
expected output (`want`) and the actual output (`got`).
! """
# Check if we should use diff. Don't use diff if the actual
# or expected outputs are too short, or if the expected output
--- 983,987 ----
Return a string describing the differences between the
expected output (`want`) and the actual output (`got`).
! """
# Check if we should use diff. Don't use diff if the actual
# or expected outputs are too short, or if the expected output
***************
*** 1057,1061 ****
def __failure_header(self, test, example):
! s = (self.DIVIDER + "\n" +
_tag_msg("Failure in example", example.source))
if test.filename is None:
--- 1059,1063 ----
def __failure_header(self, test, example):
! s = (self.DIVIDER + "\n" +
_tag_msg("Failure in example", example.source))
if test.filename is None:
***************
*** 1120,1124 ****
# Extract the example's actual output from fakeout, and
# write it to `got`. Add a terminating newline if it
! # doesn't have already one.
got = self._fakeout.getvalue()
self._fakeout.truncate(0)
--- 1122,1126 ----
# Extract the example's actual output from fakeout, and
# write it to `got`. Add a terminating newline if it
! # doesn't have already one.
got = self._fakeout.getvalue()
self._fakeout.truncate(0)
***************
*** 1361,1365 ****
using a context diff.
"""
!
""" [XX] This is no longer true:
Advanced tomfoolery: testmod runs methods of a local instance of
--- 1363,1367 ----
using a context diff.
"""
!
""" [XX] This is no longer true:
Advanced tomfoolery: testmod runs methods of a local instance of
***************
*** 1385,1389 ****
if name is None:
name = m.__name__
!
# If globals were not specified, then default to the module.
if globs is None:
--- 1387,1391 ----
if name is None:
name = m.__name__
!
# If globals were not specified, then default to the module.
if globs is None:
***************
*** 1470,1474 ****
if module is None: module = '(None)'
return self.rundoc(m, name, module)
!
def run__test__(self, d, name):
import new
--- 1472,1476 ----
if module is None: module = '(None)'
return self.rundoc(m, name, module)
!
def run__test__(self, d, name):
import new
***************
*** 1572,1576 ****
if module is not None and filename is not None:
raise ValueError('Specify module or filename, not both.')
!
if test_finder is None:
test_finder = DocTestFinder()
--- 1574,1578 ----
if module is not None and filename is not None:
raise ValueError('Specify module or filename, not both.')
!
if test_finder is None:
test_finder = DocTestFinder()
***************
*** 1602,1606 ****
filename = filename[:-1]
test.filename = filename
! suite.addTest(DocTestTestCase(test_runner, test, globs,
extraglobs, setUp, tearDown))
--- 1604,1608 ----
filename = filename[:-1]
test.filename = filename
! suite.addTest(DocTestTestCase(test_runner, test, globs,
extraglobs, setUp, tearDown))
***************
*** 1779,1783 ****
# """,
# "whitespace normalization": r"""
! # If the whitespace normalization flag is used, then
# differences in whitespace are ignored.
# >>> print range(30)
--- 1781,1785 ----
# """,
# "whitespace normalization": r"""
! # If the whitespace normalization flag is used, then
# differences in whitespace are ignored.
# >>> print range(30)
***************
*** 1910,1914 ****
Traceback (most recent call last):
[...]
! ValueError:
foo
--- 1912,1916 ----
Traceback (most recent call last):
[...]
! ValueError:
foo
***************
*** 1924,1928 ****
r.run(DocTestSuite())#optionflags=ELLIPSIS | NORMALIZE_WHITESPACE |
# UNIFIED_DIFF))
!
if __name__ == "__main__":
_test()
--- 1926,1930 ----
r.run(DocTestSuite())#optionflags=ELLIPSIS | NORMALIZE_WHITESPACE |
# UNIFIED_DIFF))
!
if __name__ == "__main__":
_test()
More information about the Python-checkins
mailing list