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
94030712
Commit
94030712
authored
Oct 06, 2011
by
Ned Deily
Browse files
Options
Browse Files
Download
Plain Diff
merge from 3.2
parents
17a332ac
ed27df7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
45 deletions
+75
-45
Lib/pkgutil.py
Lib/pkgutil.py
+11
-3
Lib/test/test_pkgutil.py
Lib/test/test_pkgutil.py
+11
-0
Lib/test/test_pydoc.py
Lib/test/test_pydoc.py
+53
-42
No files found.
Lib/pkgutil.py
View file @
94030712
...
@@ -191,8 +191,11 @@ class ImpImporter:
...
@@ -191,8 +191,11 @@ class ImpImporter:
yielded
=
{}
yielded
=
{}
import
inspect
import
inspect
try
:
filenames
=
os
.
listdir
(
self
.
path
)
filenames
=
os
.
listdir
(
self
.
path
)
except
OSError
:
# ignore unreadable directories like import does
filenames
=
[]
filenames
.
sort
()
# handle packages before same-named modules
filenames
.
sort
()
# handle packages before same-named modules
for
fn
in
filenames
:
for
fn
in
filenames
:
...
@@ -205,7 +208,12 @@ class ImpImporter:
...
@@ -205,7 +208,12 @@ class ImpImporter:
if
not
modname
and
os
.
path
.
isdir
(
path
)
and
'.'
not
in
fn
:
if
not
modname
and
os
.
path
.
isdir
(
path
)
and
'.'
not
in
fn
:
modname
=
fn
modname
=
fn
for
fn
in
os
.
listdir
(
path
):
try
:
dircontents
=
os
.
listdir
(
path
)
except
OSError
:
# ignore unreadable directories like import does
dircontents
=
[]
for
fn
in
dircontents
:
subname
=
inspect
.
getmodulename
(
fn
)
subname
=
inspect
.
getmodulename
(
fn
)
if
subname
==
'__init__'
:
if
subname
==
'__init__'
:
ispkg
=
True
ispkg
=
True
...
...
Lib/test/test_pkgutil.py
View file @
94030712
...
@@ -84,6 +84,17 @@ class PkgutilTests(unittest.TestCase):
...
@@ -84,6 +84,17 @@ class PkgutilTests(unittest.TestCase):
del
sys
.
modules
[
pkg
]
del
sys
.
modules
[
pkg
]
def
test_unreadable_dir_on_syspath
(
self
):
# issue7367 - walk_packages failed if unreadable dir on sys.path
package_name
=
"unreadable_package"
d
=
os
.
path
.
join
(
self
.
dirname
,
package_name
)
# this does not appear to create an unreadable dir on Windows
# but the test should not fail anyway
os
.
mkdir
(
d
,
0
)
for
t
in
pkgutil
.
walk_packages
(
path
=
[
self
.
dirname
]):
self
.
fail
(
"unexpected package found"
)
os
.
rmdir
(
d
)
class
PkgutilPEP302Tests
(
unittest
.
TestCase
):
class
PkgutilPEP302Tests
(
unittest
.
TestCase
):
class
MyTestLoader
(
object
):
class
MyTestLoader
(
object
):
...
...
Lib/test/test_pydoc.py
View file @
94030712
...
@@ -7,7 +7,6 @@ import pydoc
...
@@ -7,7 +7,6 @@ import pydoc
import
keyword
import
keyword
import
re
import
re
import
string
import
string
import
subprocess
import
test.support
import
test.support
import
time
import
time
import
unittest
import
unittest
...
@@ -15,11 +14,9 @@ import xml.etree
...
@@ -15,11 +14,9 @@ import xml.etree
import
textwrap
import
textwrap
from
io
import
StringIO
from
io
import
StringIO
from
collections
import
namedtuple
from
collections
import
namedtuple
from
contextlib
import
contextmanager
from
test.script_helper
import
assert_python_ok
from
test.script_helper
import
assert_python_ok
from
test.support
import
(
from
test.support
import
(
TESTFN
,
forget
,
rmtree
,
EnvironmentVarGuard
,
TESTFN
,
rmtree
,
reap_children
,
reap_threads
,
captured_output
,
captured_stdout
,
unlink
reap_children
,
reap_threads
,
captured_output
,
captured_stdout
,
unlink
)
)
from
test
import
pydoc_mod
from
test
import
pydoc_mod
...
@@ -209,7 +206,8 @@ def run_pydoc(module_name, *args, **env):
...
@@ -209,7 +206,8 @@ def run_pydoc(module_name, *args, **env):
output of pydoc.
output of pydoc.
"""
"""
args
=
args
+
(
module_name
,)
args
=
args
+
(
module_name
,)
rc
,
out
,
err
=
assert_python_ok
(
pydoc
.
__file__
,
*
args
,
**
env
)
# do not write bytecode files to avoid caching errors
rc
,
out
,
err
=
assert_python_ok
(
'-B'
,
pydoc
.
__file__
,
*
args
,
**
env
)
return
out
.
strip
()
return
out
.
strip
()
def
get_pydoc_html
(
module
):
def
get_pydoc_html
(
module
):
...
@@ -295,43 +293,6 @@ class PydocDocTest(unittest.TestCase):
...
@@ -295,43 +293,6 @@ class PydocDocTest(unittest.TestCase):
self
.
assertEqual
(
expected
,
result
,
self
.
assertEqual
(
expected
,
result
,
"documentation for missing module found"
)
"documentation for missing module found"
)
def
test_badimport
(
self
):
# This tests the fix for issue 5230, where if pydoc found the module
# but the module had an internal import error pydoc would report no doc
# found.
modname
=
'testmod_xyzzy'
testpairs
=
(
(
'i_am_not_here'
,
'i_am_not_here'
),
(
'test.i_am_not_here_either'
,
'i_am_not_here_either'
),
(
'test.i_am_not_here.neither_am_i'
,
'i_am_not_here.neither_am_i'
),
(
'i_am_not_here.{}'
.
format
(
modname
),
'i_am_not_here.{}'
.
format
(
modname
)),
(
'test.{}'
.
format
(
modname
),
modname
),
)
@
contextmanager
def
newdirinpath
(
dir
):
os
.
mkdir
(
dir
)
sys
.
path
.
insert
(
0
,
dir
)
try
:
yield
finally
:
sys
.
path
.
pop
(
0
)
rmtree
(
dir
)
with
newdirinpath
(
TESTFN
):
fullmodname
=
os
.
path
.
join
(
TESTFN
,
modname
)
sourcefn
=
fullmodname
+
os
.
extsep
+
"py"
for
importstring
,
expectedinmsg
in
testpairs
:
with
open
(
sourcefn
,
'w'
)
as
f
:
f
.
write
(
"import {}
\
n
"
.
format
(
importstring
))
try
:
result
=
run_pydoc
(
modname
,
PYTHONPATH
=
TESTFN
).
decode
(
"ascii"
)
finally
:
forget
(
modname
)
expected
=
badimport_pattern
%
(
modname
,
expectedinmsg
)
self
.
assertEqual
(
expected
,
result
)
def
test_input_strip
(
self
):
def
test_input_strip
(
self
):
missing_module
=
" test.i_am_not_here "
missing_module
=
" test.i_am_not_here "
result
=
str
(
run_pydoc
(
missing_module
),
'ascii'
)
result
=
str
(
run_pydoc
(
missing_module
),
'ascii'
)
...
@@ -409,6 +370,55 @@ class PydocDocTest(unittest.TestCase):
...
@@ -409,6 +370,55 @@ class PydocDocTest(unittest.TestCase):
self
.
assertEqual
(
synopsis
,
'line 1: h
\
xe9
'
)
self
.
assertEqual
(
synopsis
,
'line 1: h
\
xe9
'
)
class
PydocImportTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
test_dir
=
os
.
mkdir
(
TESTFN
)
self
.
addCleanup
(
rmtree
,
TESTFN
)
def
test_badimport
(
self
):
# This tests the fix for issue 5230, where if pydoc found the module
# but the module had an internal import error pydoc would report no doc
# found.
modname
=
'testmod_xyzzy'
testpairs
=
(
(
'i_am_not_here'
,
'i_am_not_here'
),
(
'test.i_am_not_here_either'
,
'i_am_not_here_either'
),
(
'test.i_am_not_here.neither_am_i'
,
'i_am_not_here.neither_am_i'
),
(
'i_am_not_here.{}'
.
format
(
modname
),
'i_am_not_here.{}'
.
format
(
modname
)),
(
'test.{}'
.
format
(
modname
),
modname
),
)
sourcefn
=
os
.
path
.
join
(
TESTFN
,
modname
)
+
os
.
extsep
+
"py"
for
importstring
,
expectedinmsg
in
testpairs
:
with
open
(
sourcefn
,
'w'
)
as
f
:
f
.
write
(
"import {}
\
n
"
.
format
(
importstring
))
result
=
run_pydoc
(
modname
,
PYTHONPATH
=
TESTFN
).
decode
(
"ascii"
)
expected
=
badimport_pattern
%
(
modname
,
expectedinmsg
)
self
.
assertEqual
(
expected
,
result
)
def
test_apropos_with_bad_package
(
self
):
# Issue 7425 - pydoc -k failed when bad package on path
pkgdir
=
os
.
path
.
join
(
TESTFN
,
"syntaxerr"
)
os
.
mkdir
(
pkgdir
)
badsyntax
=
os
.
path
.
join
(
pkgdir
,
"__init__"
)
+
os
.
extsep
+
"py"
with
open
(
badsyntax
,
'w'
)
as
f
:
f
.
write
(
"invalid python syntax = $1
\
n
"
)
result
=
run_pydoc
(
'nothing'
,
'-k'
,
PYTHONPATH
=
TESTFN
)
self
.
assertEqual
(
b''
,
result
)
def
test_apropos_with_unreadable_dir
(
self
):
# Issue 7367 - pydoc -k failed when unreadable dir on path
self
.
unreadable_dir
=
os
.
path
.
join
(
TESTFN
,
"unreadable"
)
os
.
mkdir
(
self
.
unreadable_dir
,
0
)
self
.
addCleanup
(
os
.
rmdir
,
self
.
unreadable_dir
)
# Note, on Windows the directory appears to be still
# readable so this is not really testing the issue there
result
=
run_pydoc
(
'nothing'
,
'-k'
,
PYTHONPATH
=
TESTFN
)
self
.
assertEqual
(
b''
,
result
)
class
TestDescriptions
(
unittest
.
TestCase
):
class
TestDescriptions
(
unittest
.
TestCase
):
def
test_module
(
self
):
def
test_module
(
self
):
...
@@ -517,6 +527,7 @@ class TestHelper(unittest.TestCase):
...
@@ -517,6 +527,7 @@ class TestHelper(unittest.TestCase):
def
test_main
():
def
test_main
():
try
:
try
:
test
.
support
.
run_unittest
(
PydocDocTest
,
test
.
support
.
run_unittest
(
PydocDocTest
,
PydocImportTest
,
TestDescriptions
,
TestDescriptions
,
PydocServerTest
,
PydocServerTest
,
PydocUrlHandlerTest
,
PydocUrlHandlerTest
,
...
...
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