ยปCore Development>Code coverage>Lib/idlelib/idle_test/test_editmenu.py

Python code coverage for Lib/idlelib/idle_test/test_editmenu.py

#countcontent
1n/a'''Test (selected) IDLE Edit menu items.
2n/a
3n/aEdit modules have their own test files files
4n/a'''
5n/afrom test.support import requires
6n/arequires('gui')
7n/aimport tkinter as tk
8n/afrom tkinter import ttk
9n/aimport unittest
10n/afrom idlelib import pyshell
11n/a
12n/aclass PasteTest(unittest.TestCase):
13n/a '''Test pasting into widgets that allow pasting.
14n/a
15n/a On X11, replacing selections requires tk fix.
16n/a '''
17n/a @classmethod
18n/a def setUpClass(cls):
19n/a cls.root = root = tk.Tk()
20n/a cls.root.withdraw()
21n/a pyshell.fix_x11_paste(root)
22n/a cls.text = tk.Text(root)
23n/a cls.entry = tk.Entry(root)
24n/a cls.tentry = ttk.Entry(root)
25n/a cls.spin = tk.Spinbox(root)
26n/a root.clipboard_clear()
27n/a root.clipboard_append('two')
28n/a
29n/a @classmethod
30n/a def tearDownClass(cls):
31n/a del cls.text, cls.entry, cls.tentry
32n/a cls.root.clipboard_clear()
33n/a cls.root.update_idletasks()
34n/a cls.root.destroy()
35n/a del cls.root
36n/a
37n/a def test_paste_text(self):
38n/a "Test pasting into text with and without a selection."
39n/a text = self.text
40n/a for tag, ans in ('', 'onetwo\n'), ('sel', 'two\n'):
41n/a with self.subTest(tag=tag, ans=ans):
42n/a text.delete('1.0', 'end')
43n/a text.insert('1.0', 'one', tag)
44n/a text.event_generate('<<Paste>>')
45n/a self.assertEqual(text.get('1.0', 'end'), ans)
46n/a
47n/a def test_paste_entry(self):
48n/a "Test pasting into an entry with and without a selection."
49n/a # Generated <<Paste>> fails for tk entry without empty select
50n/a # range for 'no selection'. Live widget works fine.
51n/a for entry in self.entry, self.tentry:
52n/a for end, ans in (0, 'onetwo'), ('end', 'two'):
53n/a with self.subTest(entry=entry, end=end, ans=ans):
54n/a entry.delete(0, 'end')
55n/a entry.insert(0, 'one')
56n/a entry.select_range(0, end)
57n/a entry.event_generate('<<Paste>>')
58n/a self.assertEqual(entry.get(), ans)
59n/a
60n/a def test_paste_spin(self):
61n/a "Test pasting into a spinbox with and without a selection."
62n/a # See note above for entry.
63n/a spin = self.spin
64n/a for end, ans in (0, 'onetwo'), ('end', 'two'):
65n/a with self.subTest(end=end, ans=ans):
66n/a spin.delete(0, 'end')
67n/a spin.insert(0, 'one')
68n/a spin.selection('range', 0, end) # see note
69n/a spin.event_generate('<<Paste>>')
70n/a self.assertEqual(spin.get(), ans)
71n/a
72n/a
73n/aif __name__ == '__main__':
74n/a unittest.main(verbosity=2)