Skip to content

Commit

Permalink
[3.13] pythongh-71339: Use new assertion methods in test_idle
Browse files Browse the repository at this point in the history
Revise 10 tests in 7 files, with 1 test split into 2.
(cherry picked from commit dbb25ce)

Co-authored-by: Terry Jan Reedy [email protected]
  • Loading branch information
terryjreedy committed Jan 26, 2025
1 parent bcececd commit 53c11b6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
7 changes: 4 additions & 3 deletions Lib/idlelib/idle_test/test_configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions Lib/idlelib/idle_test/test_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions Lib/idlelib/idle_test/test_grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions Lib/idlelib/idle_test/test_multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
11 changes: 6 additions & 5 deletions Lib/idlelib/idle_test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'], '')


Expand Down Expand Up @@ -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):
Expand All @@ -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()


Expand Down
5 changes: 3 additions & 2 deletions Lib/idlelib/idle_test/test_redirector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions Lib/idlelib/idle_test/test_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>>')
Expand All @@ -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')
Expand Down

0 comments on commit 53c11b6

Please sign in to comment.