diff options
author | Tal Einat <taleinat+github@gmail.com> | 2019-08-25 05:52:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-25 05:52:58 (GMT) |
commit | d4b4c00b57d24f6ee2cf3a96213406bb09953df3 (patch) | |
tree | f91a4598253622581add7aec2cf867f2bb8090e2 /Lib/idlelib/idle_test | |
parent | aef9ad82f7f667cd001a7112d3bc636e918626f7 (diff) | |
download | cpython-d4b4c00b57d24f6ee2cf3a96213406bb09953df3.zip cpython-d4b4c00b57d24f6ee2cf3a96213406bb09953df3.tar.gz cpython-d4b4c00b57d24f6ee2cf3a96213406bb09953df3.tar.bz2 |
bpo-37929: IDLE: avoid Squeezer-related config dialog crashes (GH-15452)
These were caused by keeping around a reference to the Squeezer
instance and calling it's load_font() upon config changes, which
sometimes happened even if the shell window no longer existed.
This change completely removes that mechanism, instead having the
editor window properly update its width attribute, which can then
be used by Squeezer.
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r-- | Lib/idlelib/idle_test/test_squeezer.py | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/Lib/idlelib/idle_test/test_squeezer.py b/Lib/idlelib/idle_test/test_squeezer.py index 4e3da03..1af2ce8 100644 --- a/Lib/idlelib/idle_test/test_squeezer.py +++ b/Lib/idlelib/idle_test/test_squeezer.py @@ -82,18 +82,10 @@ class CountLinesTest(unittest.TestCase): class SqueezerTest(unittest.TestCase): """Tests for the Squeezer class.""" - def tearDown(self): - # Clean up the Squeezer class's reference to its instance, - # to avoid side-effects from one test case upon another. - if Squeezer._instance_weakref is not None: - Squeezer._instance_weakref = None - def make_mock_editor_window(self, with_text_widget=False): """Create a mock EditorWindow instance.""" editwin = NonCallableMagicMock() - # isinstance(editwin, PyShell) must be true for Squeezer to enable - # auto-squeezing; in practice this will always be true. - editwin.__class__ = PyShell + editwin.width = 80 if with_text_widget: editwin.root = get_test_tk_root(self) @@ -107,7 +99,6 @@ class SqueezerTest(unittest.TestCase): if editor_window is None: editor_window = self.make_mock_editor_window() squeezer = Squeezer(editor_window) - squeezer.get_line_width = Mock(return_value=80) return squeezer def make_text_widget(self, root=None): @@ -143,8 +134,8 @@ class SqueezerTest(unittest.TestCase): line_width=line_width, expected=expected): text = eval(text_code) - squeezer.get_line_width.return_value = line_width - self.assertEqual(squeezer.count_lines(text), expected) + with patch.object(editwin, 'width', line_width): + self.assertEqual(squeezer.count_lines(text), expected) def test_init(self): """Test the creation of Squeezer instances.""" @@ -294,7 +285,6 @@ class SqueezerTest(unittest.TestCase): """Test the reload() class-method.""" editwin = self.make_mock_editor_window(with_text_widget=True) squeezer = self.make_squeezer_instance(editwin) - squeezer.load_font = Mock() orig_auto_squeeze_min_lines = squeezer.auto_squeeze_min_lines @@ -307,7 +297,6 @@ class SqueezerTest(unittest.TestCase): Squeezer.reload() self.assertEqual(squeezer.auto_squeeze_min_lines, new_auto_squeeze_min_lines) - squeezer.load_font.assert_called() def test_reload_no_squeezer_instances(self): """Test that Squeezer.reload() runs without any instances existing.""" |