mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Recorded merge of revisions 81364 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r81364 | victor.stinner | 2010-05-19 22:40:50 +0200 (mer., 19 mai 2010) | 3 lines Issue #8766: Initialize _warnings module before importing the first module. Fix a crash if an empty directory called "encodings" exists in sys.path. ........
This commit is contained in:
parent
784c027d18
commit
148051a054
4 changed files with 47 additions and 11 deletions
|
@ -4,6 +4,9 @@ import os
|
|||
from io import StringIO
|
||||
import sys
|
||||
import unittest
|
||||
import shutil
|
||||
import tempfile
|
||||
import subprocess
|
||||
from test import support
|
||||
|
||||
from test import warning_tests
|
||||
|
@ -670,18 +673,46 @@ class PyCatchWarningTests(CatchWarningTests):
|
|||
module = py_warnings
|
||||
|
||||
|
||||
class BootstrapTest(unittest.TestCase):
|
||||
def test_issue_8766(self):
|
||||
# "import encodings" emits a warning whereas the warnings is not loaded
|
||||
# or not completly loaded (warnings imports indirectly encodings by
|
||||
# importing linecache) yet
|
||||
old_cwd = os.getcwd()
|
||||
try:
|
||||
cwd = tempfile.mkdtemp()
|
||||
try:
|
||||
os.chdir(cwd)
|
||||
os.mkdir('encodings')
|
||||
env = os.environ.copy()
|
||||
env['PYTHONPATH'] = cwd
|
||||
|
||||
# encodings loaded by initfsencoding()
|
||||
retcode = subprocess.call([sys.executable, '-c', 'pass'], env=env)
|
||||
self.assertEqual(retcode, 0)
|
||||
|
||||
# Use -W to load warnings module at startup
|
||||
retcode = subprocess.call(
|
||||
[sys.executable, '-c', 'pass', '-W', 'always'],
|
||||
env=env)
|
||||
self.assertEqual(retcode, 0)
|
||||
finally:
|
||||
shutil.rmtree(cwd)
|
||||
finally:
|
||||
os.chdir(old_cwd)
|
||||
|
||||
def test_main():
|
||||
py_warnings.onceregistry.clear()
|
||||
c_warnings.onceregistry.clear()
|
||||
support.run_unittest(CFilterTests,
|
||||
PyFilterTests,
|
||||
CWarnTests,
|
||||
PyWarnTests,
|
||||
CWCmdLineTests, PyWCmdLineTests,
|
||||
_WarningsTests,
|
||||
CWarningsDisplayTests, PyWarningsDisplayTests,
|
||||
CCatchWarningTests, PyCatchWarningTests,
|
||||
)
|
||||
support.run_unittest(
|
||||
CFilterTests, PyFilterTests,
|
||||
CWarnTests, PyWarnTests,
|
||||
CWCmdLineTests, PyWCmdLineTests,
|
||||
_WarningsTests,
|
||||
CWarningsDisplayTests, PyWarningsDisplayTests,
|
||||
CCatchWarningTests, PyCatchWarningTests,
|
||||
BootstrapTest,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue