Commit 9397e2a8 authored by csabella's avatar csabella Committed by Terry Jan Reedy

bpo-31004: IDLE: Factor out FontPage class from configdialog (step 1) (#2905)

The slightly modified tests continue to pass. The General test
broken by the switch to Notebook is fixed.
Patch mostly by Cheryl Sabella.
parent c3aa47f6
This diff is collapsed.
......@@ -9,7 +9,7 @@ requires('gui')
import unittest
from unittest import mock
from idlelib.idle_test.mock_idle import Func
from tkinter import Tk, IntVar, BooleanVar, DISABLED, NORMAL
from tkinter import Tk, Frame, IntVar, BooleanVar, DISABLED, NORMAL
from idlelib import config
from idlelib.configdialog import idleConf, changes, tracers
......@@ -47,7 +47,7 @@ def tearDownModule():
del root
class FontTest(unittest.TestCase):
class FontPageTest(unittest.TestCase):
"""Test that font widgets enable users to make font changes.
Test that widget actions set vars, that var changes add three
......@@ -56,11 +56,15 @@ class FontTest(unittest.TestCase):
"""
@classmethod
def setUpClass(cls):
dialog.set_samples = Func() # Mask instance method.
page = cls.page = dialog.fontpage
#dialog.note.insert(0, page, text='copy')
#dialog.note.add(page, text='copyfgfg')
dialog.note.select(page)
page.set_samples = Func() # Mask instance method.
@classmethod
def tearDownClass(cls):
del dialog.set_samples # Unmask instance method.
del cls.page.set_samples # Unmask instance method.
def setUp(self):
changes.clear()
......@@ -68,7 +72,8 @@ class FontTest(unittest.TestCase):
def test_load_font_cfg(self):
# Leave widget load test to human visual check.
# TODO Improve checks when add IdleConf.get_font_values.
d = dialog
tracers.detach()
d = self.page
d.font_name.set('Fake')
d.font_size.set('1')
d.font_bold.set(True)
......@@ -77,16 +82,17 @@ class FontTest(unittest.TestCase):
self.assertNotEqual(d.font_name.get(), 'Fake')
self.assertNotEqual(d.font_size.get(), '1')
self.assertFalse(d.font_bold.get())
self.assertEqual(d.set_samples.called, 3)
self.assertEqual(d.set_samples.called, 1)
tracers.attach()
def test_fontlist_key(self):
# Up and Down keys should select a new font.
if dialog.fontlist.size() < 2:
cls.skipTest('need at least 2 fonts')
fontlist = dialog.fontlist
d = self.page
if d.fontlist.size() < 2:
self.skipTest('need at least 2 fonts')
fontlist = d.fontlist
fontlist.activate(0)
font = dialog.fontlist.get('active')
font = d.fontlist.get('active')
# Test Down key.
fontlist.focus_force()
......@@ -96,7 +102,7 @@ class FontTest(unittest.TestCase):
down_font = fontlist.get('active')
self.assertNotEqual(down_font, font)
self.assertIn(dialog.font_name.get(), down_font.lower())
self.assertIn(d.font_name.get(), down_font.lower())
# Test Up key.
fontlist.focus_force()
......@@ -106,14 +112,14 @@ class FontTest(unittest.TestCase):
up_font = fontlist.get('active')
self.assertEqual(up_font, font)
self.assertIn(dialog.font_name.get(), up_font.lower())
self.assertIn(d.font_name.get(), up_font.lower())
def test_fontlist_mouse(self):
# Click on item should select that item.
if dialog.fontlist.size() < 2:
d = self.page
if d.fontlist.size() < 2:
cls.skipTest('need at least 2 fonts')
fontlist = dialog.fontlist
fontlist = d.fontlist
fontlist.activate(0)
# Select next item in listbox
......@@ -129,17 +135,17 @@ class FontTest(unittest.TestCase):
font1 = fontlist.get(1)
select_font = fontlist.get('anchor')
self.assertEqual(select_font, font1)
self.assertIn(dialog.font_name.get(), font1.lower())
self.assertIn(d.font_name.get(), font1.lower())
def test_sizelist(self):
# Click on number shouod select that number
d = dialog
d = self.page
d.sizelist.variable.set(40)
self.assertEqual(d.font_size.get(), '40')
def test_bold_toggle(self):
# Click on checkbutton should invert it.
d = dialog
d = self.page
d.font_bold.set(False)
d.bold_toggle.invoke()
self.assertTrue(d.font_bold.get())
......@@ -154,7 +160,7 @@ class FontTest(unittest.TestCase):
default_font = idleConf.GetFont(root, 'main', 'EditorWindow')
default_size = str(default_font[1])
default_bold = default_font[2] == 'bold'
d = dialog
d = self.page
d.font_size.set(default_size)
d.font_bold.set(default_bold)
d.set_samples.called = 0
......@@ -183,7 +189,7 @@ class FontTest(unittest.TestCase):
self.assertEqual(d.set_samples.called, 3)
def test_set_samples(self):
d = dialog
d = self.page
del d.set_samples # Unmask method for test
d.font_sample, d.highlight_sample = {}, {}
d.font_name.set('test')
......@@ -201,16 +207,21 @@ class FontTest(unittest.TestCase):
class IndentTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.page = dialog.fontpage
def test_load_tab_cfg(self):
d = dialog
d = self.page
d.space_num.set(16)
d.load_tab_cfg()
self.assertEqual(d.space_num.get(), 4)
def test_indent_scale(self):
d = self.page
changes.clear()
dialog.indent_scale.set(26)
self.assertEqual(dialog.space_num.get(), 16)
d.indent_scale.set(20)
self.assertEqual(d.space_num.get(), 16)
self.assertEqual(mainpage, {'Indent': {'num-spaces': '16'}})
......@@ -234,8 +245,10 @@ class GeneralTest(unittest.TestCase):
"""
@classmethod
def setUpClass(cls):
# Mask instance methods used by help functions.
d = dialog
# Select General tab so can force focus on helplist.
d.note.select(d.genpage)
# Mask instance methods used by help functions.
d.set = d.set_add_delete_state = Func()
d.upc = d.update_help_changes = Func()
......@@ -311,9 +324,8 @@ class GeneralTest(unittest.TestCase):
helplist.event_generate('<Motion>', x=x, y=y)
helplist.event_generate('<Button-1>', x=x, y=y)
helplist.event_generate('<ButtonRelease-1>', x=x, y=y)
# The following fail after the switch to
# self.assertEqual(helplist.get('anchor'), 'source')
# self.assertTrue(d.set.called)
self.assertEqual(helplist.get('anchor'), 'source')
self.assertTrue(d.set.called)
self.assertFalse(d.upc.called)
def test_set_add_delete_state(self):
......
IDLE - Factor FontPage(Frame) class from ConfigDialog.
Slightly modified tests continue to pass. Fix General tests. Patch mostly by
Cheryl Sabella.
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