Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
78b58f38
Commit
78b58f38
authored
Aug 09, 2004
by
Edward Loper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed Parser.get_examples() to return a list of Example objects,
rather than a list of triples.
parent
34fcb147
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
21 deletions
+13
-21
Lib/doctest.py
Lib/doctest.py
+13
-21
No files found.
Lib/doctest.py
View file @
78b58f38
...
...
@@ -493,11 +493,12 @@ class Example:
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.
- source:
A single python statement, ending in a newline iff the
statement
spans more than one line.
- want: The expected output from running the source code. If
not empty, then this string ends with a newline.
- want: The expected output from running the source code (either
from stdout, or a traceback in case of exception). `want`
should always end with a newline, unless no output is expected,
- lineno: The line number within the DocTest string containing
this Example where the Example begins. This line number is
...
...
@@ -550,8 +551,7 @@ class DocTest:
self
.
lineno
=
lineno
# Parse the docstring.
self
.
docstring
=
docstring
examples
=
Parser
(
name
,
docstring
).
get_examples
()
self
.
examples
=
[
Example
(
*
example
)
for
example
in
examples
]
self
.
examples
=
Parser
(
name
,
docstring
).
get_examples
()
def
__repr__
(
self
):
if
len
(
self
.
examples
)
==
0
:
...
...
@@ -605,19 +605,11 @@ class Parser:
def
get_examples
(
self
):
"""
Return the doctest examples from the string.
This is a list of (source, want, lineno) triples, one per example
in the string. "source" is a single Python statement; it ends
with a newline iff the statement contains more than one
physical line. "want" is the expected output from running the
example (either from stdout, or a traceback in case of exception).
"want" always ends with a newline, unless no output is expected,
in which case "want" is an empty string. "lineno" is the 0-based
line number of the first line of "source" within the string. It's
0-based because it's most common in doctests that nothing
interesting appears on the same line as opening triple-quote,
and so the first interesting line is called "line 1" then.
Extract all doctest examples, from the string, and return them
as a list of `Example` objects. Line numbers are 0-based,
because it's most common in doctests that nothing interesting
appears on the same line as opening triple-quote, and so the
first interesting line is called
\
"
line 1
\
"
then.
>>> text = '''
... >>> x, y = 2, 3 # no output expected
...
...
@@ -632,7 +624,7 @@ class Parser:
... 5
... '''
>>> for x in Parser('<string>', text).get_examples():
... print
x
... print
(x.source, x.want, x.lineno)
('x, y = 2, 3 # no output expected', '', 1)
('if 1:
\
\
n print x
\
\
n print y
\
\
n', '2
\
\
n3
\
\
n', 2)
('x+y', '5
\
\
n', 9)
...
...
@@ -648,7 +640,7 @@ class Parser:
(
source
,
want
)
=
self
.
_parse_example
(
m
,
lineno
)
if
self
.
_IS_BLANK_OR_COMMENT
.
match
(
source
):
continue
examples
.
append
(
(
source
,
want
,
lineno
)
)
examples
.
append
(
Example
(
source
,
want
,
lineno
)
)
# Update lineno (lines inside this example)
lineno
+=
self
.
string
.
count
(
'
\
n
'
,
m
.
start
(),
m
.
end
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment