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

Revise 10 tests in 7 files, with 1 test split into 2.
(cherry picked from commit 1499f66c4c)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2025-01-26 11:33:44 +01:00 committed by GitHub
parent 53204a11f1
commit 0d53d7afd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 28 additions and 22 deletions

View file

@ -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):

View file

@ -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.

View file

@ -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):

View file

@ -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)

View file

@ -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()

View file

@ -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):

View file

@ -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')