diff options
author | Tal Einat <taleinat@gmail.com> | 2019-07-23 12:22:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-23 12:22:11 (GMT) |
commit | 7123ea009b0b004062d91f69859bddf422c34ab4 (patch) | |
tree | 710e79beacd4853354ccb4a5d6333148914e54ec /Lib/idlelib/idle_test/test_codecontext.py | |
parent | 1ebee37dde5c2aabc8e2d2c7bbe2a69b293133bb (diff) | |
download | cpython-7123ea009b0b004062d91f69859bddf422c34ab4.zip cpython-7123ea009b0b004062d91f69859bddf422c34ab4.tar.gz cpython-7123ea009b0b004062d91f69859bddf422c34ab4.tar.bz2 |
bpo-17535: IDLE editor line numbers (GH-14030)
Diffstat (limited to 'Lib/idlelib/idle_test/test_codecontext.py')
-rw-r--r-- | Lib/idlelib/idle_test/test_codecontext.py | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/Lib/idlelib/idle_test/test_codecontext.py b/Lib/idlelib/idle_test/test_codecontext.py index c6c8e8e..3ec49e9 100644 --- a/Lib/idlelib/idle_test/test_codecontext.py +++ b/Lib/idlelib/idle_test/test_codecontext.py @@ -4,7 +4,7 @@ from idlelib import codecontext 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 @@ class CodeContextTest(unittest.TestCase): 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 @@ class CodeContextTest(unittest.TestCase): 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 @@ class CodeContextTest(unittest.TestCase): 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 @@ class CodeContextTest(unittest.TestCase): 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. - 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) + # Activate code context, previous font change is immediately effective. 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() - - # 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']) + assert_colors_are_equal(test_colors) - # 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): |