mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-43013: Fix old tkinter module names in idlelib (GH-24326)
Lowercase 'tkColorChooser', 'tkFileDialog', 'tkSimpleDialog', and 'tkMessageBox' and remove 'tk'. Just lowercase 'tkFont' as 'font' is already used. Adjust import.
This commit is contained in:
parent
cf19cc3b92
commit
879986d8a9
13 changed files with 66 additions and 67 deletions
|
@ -59,27 +59,26 @@ class Mbox_func:
|
|||
class Mbox:
|
||||
"""Mock for tkinter.messagebox with an Mbox_func for each function.
|
||||
|
||||
This module was 'tkMessageBox' in 2.x; hence the 'import as' in 3.x.
|
||||
Example usage in test_module.py for testing functions in module.py:
|
||||
---
|
||||
from idlelib.idle_test.mock_tk import Mbox
|
||||
import module
|
||||
|
||||
orig_mbox = module.tkMessageBox
|
||||
orig_mbox = module.messagebox
|
||||
showerror = Mbox.showerror # example, for attribute access in test methods
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
module.tkMessageBox = Mbox
|
||||
module.messagebox = Mbox
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
module.tkMessageBox = orig_mbox
|
||||
module.messagebox = orig_mbox
|
||||
---
|
||||
For 'ask' functions, set func.result return value before calling the method
|
||||
that uses the message function. When tkMessageBox functions are the
|
||||
that uses the message function. When messagebox functions are the
|
||||
only gui alls in a method, this replacement makes the method gui-free,
|
||||
"""
|
||||
askokcancel = Mbox_func() # True or False
|
||||
|
|
|
@ -423,7 +423,7 @@ class HighPageTest(unittest.TestCase):
|
|||
def test_color(self):
|
||||
d = self.page
|
||||
d.on_new_color_set = Func()
|
||||
# self.color is only set in get_color through ColorChooser.
|
||||
# self.color is only set in get_color through colorchooser.
|
||||
d.color.set('green')
|
||||
self.assertEqual(d.on_new_color_set.called, 1)
|
||||
del d.on_new_color_set
|
||||
|
@ -540,8 +540,8 @@ class HighPageTest(unittest.TestCase):
|
|||
def test_get_color(self):
|
||||
eq = self.assertEqual
|
||||
d = self.page
|
||||
orig_chooser = configdialog.tkColorChooser.askcolor
|
||||
chooser = configdialog.tkColorChooser.askcolor = Func()
|
||||
orig_chooser = configdialog.colorchooser.askcolor
|
||||
chooser = configdialog.colorchooser.askcolor = Func()
|
||||
gntn = d.get_new_theme_name = Func()
|
||||
|
||||
d.highlight_target.set('Editor Breakpoint')
|
||||
|
@ -582,7 +582,7 @@ class HighPageTest(unittest.TestCase):
|
|||
eq(d.color.get(), '#de0000')
|
||||
|
||||
del d.get_new_theme_name
|
||||
configdialog.tkColorChooser.askcolor = orig_chooser
|
||||
configdialog.colorchooser.askcolor = orig_chooser
|
||||
|
||||
def test_on_new_color_set(self):
|
||||
d = self.page
|
||||
|
|
|
@ -10,7 +10,7 @@ from unittest.mock import Mock
|
|||
from idlelib.idle_test.mock_tk import Mbox
|
||||
import idlelib.searchengine as se
|
||||
|
||||
orig_mbox = se.tkMessageBox
|
||||
orig_mbox = se.messagebox
|
||||
showerror = Mbox.showerror
|
||||
|
||||
|
||||
|
@ -20,7 +20,7 @@ class ReplaceDialogTest(unittest.TestCase):
|
|||
def setUpClass(cls):
|
||||
cls.root = Tk()
|
||||
cls.root.withdraw()
|
||||
se.tkMessageBox = Mbox
|
||||
se.messagebox = Mbox
|
||||
cls.engine = se.SearchEngine(cls.root)
|
||||
cls.dialog = ReplaceDialog(cls.root, cls.engine)
|
||||
cls.dialog.bell = lambda: None
|
||||
|
@ -32,7 +32,7 @@ class ReplaceDialogTest(unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
se.tkMessageBox = orig_mbox
|
||||
se.messagebox = orig_mbox
|
||||
del cls.text, cls.dialog, cls.engine
|
||||
cls.root.destroy()
|
||||
del cls.root
|
||||
|
|
|
@ -4,7 +4,7 @@ from idlelib import searchengine as se
|
|||
import unittest
|
||||
# from test.support import requires
|
||||
from tkinter import BooleanVar, StringVar, TclError # ,Tk, Text
|
||||
import tkinter.messagebox as tkMessageBox
|
||||
from tkinter import messagebox
|
||||
from idlelib.idle_test.mock_tk import Var, Mbox
|
||||
from idlelib.idle_test.mock_tk import Text as mockText
|
||||
import re
|
||||
|
@ -19,13 +19,13 @@ def setUpModule():
|
|||
# Replace s-e module tkinter imports other than non-gui TclError.
|
||||
se.BooleanVar = Var
|
||||
se.StringVar = Var
|
||||
se.tkMessageBox = Mbox
|
||||
se.messagebox = Mbox
|
||||
|
||||
def tearDownModule():
|
||||
# Restore 'just in case', though other tests should also replace.
|
||||
se.BooleanVar = BooleanVar
|
||||
se.StringVar = StringVar
|
||||
se.tkMessageBox = tkMessageBox
|
||||
se.messagebox = messagebox
|
||||
|
||||
|
||||
class Mock:
|
||||
|
|
|
@ -396,7 +396,7 @@ class ExpandingButtonTest(unittest.TestCase):
|
|||
expandingbutton.base_text = expandingbutton.text
|
||||
|
||||
# Patch the message box module to always return False.
|
||||
with patch('idlelib.squeezer.tkMessageBox') as mock_msgbox:
|
||||
with patch('idlelib.squeezer.messagebox') as mock_msgbox:
|
||||
mock_msgbox.askokcancel.return_value = False
|
||||
mock_msgbox.askyesno.return_value = False
|
||||
# Trigger the expand event.
|
||||
|
@ -407,7 +407,7 @@ class ExpandingButtonTest(unittest.TestCase):
|
|||
self.assertEqual(expandingbutton.text.get('1.0', 'end-1c'), '')
|
||||
|
||||
# Patch the message box module to always return True.
|
||||
with patch('idlelib.squeezer.tkMessageBox') as mock_msgbox:
|
||||
with patch('idlelib.squeezer.messagebox') as mock_msgbox:
|
||||
mock_msgbox.askokcancel.return_value = True
|
||||
mock_msgbox.askyesno.return_value = True
|
||||
# Trigger the expand event.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue