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
3a7305ed
Commit
3a7305ed
authored
May 22, 2008
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix test_pydoc so it works on make installed Python installations
Also let it pass when invoked directly
parent
ca3939cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
14 deletions
+26
-14
Lib/test/test_pydoc.py
Lib/test/test_pydoc.py
+26
-14
No files found.
Lib/test/test_pydoc.py
View file @
3a7305ed
import
sys
import
os
import
difflib
import
subprocess
import
re
...
...
@@ -16,7 +17,7 @@ NAME
FILE
%s
%s
CLASSES
__builtin__.object
B
...
...
@@ -76,7 +77,7 @@ expected_html_pattern = \
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="test.html"><font color="#ffffff">test</font></a>.pydoc_mod</strong></big></big> (version 1.2.3.4)</font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:%s">%s</a></font></td></tr></table>
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:%s">%s</a>
%s
</font></td></tr></table>
<p><tt>This is a test module for test_pydoc</tt></p>
<p>
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
...
...
@@ -163,6 +164,7 @@ war</tt></dd></dl>
<td width="100%%">Nobody</td></tr></table>
"""
.
strip
()
# output pattern for missing module
missing_pattern
=
"no Python documentation found for '%s'"
...
...
@@ -177,17 +179,26 @@ def run_pydoc(module_name, *args):
def
get_pydoc_html
(
module
):
"Returns pydoc generated output as html"
output
=
pydoc
.
HTMLDoc
().
docmodule
(
module
)
return
output
.
strip
()
doc
=
pydoc
.
HTMLDoc
()
output
=
doc
.
docmodule
(
module
)
loc
=
doc
.
getdocloc
(
pydoc_mod
)
or
""
if
loc
:
loc
=
"<br><a href=
\
"
"
+
loc
+
"
\
"
>Module Docs</a>"
return
output
.
strip
(),
loc
def
get_pydoc_text
(
module
):
"Returns pydoc generated output as text"
output
=
pydoc
.
TextDoc
().
docmodule
(
module
)
doc
=
pydoc
.
TextDoc
()
loc
=
doc
.
getdocloc
(
pydoc_mod
)
or
""
if
loc
:
loc
=
"
\
n
MODULE DOCS
\
n
"
+
loc
+
"
\
n
"
output
=
doc
.
docmodule
(
module
)
# cleanup the extra text formatting that pydoc preforms
patt
=
re
.
compile
(
'
\
b
.'
)
output
=
patt
.
sub
(
''
,
output
)
return
output
.
strip
()
return
output
.
strip
()
,
loc
def
print_diffs
(
text1
,
text2
):
"Prints unified diffs for two texts"
...
...
@@ -201,16 +212,17 @@ def print_diffs(text1, text2):
class
PyDocDocTest
(
unittest
.
TestCase
):
def
test_html_doc
(
self
):
result
=
get_pydoc_html
(
pydoc_mod
)
result
,
doc_loc
=
get_pydoc_html
(
pydoc_mod
)
mod_file
=
inspect
.
getabsfile
(
pydoc_mod
)
expected_html
=
expected_html_pattern
%
(
mod_file
,
mod_file
)
expected_html
=
expected_html_pattern
%
(
mod_file
,
mod_file
,
doc_loc
)
if
result
!=
expected_html
:
print_diffs
(
expected_html
,
result
)
self
.
fail
(
"outputs are not equal, see diff above"
)
def
test_text_doc
(
self
):
result
=
get_pydoc_text
(
pydoc_mod
)
expected_text
=
expected_text_pattern
%
inspect
.
getabsfile
(
pydoc_mod
)
result
,
doc_loc
=
get_pydoc_text
(
pydoc_mod
)
expected_text
=
expected_text_pattern
%
\
(
inspect
.
getabsfile
(
pydoc_mod
),
doc_loc
)
if
result
!=
expected_text
:
print_diffs
(
expected_text
,
result
)
self
.
fail
(
"outputs are not equal, see diff above"
)
...
...
@@ -236,8 +248,8 @@ class TestDescriptions(unittest.TestCase):
c
=
C
()
self
.
assertEqual
(
pydoc
.
describe
(
C
),
'class C'
)
self
.
assertEqual
(
pydoc
.
describe
(
c
),
'instance of C'
)
self
.
assert_
(
'instance of C in module test.test_pydoc'
in
pydoc
.
render_doc
(
c
))
expected
=
'instance of C in module %s'
%
__name__
self
.
assert_
(
expected
in
pydoc
.
render_doc
(
c
))
def
test_class
(
self
):
class
C
(
object
):
"New-style class"
...
...
@@ -245,8 +257,8 @@ class TestDescriptions(unittest.TestCase):
self
.
assertEqual
(
pydoc
.
describe
(
C
),
'class C'
)
self
.
assertEqual
(
pydoc
.
describe
(
c
),
'C'
)
self
.
assert_
(
'C in module test.test_pydoc object'
in
pydoc
.
render_doc
(
c
))
expected
=
'C in module %s object'
%
__name__
self
.
assert_
(
expected
in
pydoc
.
render_doc
(
c
))
def
test_main
():
...
...
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