Commit 7c153414 authored by Terry Jan Reedy's avatar Terry Jan Reedy

Issue 27372: Stop test_idle from changing locale, so test passes.

In 3.6, the warning is now called an error, making it harder to ignore.
parent b554fadd
...@@ -7,3 +7,4 @@ Use the files named idle.* to start Idle. ...@@ -7,3 +7,4 @@ Use the files named idle.* to start Idle.
The other files are private implementations. Their details are subject to The other files are private implementations. Their details are subject to
change. See PEP 434 for more. Import them at your own risk. change. See PEP 434 for more. Import them at your own risk.
""" """
testing = False # Set True by test.test_idle.
...@@ -26,9 +26,9 @@ from idlelib import help ...@@ -26,9 +26,9 @@ from idlelib import help
# The default tab setting for a Text widget, in average-width characters. # The default tab setting for a Text widget, in average-width characters.
TK_TABWIDTH_DEFAULT = 8 TK_TABWIDTH_DEFAULT = 8
_py_version = ' (%s)' % platform.python_version() _py_version = ' (%s)' % platform.python_version()
def _sphinx_version(): def _sphinx_version():
"Format sys.version_info to produce the Sphinx version string used to install the chm docs" "Format sys.version_info to produce the Sphinx version string used to install the chm docs"
major, minor, micro, level, serial = sys.version_info major, minor, micro, level, serial = sys.version_info
...@@ -45,11 +45,12 @@ class EditorWindow(object): ...@@ -45,11 +45,12 @@ class EditorWindow(object):
from idlelib.percolator import Percolator from idlelib.percolator import Percolator
from idlelib.colorizer import ColorDelegator, color_config from idlelib.colorizer import ColorDelegator, color_config
from idlelib.undo import UndoDelegator from idlelib.undo import UndoDelegator
from idlelib.iomenu import IOBinding, filesystemencoding, encoding from idlelib.iomenu import IOBinding, encoding
from idlelib import mainmenu from idlelib import mainmenu
from tkinter import Toplevel from tkinter import Toplevel
from idlelib.statusbar import MultiStatusBar from idlelib.statusbar import MultiStatusBar
filesystemencoding = sys.getfilesystemencoding() # for file names
help_url = None help_url = None
def __init__(self, flist=None, filename=None, key=None, root=None): def __init__(self, flist=None, filename=None, key=None, root=None):
...@@ -1649,5 +1650,8 @@ def _editor_window(parent): # htest # ...@@ -1649,5 +1650,8 @@ def _editor_window(parent): # htest #
# edit.text.bind("<<close-window>>", edit.close_event) # edit.text.bind("<<close-window>>", edit.close_event)
if __name__ == '__main__': if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_editor', verbosity=2, exit=False)
from idlelib.idle_test.htest import run from idlelib.idle_test.htest import run
run(_editor_window) run(_editor_window)
...@@ -10,22 +10,22 @@ import tkinter.filedialog as tkFileDialog ...@@ -10,22 +10,22 @@ import tkinter.filedialog as tkFileDialog
import tkinter.messagebox as tkMessageBox import tkinter.messagebox as tkMessageBox
from tkinter.simpledialog import askstring from tkinter.simpledialog import askstring
import idlelib
from idlelib.config import idleConf from idlelib.config import idleConf
if idlelib.testing: # Set True by test.test_idle to avoid setlocale.
# Try setting the locale, so that we can find out encoding = 'utf-8'
# what encoding to use else:
try: # Try setting the locale, so that we can find out
# what encoding to use
try:
import locale import locale
locale.setlocale(locale.LC_CTYPE, "") locale.setlocale(locale.LC_CTYPE, "")
except (ImportError, locale.Error): except (ImportError, locale.Error):
pass pass
# Encoding for file names locale_decode = 'ascii'
filesystemencoding = sys.getfilesystemencoding() ### currently unused if sys.platform == 'win32':
locale_encoding = 'ascii'
if sys.platform == 'win32':
# On Windows, we could use "mbcs". However, to give the user # On Windows, we could use "mbcs". However, to give the user
# a portable encoding name, we need to find the code page # a portable encoding name, we need to find the code page
try: try:
...@@ -33,7 +33,7 @@ if sys.platform == 'win32': ...@@ -33,7 +33,7 @@ if sys.platform == 'win32':
codecs.lookup(locale_encoding) codecs.lookup(locale_encoding)
except LookupError: except LookupError:
pass pass
else: else:
try: try:
# Different things can fail here: the locale module may not be # Different things can fail here: the locale module may not be
# loaded, it may not offer nl_langinfo, or CODESET, or the # loaded, it may not offer nl_langinfo, or CODESET, or the
...@@ -57,10 +57,13 @@ else: ...@@ -57,10 +57,13 @@ else:
except (ValueError, LookupError): except (ValueError, LookupError):
pass pass
locale_encoding = locale_encoding.lower() locale_encoding = locale_encoding.lower()
encoding = locale_encoding ### KBK 07Sep07 This is used all over IDLE, check! encoding = locale_encoding
### 'encoding' is used below in encode(), check! # Encoding is used in multiple files; locale_encoding nowhere.
# The only use of 'encoding' below is in _decode as initial value
# of deprecated block asking user for encoding.
# Perhaps use elsewhere should be reviewed.
coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII) coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII) blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII)
...@@ -304,7 +307,7 @@ class IOBinding: ...@@ -304,7 +307,7 @@ class IOBinding:
"The file's encoding is invalid for Python 3.x.\n" "The file's encoding is invalid for Python 3.x.\n"
"IDLE will convert it to UTF-8.\n" "IDLE will convert it to UTF-8.\n"
"What is the current encoding of the file?", "What is the current encoding of the file?",
initialvalue = locale_encoding, initialvalue = encoding,
parent = self.editwin.text) parent = self.editwin.text)
if enc: if enc:
...@@ -564,5 +567,8 @@ def _io_binding(parent): # htest # ...@@ -564,5 +567,8 @@ def _io_binding(parent): # htest #
IOBinding(editwin) IOBinding(editwin)
if __name__ == "__main__": if __name__ == "__main__":
import unittest
unittest.main('idlelib.idle_test.test_iomenu', verbosity=2, exit=False)
from idlelib.idle_test.htest import run from idlelib.idle_test.htest import run
run(_io_binding) run(_io_binding)
import unittest import unittest
from test.support import import_module from test.support import import_module
# Skip test if _thread or _tkinter wasn't built or idlelib was deleted. # Skip test if _thread or _tkinter wasn't built, or idlelib is missing,
# or if tcl/tk version before 8.5, which is needed for ttk widgets.
import_module('threading') # imported by PyShell, imports _thread import_module('threading') # imported by PyShell, imports _thread
tk = import_module('tkinter') # imports _tkinter tk = import_module('tkinter') # imports _tkinter
if tk.TkVersion < 8.5: if tk.TkVersion < 8.5:
raise unittest.SkipTest("IDLE requires tk 8.5 or later.") raise unittest.SkipTest("IDLE requires tk 8.5 or later.")
tk.NoDefaultRoot() tk.NoDefaultRoot()
idletest = import_module('idlelib.idle_test') idlelib = import_module('idlelib')
idlelib.testing = True # Avoid locale-changed test error
# Without test_main present, regrtest.runtest_inner (line1219) calls # Without test_main present, test.libregrtest.runtest.runtest_inner
# unittest.TestLoader().loadTestsFromModule(this_module) which calls # calls (line 173) unittest.TestLoader().loadTestsFromModule(module)
# load_tests() if it finds it. (Unittest.main does the same.) # which calls load_tests() if it finds it. (Unittest.main does the same.)
load_tests = idletest.load_tests from idlelib.idle_test import load_tests
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(verbosity=2, exit=False) unittest.main(verbosity=2, exit=False)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment