mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
[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:
parent
53204a11f1
commit
0d53d7afd5
7 changed files with 28 additions and 22 deletions
|
@ -5,6 +5,7 @@ Half the class creates dialog, half works with user customizations.
|
|||
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 @@ class ConfigDialogTest(unittest.TestCase):
|
|||
pass
|
||||
|
||||
|
||||
class ButtonTest(unittest.TestCase):
|
||||
class ButtonTest(unittest.TestCase, ExtraAssertions):
|
||||
|
||||
def test_click_ok(self):
|
||||
d = dialog
|
||||
|
@ -98,8 +99,8 @@ class ButtonTest(unittest.TestCase):
|
|||
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):
|
||||
|
|
|
@ -9,6 +9,7 @@ from textwrap import dedent
|
|||
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 @@ class DebuggerGuiTest(unittest.TestCase):
|
|||
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 @@ class StackViewerTest(unittest.TestCase):
|
|||
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.
|
||||
|
|
|
@ -8,6 +8,7 @@ Currently only test grep_it, coverage 51%.
|
|||
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 @@ class FindfilesTest(unittest.TestCase):
|
|||
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 @@ class Grep_itTest(unittest.TestCase):
|
|||
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):
|
||||
|
|
|
@ -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 @@ class MultiCallTest(unittest.TestCase):
|
|||
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)
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ HelpSource htests. These are run by running query.py.
|
|||
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 @@ class SectionNameTest(unittest.TestCase):
|
|||
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 @@ class ModuleNameTest(unittest.TestCase):
|
|||
|
||||
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 @@ class SectionnameGuiTest(unittest.TestCase):
|
|||
root.destroy()
|
||||
|
||||
|
||||
class ModulenameGuiTest(unittest.TestCase):
|
||||
class ModulenameGuiTest(unittest.TestCase, ExtraAssertions):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
@ -389,7 +390,7 @@ class ModulenameGuiTest(unittest.TestCase):
|
|||
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()
|
||||
|
||||
|
||||
|
|
|
@ -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 @@ class InitCloseTest(unittest.TestCase):
|
|||
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):
|
||||
|
|
|
@ -5,8 +5,8 @@ import sys
|
|||
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 @@ class LineNumbersTest(unittest.TestCase):
|
|||
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 @@ class ShellSidebarTest(unittest.TestCase):
|
|||
|
||||
@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 @@ class ShellSidebarTest(unittest.TestCase):
|
|||
|
||||
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 @@ class ShellSidebarTest(unittest.TestCase):
|
|||
|
||||
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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue