Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c52d113e
Kaydet (Commit)
c52d113e
authored
May 19, 2013
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #11995: test_pydoc doesn't import all sys.path modules anymore.
üst
87aa7dc2
916fc7bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
16 deletions
+63
-16
test_pydoc.py
Lib/test/test_pydoc.py
+58
-15
NEWS
Misc/NEWS
+5
-1
No files found.
Lib/test/test_pydoc.py
Dosyayı görüntüle @
c52d113e
import
os
import
sys
import
builtins
import
contextlib
import
difflib
import
inspect
import
pydoc
import
keyword
import
pkgutil
import
re
import
string
import
test.support
...
...
@@ -17,7 +19,8 @@ from collections import namedtuple
from
test.script_helper
import
assert_python_ok
from
test.support
import
(
TESTFN
,
rmtree
,
reap_children
,
reap_threads
,
captured_output
,
captured_stdout
,
unlink
reap_children
,
reap_threads
,
captured_output
,
captured_stdout
,
captured_stderr
,
unlink
)
from
test
import
pydoc_mod
...
...
@@ -255,6 +258,29 @@ def get_html_title(text):
return
title
class
PydocBaseTest
(
unittest
.
TestCase
):
def
_restricted_walk_packages
(
self
,
walk_packages
,
path
=
None
):
"""
A version of pkgutil.walk_packages() that will restrict itself to
a given path.
"""
default_path
=
path
or
[
os
.
path
.
dirname
(
__file__
)]
def
wrapper
(
path
=
None
,
prefix
=
''
,
onerror
=
None
):
return
walk_packages
(
path
or
default_path
,
prefix
,
onerror
)
return
wrapper
@contextlib.contextmanager
def
restrict_walk_packages
(
self
,
path
=
None
):
walk_packages
=
pkgutil
.
walk_packages
pkgutil
.
walk_packages
=
self
.
_restricted_walk_packages
(
walk_packages
,
path
)
try
:
yield
finally
:
pkgutil
.
walk_packages
=
walk_packages
class
PydocDocTest
(
unittest
.
TestCase
):
@unittest.skipIf
(
sys
.
flags
.
optimize
>=
2
,
...
...
@@ -441,7 +467,7 @@ class PydocDocTest(unittest.TestCase):
self
.
assertDictEqual
(
methods
,
expected
)
class
PydocImportTest
(
unittest
.
TestCase
):
class
PydocImportTest
(
PydocBaseTest
):
def
setUp
(
self
):
self
.
test_dir
=
os
.
mkdir
(
TESTFN
)
...
...
@@ -475,8 +501,19 @@ class PydocImportTest(unittest.TestCase):
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
(
'zqwykjv'
,
'-k'
,
PYTHONPATH
=
TESTFN
)
self
.
assertEqual
(
b
''
,
result
)
with
self
.
restrict_walk_packages
(
path
=
[
TESTFN
]):
with
captured_stdout
()
as
out
:
with
captured_stderr
()
as
err
:
pydoc
.
apropos
(
'xyzzy'
)
# No result, no error
self
.
assertEqual
(
out
.
getvalue
(),
''
)
self
.
assertEqual
(
err
.
getvalue
(),
''
)
# The package name is still matched
with
captured_stdout
()
as
out
:
with
captured_stderr
()
as
err
:
pydoc
.
apropos
(
'syntaxerr'
)
self
.
assertEqual
(
out
.
getvalue
()
.
strip
(),
'syntaxerr'
)
self
.
assertEqual
(
err
.
getvalue
(),
''
)
def
test_apropos_with_unreadable_dir
(
self
):
# Issue 7367 - pydoc -k failed when unreadable dir on path
...
...
@@ -485,8 +522,13 @@ class PydocImportTest(unittest.TestCase):
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
(
'zqwykjv'
,
'-k'
,
PYTHONPATH
=
TESTFN
)
self
.
assertEqual
(
b
''
,
result
)
with
self
.
restrict_walk_packages
(
path
=
[
TESTFN
]):
with
captured_stdout
()
as
out
:
with
captured_stderr
()
as
err
:
pydoc
.
apropos
(
'SOMEKEY'
)
# No result, no error
self
.
assertEqual
(
out
.
getvalue
(),
''
)
self
.
assertEqual
(
err
.
getvalue
(),
''
)
class
TestDescriptions
(
unittest
.
TestCase
):
...
...
@@ -548,7 +590,7 @@ class PydocServerTest(unittest.TestCase):
self
.
assertEqual
(
serverthread
.
error
,
None
)
class
PydocUrlHandlerTest
(
unittest
.
TestCase
):
class
PydocUrlHandlerTest
(
PydocBaseTest
):
"""Tests for pydoc._url_handler"""
def
test_content_type_err
(
self
):
...
...
@@ -575,18 +617,19 @@ class PydocUrlHandlerTest(unittest.TestCase):
(
"getfile?key=foobar"
,
"Pydoc: Error - getfile?key=foobar"
),
]
for
url
,
title
in
requests
:
with
self
.
restrict_walk_packages
():
for
url
,
title
in
requests
:
text
=
pydoc
.
_url_handler
(
url
,
"text/html"
)
result
=
get_html_title
(
text
)
self
.
assertEqual
(
result
,
title
,
text
)
path
=
string
.
__file__
title
=
"Pydoc: getfile "
+
path
url
=
"getfile?key="
+
path
text
=
pydoc
.
_url_handler
(
url
,
"text/html"
)
result
=
get_html_title
(
text
)
self
.
assertEqual
(
result
,
title
)
path
=
string
.
__file__
title
=
"Pydoc: getfile "
+
path
url
=
"getfile?key="
+
path
text
=
pydoc
.
_url_handler
(
url
,
"text/html"
)
result
=
get_html_title
(
text
)
self
.
assertEqual
(
result
,
title
)
class
TestHelper
(
unittest
.
TestCase
):
def
test_keywords
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
c52d113e
...
...
@@ -331,6 +331,11 @@ Documentation
-
Issue
#
6696
:
add
documentation
for
the
Profile
objects
,
and
improve
profile
/
cProfile
docs
.
Patch
by
Tom
Pinckney
.
Tests
-----
-
Issue
#
11995
:
test_pydoc
doesn
't import all sys.path modules anymore.
C-API
-----
...
...
@@ -338,7 +343,6 @@ C-API
- Issue #17327: Add PyDict_SetDefault.
IDLE
----
...
...
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