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