diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-02-27 11:14:06 -0800 |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2019-02-27 14:14:06 -0500 |
commit | 488aabafe2f1c5db05a6c1a7a8b49d7b89b1f36b (patch) | |
tree | 1d9e577b88099b537057a1764fbe2d3f9b561381 | |
parent | bpo-28441: Ensure `.exe` suffix in `sys.executable` on MinGW and Cygwin (GH-4... (diff) | |
download | cpython-488aabafe2f1c5db05a6c1a7a8b49d7b89b1f36b.tar.gz cpython-488aabafe2f1c5db05a6c1a7a8b49d7b89b1f36b.tar.bz2 cpython-488aabafe2f1c5db05a6c1a7a8b49d7b89b1f36b.zip |
bpo-36096: IDLE: Refactor class variables in colorizer (GH-12002) (GH-12075)
(cherry picked from commit ed1deb0719f0ac1b08a374e30ad26a701d4d51a2)
Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
-rw-r--r-- | Lib/idlelib/colorizer.py | 26 | ||||
-rw-r--r-- | Lib/idlelib/idle_test/test_colorizer.py | 52 | ||||
-rw-r--r-- | Misc/NEWS.d/next/IDLE/2019-02-23-17-53-53.bpo-36096.mN5Ly3.rst | 1 |
3 files changed, 58 insertions, 21 deletions
diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py index 57942e8a7ca..fd13281fb29 100644 --- a/Lib/idlelib/colorizer.py +++ b/Lib/idlelib/colorizer.py @@ -55,26 +55,35 @@ def color_config(text): class ColorDelegator(Delegator): """Delegator for syntax highlighting (text coloring). - Class variables: - after_id: Identifier for scheduled after event. + Instance variables: + delegate: Delegator below this one in the stack, meaning the + one this one delegates to. + + Used to track state: + after_id: Identifier for scheduled after event, which is a + timer for colorizing the text. allow_colorizing: Boolean toggle for applying colorizing. colorizing: Boolean flag when colorizing is in process. stop_colorizing: Boolean flag to end an active colorizing process. close_when_done: Widget to destroy after colorizing process completes (doesn't seem to be used by IDLE). - - Instance variables: - delegate: Delegator below this one in the stack, meaning the - one this one delegates to. """ def __init__(self): Delegator.__init__(self) + self.init_state() self.prog = prog self.idprog = idprog self.LoadTagDefs() + def init_state(self): + "Initialize variables that track colorizing state." + self.after_id = None + self.allow_colorizing = True + self.stop_colorizing = False + self.colorizing = False + def setdelegate(self, delegate): """Set the delegate for this instance. @@ -134,11 +143,6 @@ class ColorDelegator(Delegator): self.delegate.delete(index1, index2) self.notify_range(index1) - after_id = None - allow_colorizing = True - stop_colorizing = False - colorizing = False - def notify_range(self, index1, index2=None): "Mark text changes for processing and restart colorizing, if active." self.tag_add("TODO", index1, index2) diff --git a/Lib/idlelib/idle_test/test_colorizer.py b/Lib/idlelib/idle_test/test_colorizer.py index 4ade5a149b4..c31c49236ca 100644 --- a/Lib/idlelib/idle_test/test_colorizer.py +++ b/Lib/idlelib/idle_test/test_colorizer.py @@ -100,7 +100,7 @@ class ColorConfigTest(unittest.TestCase): eq(text['inactiveselectbackground'], 'gray') -class ColorDelegatorTest(unittest.TestCase): +class ColorDelegatorInstantiationTest(unittest.TestCase): @classmethod def setUpClass(cls): @@ -108,25 +108,19 @@ class ColorDelegatorTest(unittest.TestCase): root = cls.root = Tk() root.withdraw() text = cls.text = Text(root) - cls.percolator = Percolator(text) - # Delegator stack = [Delagator(text)] @classmethod def tearDownClass(cls): - cls.percolator.redir.close() - del cls.percolator, cls.text + del cls.text cls.root.update_idletasks() cls.root.destroy() del cls.root def setUp(self): self.color = colorizer.ColorDelegator() - self.percolator.insertfilter(self.color) - # Calls color.setdelagate(Delagator(text)). def tearDown(self): self.color.close() - self.percolator.removefilter(self.color) self.text.delete('1.0', 'end') self.color.resetcache() del self.color @@ -134,12 +128,50 @@ class ColorDelegatorTest(unittest.TestCase): def test_init(self): color = self.color self.assertIsInstance(color, colorizer.ColorDelegator) - # The following are class variables. + + def test_init_state(self): + # init_state() is called during the instantiation of + # ColorDelegator in setUp(). + color = self.color + self.assertIsNone(color.after_id) self.assertTrue(color.allow_colorizing) self.assertFalse(color.colorizing) + self.assertFalse(color.stop_colorizing) + + +class ColorDelegatorTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + requires('gui') + root = cls.root = Tk() + root.withdraw() + text = cls.text = Text(root) + cls.percolator = Percolator(text) + # Delegator stack = [Delegator(text)] + + @classmethod + def tearDownClass(cls): + cls.percolator.redir.close() + del cls.percolator, cls.text + cls.root.update_idletasks() + cls.root.destroy() + del cls.root + + def setUp(self): + self.color = colorizer.ColorDelegator() + self.percolator.insertfilter(self.color) + # Calls color.setdelegate(Delegator(text)). + + def tearDown(self): + self.color.close() + self.percolator.removefilter(self.color) + self.text.delete('1.0', 'end') + self.color.resetcache() + del self.color def test_setdelegate(self): - # Called in setUp. + # Called in setUp when filter is attached to percolator. color = self.color self.assertIsInstance(color.delegate, colorizer.Delegator) # It is too late to mock notify_range, so test side effect. diff --git a/Misc/NEWS.d/next/IDLE/2019-02-23-17-53-53.bpo-36096.mN5Ly3.rst b/Misc/NEWS.d/next/IDLE/2019-02-23-17-53-53.bpo-36096.mN5Ly3.rst new file mode 100644 index 00000000000..cd6f76e9ac2 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-02-23-17-53-53.bpo-36096.mN5Ly3.rst @@ -0,0 +1 @@ +Refactor class variables to instance variables in colorizer. |