$54 GRAYBYTE WORDPRESS FILE MANAGER $22

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python37/lib64/python3.7/idlelib/idle_test/

HOME
Current File : /opt/alt/python37/lib64/python3.7/idlelib/idle_test//test_config_key.py
"""Test config_key, coverage 98%.

Coverage is effectively 100%.  Tkinter dialog is mocked, Mac-only line
may be skipped, and dummy function in bind test should not be called.
Not tested: exit with 'self.advanced or self.keys_ok(keys)) ...' False.
"""

from idlelib import config_key
from test.support import requires
import unittest
from unittest import mock
from tkinter import Tk, TclError
from idlelib.idle_test.mock_idle import Func
from idlelib.idle_test.mock_tk import Mbox_func

gkd = config_key.GetKeysDialog


class ValidationTest(unittest.TestCase):
    "Test validation methods: ok, keys_ok, bind_ok."

    class Validator(gkd):
        def __init__(self, *args, **kwargs):
            config_key.GetKeysDialog.__init__(self, *args, **kwargs)
            class list_keys_final:
                get = Func()
            self.list_keys_final = list_keys_final
        get_modifiers = Func()
        showerror = Mbox_func()

    @classmethod
    def setUpClass(cls):
        requires('gui')
        cls.root = Tk()
        cls.root.withdraw()
        keylist = [['<Key-F12>'], ['<Control-Key-x>', '<Control-Key-X>']]
        cls.dialog = cls.Validator(
            cls.root, 'Title', '<<Test>>', keylist, _utest=True)

    @classmethod
    def tearDownClass(cls):
        cls.dialog.cancel()
        cls.root.update_idletasks()
        cls.root.destroy()
        del cls.dialog, cls.root

    def setUp(self):
        self.dialog.showerror.message = ''
    # A test that needs a particular final key value should set it.
    # A test that sets a non-blank modifier list should reset it to [].

    def test_ok_empty(self):
        self.dialog.key_string.set(' ')
        self.dialog.ok()
        self.assertEqual(self.dialog.result, '')
        self.assertEqual(self.dialog.showerror.message, 'No key specified.')

    def test_ok_good(self):
        self.dialog.key_string.set('<Key-F11>')
        self.dialog.list_keys_final.get.result = 'F11'
        self.dialog.ok()
        self.assertEqual(self.dialog.result, '<Key-F11>')
        self.assertEqual(self.dialog.showerror.message, '')

    def test_keys_no_ending(self):
        self.assertFalse(self.dialog.keys_ok('<Control-Shift'))
        self.assertIn('Missing the final', self.dialog.showerror.message)

    def test_keys_no_modifier_bad(self):
        self.dialog.list_keys_final.get.result = 'A'
        self.assertFalse(self.dialog.keys_ok('<Key-A>'))
        self.assertIn('No modifier', self.dialog.showerror.message)

    def test_keys_no_modifier_ok(self):
        self.dialog.list_keys_final.get.result = 'F11'
        self.assertTrue(self.dialog.keys_ok('<Key-F11>'))
        self.assertEqual(self.dialog.showerror.message, '')

    def test_keys_shift_bad(self):
        self.dialog.list_keys_final.get.result = 'a'
        self.dialog.get_modifiers.result = ['Shift']
        self.assertFalse(self.dialog.keys_ok('<a>'))
        self.assertIn('shift modifier', self.dialog.showerror.message)
        self.dialog.get_modifiers.result = []

    def test_keys_dup(self):
        for mods, final, seq in (([], 'F12', '<Key-F12>'),
                                 (['Control'], 'x', '<Control-Key-x>'),
                                 (['Control'], 'X', '<Control-Key-X>')):
            with self.subTest(m=mods, f=final, s=seq):
                self.dialog.list_keys_final.get.result = final
                self.dialog.get_modifiers.result = mods
                self.assertFalse(self.dialog.keys_ok(seq))
                self.assertIn('already in use', self.dialog.showerror.message)
        self.dialog.get_modifiers.result = []

    def test_bind_ok(self):
        self.assertTrue(self.dialog.bind_ok('<Control-Shift-Key-a>'))
        self.assertEqual(self.dialog.showerror.message, '')

    def test_bind_not_ok(self):
        self.assertFalse(self.dialog.bind_ok('<Control-Shift>'))
        self.assertIn('not accepted', self.dialog.showerror.message)


class ToggleLevelTest(unittest.TestCase):
    "Test toggle between Basic and Advanced frames."

    @classmethod
    def setUpClass(cls):
        requires('gui')
        cls.root = Tk()
        cls.root.withdraw()
        cls.dialog = gkd(cls.root, 'Title', '<<Test>>', [], _utest=True)

    @classmethod
    def tearDownClass(cls):
        cls.dialog.cancel()
        cls.root.update_idletasks()
        cls.root.destroy()
        del cls.dialog, cls.root

    def test_toggle_level(self):
        dialog = self.dialog

        def stackorder():
            """Get the stack order of the children of the frame.

            winfo_children() stores the children in stack order, so
            this can be used to check whether a frame is above or
            below another one.
            """
            for index, child in enumerate(dialog.frame.winfo_children()):
                if child._name == 'keyseq_basic':
                    basic = index
                if child._name == 'keyseq_advanced':
                    advanced = index
            return basic, advanced

        # New window starts at basic level.
        self.assertFalse(dialog.advanced)
        self.assertIn('Advanced', dialog.button_level['text'])
        basic, advanced = stackorder()
        self.assertGreater(basic, advanced)

        # Toggle to advanced.
        dialog.toggle_level()
        self.assertTrue(dialog.advanced)
        self.assertIn('Basic', dialog.button_level['text'])
        basic, advanced = stackorder()
        self.assertGreater(advanced, basic)

        # Toggle to basic.
        dialog.button_level.invoke()
        self.assertFalse(dialog.advanced)
        self.assertIn('Advanced', dialog.button_level['text'])
        basic, advanced = stackorder()
        self.assertGreater(basic, advanced)


class KeySelectionTest(unittest.TestCase):
    "Test selecting key on Basic frames."

    class Basic(gkd):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            class list_keys_final:
                get = Func()
                select_clear = Func()
                yview = Func()
            self.list_keys_final = list_keys_final
        def set_modifiers_for_platform(self):
            self.modifiers = ['foo', 'bar', 'BAZ']
            self.modifier_label = {'BAZ': 'ZZZ'}
        showerror = Mbox_func()

    @classmethod
    def setUpClass(cls):
        requires('gui')
        cls.root = Tk()
        cls.root.withdraw()
        cls.dialog = cls.Basic(cls.root, 'Title', '<<Test>>', [], _utest=True)

    @classmethod
    def tearDownClass(cls):
        cls.dialog.cancel()
        cls.root.update_idletasks()
        cls.root.destroy()
        del cls.dialog, cls.root

    def setUp(self):
        self.dialog.clear_key_seq()

    def test_get_modifiers(self):
        dialog = self.dialog
        gm = dialog.get_modifiers
        eq = self.assertEqual

        # Modifiers are set on/off by invoking the checkbutton.
        dialog.modifier_checkbuttons['foo'].invoke()
        eq(gm(), ['foo'])

        dialog.modifier_checkbuttons['BAZ'].invoke()
        eq(gm(), ['foo', 'BAZ'])

        dialog.modifier_checkbuttons['foo'].invoke()
        eq(gm(), ['BAZ'])

    @mock.patch.object(gkd, 'get_modifiers')
    def test_build_key_string(self, mock_modifiers):
        dialog = self.dialog
        key = dialog.list_keys_final
        string = dialog.key_string.get
        eq = self.assertEqual

        key.get.result = 'a'
        mock_modifiers.return_value = []
        dialog.build_key_string()
        eq(string(), '<Key-a>')

        mock_modifiers.return_value = ['mymod']
        dialog.build_key_string()
        eq(string(), '<mymod-Key-a>')

        key.get.result = ''
        mock_modifiers.return_value = ['mymod', 'test']
        dialog.build_key_string()
        eq(string(), '<mymod-test>')

    @mock.patch.object(gkd, 'get_modifiers')
    def test_final_key_selected(self, mock_modifiers):
        dialog = self.dialog
        key = dialog.list_keys_final
        string = dialog.key_string.get
        eq = self.assertEqual

        mock_modifiers.return_value = ['Shift']
        key.get.result = '{'
        dialog.final_key_selected()
        eq(string(), '<Shift-Key-braceleft>')


class CancelTest(unittest.TestCase):
    "Simulate user clicking [Cancel] button."

    @classmethod
    def setUpClass(cls):
        requires('gui')
        cls.root = Tk()
        cls.root.withdraw()
        cls.dialog = gkd(cls.root, 'Title', '<<Test>>', [], _utest=True)

    @classmethod
    def tearDownClass(cls):
        cls.dialog.cancel()
        cls.root.update_idletasks()
        cls.root.destroy()
        del cls.dialog, cls.root

    def test_cancel(self):
        self.assertEqual(self.dialog.winfo_class(), 'Toplevel')
        self.dialog.button_cancel.invoke()
        with self.assertRaises(TclError):
            self.dialog.winfo_class()
        self.assertEqual(self.dialog.result, '')


class HelperTest(unittest.TestCase):
    "Test module level helper functions."

    def test_translate_key(self):
        tr = config_key.translate_key
        eq = self.assertEqual

        # Letters return unchanged with no 'Shift'.
        eq(tr('q', []), 'Key-q')
        eq(tr('q', ['Control', 'Alt']), 'Key-q')

        # 'Shift' uppercases single lowercase letters.
        eq(tr('q', ['Shift']), 'Key-Q')
        eq(tr('q', ['Control', 'Shift']), 'Key-Q')
        eq(tr('q', ['Control', 'Alt', 'Shift']), 'Key-Q')

        # Convert key name to keysym.
        eq(tr('Page Up', []), 'Key-Prior')
        # 'Shift' doesn't change case when it's not a single char.
        eq(tr('*', ['Shift']), 'Key-asterisk')


if __name__ == '__main__':
    unittest.main(verbosity=2)

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
13 Aug 2025 1.05 AM
root / 996
0755
__pycache__
--
13 Aug 2025 1.05 AM
root / 996
0755
README.txt
8.524 KB
6 Jun 2023 3.45 AM
root / 996
0644
__init__.py
0.695 KB
18 Apr 2024 12.36 AM
root / 996
0644
htest.py
14.834 KB
18 Apr 2024 12.36 AM
root / 996
0644
mock_idle.py
1.897 KB
18 Apr 2024 12.36 AM
root / 996
0644
mock_tk.py
11.354 KB
18 Apr 2024 12.36 AM
root / 996
0644
template.py
0.627 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_autocomplete.py
10.466 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_autocomplete_w.py
0.692 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_autoexpand.py
4.529 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_browser.py
7.776 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_calltip.py
9.704 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_calltip_w.py
0.67 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_codecontext.py
15.742 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_colorizer.py
14.665 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_config.py
31.295 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_config_key.py
9.481 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_configdialog.py
53.076 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_debugger.py
0.558 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_debugger_r.py
0.616 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_debugobj.py
1.524 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_debugobj_r.py
0.532 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_delegator.py
1.53 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_editmenu.py
2.504 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_editor.py
7.347 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_filelist.py
0.776 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_format.py
23.059 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_grep.py
4.953 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_help.py
0.829 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_help_about.py
5.782 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_history.py
5.388 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_hyperparser.py
8.869 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_iomenu.py
1.248 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_macosx.py
3.231 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_mainmenu.py
0.58 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_multicall.py
1.285 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_outwin.py
5.415 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_parenmatch.py
3.467 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_pathbrowser.py
2.365 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_percolator.py
3.97 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_pyparse.py
18.776 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_pyshell.py
2.12 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_query.py
14.922 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_redirector.py
4.078 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_replace.py
8.11 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_rpc.py
0.786 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_run.py
11.462 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_runscript.py
0.759 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_scrolledlist.py
0.484 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_search.py
2.401 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_searchbase.py
5.503 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_searchengine.py
11.272 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_sidebar.py
12.921 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_squeezer.py
19.617 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_stackviewer.py
1.178 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_statusbar.py
1.106 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_text.py
6.814 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_textview.py
7.191 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_tooltip.py
5.259 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_tree.py
1.711 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_undo.py
4.129 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_warning.py
2.676 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_window.py
1.05 KB
18 Apr 2024 12.36 AM
root / 996
0644
test_zoomheight.py
0.976 KB
18 Apr 2024 12.36 AM
root / 996
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF