bpo-17535: IDLE editor line numbers (GH-14030)

This commit is contained in:
Tal Einat 2019-07-23 15:22:11 +03:00 committed by GitHub
parent 1ebee37dde
commit 7123ea009b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 891 additions and 80 deletions

View file

@ -4,7 +4,7 @@
import unittest
import unittest.mock
from test.support import requires
from tkinter import Tk, Frame, Text, TclError
from tkinter import NSEW, Tk, Frame, Text, TclError
from unittest import mock
import re
@ -62,7 +62,7 @@ def setUpClass(cls):
text.insert('1.0', code_sample)
# Need to pack for creation of code context text widget.
frame.pack(side='left', fill='both', expand=1)
text.pack(side='top', fill='both', expand=1)
text.grid(row=1, column=1, sticky=NSEW)
cls.editor = DummyEditwin(root, frame, text)
codecontext.idleConf.userCfg = testcfg
@ -77,6 +77,7 @@ def tearDownClass(cls):
def setUp(self):
self.text.yview(0)
self.text['font'] = 'TkFixedFont'
self.cc = codecontext.CodeContext(self.editor)
self.highlight_cfg = {"background": '#abcdef',
@ -86,10 +87,18 @@ def mock_idleconf_GetHighlight(theme, element):
if element == 'context':
return self.highlight_cfg
return orig_idleConf_GetHighlight(theme, element)
patcher = unittest.mock.patch.object(
GetHighlight_patcher = unittest.mock.patch.object(
codecontext.idleConf, 'GetHighlight', mock_idleconf_GetHighlight)
patcher.start()
self.addCleanup(patcher.stop)
GetHighlight_patcher.start()
self.addCleanup(GetHighlight_patcher.stop)
self.font_override = 'TkFixedFont'
def mock_idleconf_GetFont(root, configType, section):
return self.font_override
GetFont_patcher = unittest.mock.patch.object(
codecontext.idleConf, 'GetFont', mock_idleconf_GetFont)
GetFont_patcher.start()
self.addCleanup(GetFont_patcher.stop)
def tearDown(self):
if self.cc.context:
@ -339,69 +348,59 @@ def test_timer_event(self, mock_update):
def test_font(self):
eq = self.assertEqual
cc = self.cc
save_font = cc.text['font']
orig_font = cc.text['font']
test_font = 'TkTextFont'
self.assertNotEqual(orig_font, test_font)
# Ensure code context is not active.
if cc.context is not None:
cc.toggle_code_context_event()
self.font_override = test_font
# Nothing breaks or changes with inactive code context.
cc.update_font(test_font)
cc.update_font()
# Activate code context, but no change to font.
# Activate code context, previous font change is immediately effective.
cc.toggle_code_context_event()
eq(cc.context['font'], save_font)
# Call font update with the existing font.
cc.update_font(save_font)
eq(cc.context['font'], save_font)
cc.toggle_code_context_event()
# Change text widget font and activate code context.
cc.text['font'] = test_font
cc.toggle_code_context_event(test_font)
eq(cc.context['font'], test_font)
# Just call the font update.
cc.update_font(save_font)
eq(cc.context['font'], save_font)
cc.text['font'] = save_font
# Call the font update, change is picked up.
self.font_override = orig_font
cc.update_font()
eq(cc.context['font'], orig_font)
def test_highlight_colors(self):
eq = self.assertEqual
cc = self.cc
save_colors = dict(self.highlight_cfg)
orig_colors = dict(self.highlight_cfg)
test_colors = {'background': '#222222', 'foreground': '#ffff00'}
def assert_colors_are_equal(colors):
eq(cc.context['background'], colors['background'])
eq(cc.context['foreground'], colors['foreground'])
# Ensure code context is not active.
if cc.context:
cc.toggle_code_context_event()
self.highlight_cfg = test_colors
# Nothing breaks with inactive code context.
cc.update_highlight_colors()
# Activate code context, but no change to colors.
# Activate code context, previous colors change is immediately effective.
cc.toggle_code_context_event()
eq(cc.context['background'], save_colors['background'])
eq(cc.context['foreground'], save_colors['foreground'])
assert_colors_are_equal(test_colors)
# Call colors update, but no change to font.
# Call colors update with no change to the configured colors.
cc.update_highlight_colors()
eq(cc.context['background'], save_colors['background'])
eq(cc.context['foreground'], save_colors['foreground'])
cc.toggle_code_context_event()
assert_colors_are_equal(test_colors)
# Change colors and activate code context.
self.highlight_cfg = test_colors
cc.toggle_code_context_event()
eq(cc.context['background'], test_colors['background'])
eq(cc.context['foreground'], test_colors['foreground'])
# Change colors and call highlight colors update.
self.highlight_cfg = save_colors
# Call the colors update with code context active, change is picked up.
self.highlight_cfg = orig_colors
cc.update_highlight_colors()
eq(cc.context['background'], save_colors['background'])
eq(cc.context['foreground'], save_colors['foreground'])
assert_colors_are_equal(orig_colors)
class HelperFunctionText(unittest.TestCase):