https://github.com/python/cpython/commit/1499f66c4c63d68a7ff4fa15fd3f253921f701aa
commit: 1499f66c4c63d68a7ff4fa15fd3f253921f701aa
branch: 3.13
author: Terry Jan Reedy <[email protected]>
committer: terryjreedy <[email protected]>
date: 2025-01-26T09:42:08Z
summary:

[3.13] gh-71339: Use new assertion methods in test_idle (#129314)

Revise 10 tests in 7 files, with 1 test split into 2.
(cherry picked from commit dbb25ce)

files:
M Lib/idlelib/idle_test/test_configdialog.py
M Lib/idlelib/idle_test/test_debugger.py
M Lib/idlelib/idle_test/test_grep.py
M Lib/idlelib/idle_test/test_multicall.py
M Lib/idlelib/idle_test/test_query.py
M Lib/idlelib/idle_test/test_redirector.py
M Lib/idlelib/idle_test/test_sidebar.py

diff --git a/Lib/idlelib/idle_test/test_configdialog.py 
b/Lib/idlelib/idle_test/test_configdialog.py
index 5099d093382445..0daca89084b048 100644
--- a/Lib/idlelib/idle_test/test_configdialog.py
+++ b/Lib/idlelib/idle_test/test_configdialog.py
@@ -5,6 +5,7 @@
 from idlelib import configdialog
 from test.support import requires
 requires('gui')
+from test.support.testcase import ExtraAssertions
 import unittest
 from unittest import mock
 from idlelib.idle_test.mock_idle import Func
@@ -59,7 +60,7 @@ def activate_config_changes(self):
         pass
 
 
-class ButtonTest(unittest.TestCase):
+class ButtonTest(unittest.TestCase, ExtraAssertions):
 
     def test_click_ok(self):
         d = dialog
@@ -98,8 +99,8 @@ def test_click_help(self):
             dialog.buttons['Help'].invoke()
             title, contents = view.kwds['title'], view.kwds['contents']
         self.assertEqual(title, 'Help for IDLE preferences')
-        self.assertTrue(contents.startswith('When you click') and
-                        contents.endswith('a different name.\n'))
+        self.assertStartsWith(contents, 'When you click')
+        self.assertEndsWith(contents,'a different name.\n')
 
 
 class FontPageTest(unittest.TestCase):
diff --git a/Lib/idlelib/idle_test/test_debugger.py 
b/Lib/idlelib/idle_test/test_debugger.py
index d1c9638dd5d711..f4009258e0594c 100644
--- a/Lib/idlelib/idle_test/test_debugger.py
+++ b/Lib/idlelib/idle_test/test_debugger.py
@@ -9,6 +9,7 @@
 from tkinter import Tk
 
 from test.support import requires
+from test.support.testcase import ExtraAssertions
 import unittest
 from unittest import mock
 from unittest.mock import Mock, patch
@@ -227,7 +228,7 @@ def test_show_stack_with_frame(self):
         self.idb.get_stack.assert_called_once_with(test_frame, None)
 
 
-class StackViewerTest(unittest.TestCase):
+class StackViewerTest(unittest.TestCase, ExtraAssertions):
 
     @classmethod
     def setUpClass(cls):
@@ -256,7 +257,7 @@ def test_init(self):
         flist = None
         master_window = self.root
         sv = debugger.StackViewer(master_window, flist, gui)
-        self.assertTrue(hasattr(sv, 'stack'))
+        self.assertHasAttr(sv, 'stack')
 
     def test_load_stack(self):
         # Test the .load_stack() method against a fixed test stack.
diff --git a/Lib/idlelib/idle_test/test_grep.py 
b/Lib/idlelib/idle_test/test_grep.py
index a0b5b69171879c..ad0a813e71d7b8 100644
--- a/Lib/idlelib/idle_test/test_grep.py
+++ b/Lib/idlelib/idle_test/test_grep.py
@@ -8,6 +8,7 @@
 from idlelib import grep
 import unittest
 from test.support import captured_stdout
+from test.support.testcase import ExtraAssertions
 from idlelib.idle_test.mock_tk import Var
 import os
 import re
@@ -115,7 +116,7 @@ def test_recurse(self):
         self.assertIn(self.realpath, filelist)
 
 
-class Grep_itTest(unittest.TestCase):
+class Grep_itTest(unittest.TestCase, ExtraAssertions):
     # Test captured reports with 0 and some hits.
     # Should test file names, but Windows reports have mixed / and \ separators
     # from incomplete replacement, so 'later'.
@@ -143,7 +144,7 @@ def test_found(self):
         self.assertIn(pat, lines[0])
         self.assertIn('py: 1:', lines[1])  # line number 1
         self.assertIn('2', lines[3])  # hits found 2
-        self.assertTrue(lines[4].startswith('(Hint:'))
+        self.assertStartsWith(lines[4], '(Hint:')
 
 
 class Default_commandTest(unittest.TestCase):
diff --git a/Lib/idlelib/idle_test/test_multicall.py 
b/Lib/idlelib/idle_test/test_multicall.py
index b3a3bfb88f9c31..0c1fbfd648820f 100644
--- a/Lib/idlelib/idle_test/test_multicall.py
+++ b/Lib/idlelib/idle_test/test_multicall.py
@@ -3,10 +3,11 @@
 from idlelib import multicall
 import unittest
 from test.support import requires
+from test.support.testcase import ExtraAssertions
 from tkinter import Tk, Text
 
 
-class MultiCallTest(unittest.TestCase):
+class MultiCallTest(unittest.TestCase, ExtraAssertions):
 
     @classmethod
     def setUpClass(cls):
@@ -27,7 +28,7 @@ def tearDownClass(cls):
     def test_creator(self):
         mc = self.mc
         self.assertIs(multicall._multicall_dict[Text], mc)
-        self.assertTrue(issubclass(mc, Text))
+        self.assertIsSubclass(mc, Text)
         mc2 = multicall.MultiCallCreator(Text)
         self.assertIs(mc, mc2)
 
diff --git a/Lib/idlelib/idle_test/test_query.py 
b/Lib/idlelib/idle_test/test_query.py
index bb12b2b08652d5..ee368255f9b5c7 100644
--- a/Lib/idlelib/idle_test/test_query.py
+++ b/Lib/idlelib/idle_test/test_query.py
@@ -12,6 +12,7 @@
 from idlelib import query
 import unittest
 from test.support import requires
+from test.support.testcase import ExtraAssertions
 from tkinter import Tk, END
 
 import sys
@@ -105,7 +106,7 @@ def test_good_section_name(self):
         self.assertEqual(dialog.entry_error['text'], '')
 
 
-class ModuleNameTest(unittest.TestCase):
+class ModuleNameTest(unittest.TestCase, ExtraAssertions):
     "Test ModuleName subclass of Query."
 
     class Dummy_ModuleName:
@@ -134,10 +135,10 @@ def test_c_source_name(self):
 
     def test_good_module_name(self):
         dialog = self.Dummy_ModuleName('idlelib')
-        self.assertTrue(dialog.entry_ok().endswith('__init__.py'))
+        self.assertEndsWith(dialog.entry_ok(), '__init__.py')
         self.assertEqual(dialog.entry_error['text'], '')
         dialog = self.Dummy_ModuleName('idlelib.idle')
-        self.assertTrue(dialog.entry_ok().endswith('idle.py'))
+        self.assertEndsWith(dialog.entry_ok(), 'idle.py')
         self.assertEqual(dialog.entry_error['text'], '')
 
 
@@ -376,7 +377,7 @@ def test_click_section_name(self):
         root.destroy()
 
 
-class ModulenameGuiTest(unittest.TestCase):
+class ModulenameGuiTest(unittest.TestCase, ExtraAssertions):
 
     @classmethod
     def setUpClass(cls):
@@ -389,7 +390,7 @@ def test_click_module_name(self):
         self.assertEqual(dialog.text0, 'idlelib')
         self.assertEqual(dialog.entry.get(), 'idlelib')
         dialog.button_ok.invoke()
-        self.assertTrue(dialog.result.endswith('__init__.py'))
+        self.assertEndsWith(dialog.result, '__init__.py')
         root.destroy()
 
 
diff --git a/Lib/idlelib/idle_test/test_redirector.py 
b/Lib/idlelib/idle_test/test_redirector.py
index a97b3002afcf12..7bd1116debc238 100644
--- a/Lib/idlelib/idle_test/test_redirector.py
+++ b/Lib/idlelib/idle_test/test_redirector.py
@@ -3,11 +3,12 @@
 from idlelib.redirector import WidgetRedirector
 import unittest
 from test.support import requires
+from test.support.testcase import ExtraAssertions
 from tkinter import Tk, Text, TclError
 from idlelib.idle_test.mock_idle import Func
 
 
-class InitCloseTest(unittest.TestCase):
+class InitCloseTest(unittest.TestCase, ExtraAssertions):
 
     @classmethod
     def setUpClass(cls):
@@ -34,7 +35,7 @@ def test_close(self):
         redir.register('insert', Func)
         redir.close()
         self.assertEqual(redir._operations, {})
-        self.assertFalse(hasattr(self.text, 'widget'))
+        self.assertNotHasAttr(self.text, 'widget')
 
 
 class WidgetRedirectorTest(unittest.TestCase):
diff --git a/Lib/idlelib/idle_test/test_sidebar.py 
b/Lib/idlelib/idle_test/test_sidebar.py
index 605e7a892570d7..3e854561a0f5b9 100644
--- a/Lib/idlelib/idle_test/test_sidebar.py
+++ b/Lib/idlelib/idle_test/test_sidebar.py
@@ -5,8 +5,8 @@
 from itertools import chain
 import unittest
 import unittest.mock
-from test.support import requires, swap_attr
-from test import support
+from test.support import adjust_int_max_str_digits, requires, swap_attr
+from test.support.testcase import ExtraAssertions
 import tkinter as tk
 from idlelib.idle_test.tkinter_testing_utils import run_in_tk_mainloop
 
@@ -391,7 +391,7 @@ def assert_colors_are_equal(colors):
         assert_colors_are_equal(orig_colors)
 
 
-class ShellSidebarTest(unittest.TestCase):
+class ShellSidebarTest(unittest.TestCase, ExtraAssertions):
     root: tk.Tk = None
     shell: PyShell = None
 
@@ -613,7 +613,7 @@ def test_interrupt_recall_undo_redo(self):
 
     @run_in_tk_mainloop()
     def test_very_long_wrapped_line(self):
-        with support.adjust_int_max_str_digits(11_111), \
+        with adjust_int_max_str_digits(11_111), \
                 swap_attr(self.shell, 'squeezer', None):
             self.do_input('x = ' + '1'*10_000 + '\n')
             yield
@@ -725,7 +725,7 @@ def test_copy(self):
 
         text.tag_add('sel', f'{first_line}.0', 'end-1c')
         selected_text = text.get('sel.first', 'sel.last')
-        self.assertTrue(selected_text.startswith('if True:\n'))
+        self.assertStartsWith(selected_text, 'if True:\n')
         self.assertIn('\n1\n', selected_text)
 
         text.event_generate('<<copy>>')
@@ -749,7 +749,7 @@ def test_copy_with_prompts(self):
 
         text.tag_add('sel', f'{first_line}.3', 'end-1c')
         selected_text = text.get('sel.first', 'sel.last')
-        self.assertTrue(selected_text.startswith('True:\n'))
+        self.assertStartsWith(selected_text, 'True:\n')
 
         selected_lines_text = text.get('sel.first linestart', 'sel.last')
         selected_lines = selected_lines_text.split('\n')

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to