summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-08-04 16:43:56 (GMT)
committerGitHub <noreply@github.com>2019-08-04 16:43:56 (GMT)
commit1d2b4dba6ccbeb90ef797034b775c0f1ed17d1a0 (patch)
tree5e117b4f3e6038aa469a5c9252fdfca3d3c88784 /Lib/idlelib/idle_test
parentdd5f8abb54923bf2efea51b7a553ca1fca9cad68 (diff)
downloadcpython-1d2b4dba6ccbeb90ef797034b775c0f1ed17d1a0.zip
cpython-1d2b4dba6ccbeb90ef797034b775c0f1ed17d1a0.tar.gz
cpython-1d2b4dba6ccbeb90ef797034b775c0f1ed17d1a0.tar.bz2
bpo-37706: IDLE - fix sidebar code bug and drag tests (GH-15103)
Convert mouse y to line number in the sidebar rather than the text. (cherry picked from commit 86f1a18abfee5939452f468d80de998918e2afd2) Co-authored-by: Tal Einat <taleinat+github@gmail.com>
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r--Lib/idlelib/idle_test/htest.py13
-rw-r--r--Lib/idlelib/idle_test/test_sidebar.py52
2 files changed, 37 insertions, 28 deletions
diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py
index 6990af5..1373b76 100644
--- a/Lib/idlelib/idle_test/htest.py
+++ b/Lib/idlelib/idle_test/htest.py
@@ -210,13 +210,20 @@ _linenumbers_drag_scrolling_spec = {
'file': 'sidebar',
'kwds': {},
'msg': textwrap.dedent("""\
- Click on the line numbers and drag down below the edge of the
+ 1. Click on the line numbers and drag down below the edge of the
window, moving the mouse a bit and then leaving it there for a while.
The text and line numbers should gradually scroll down, with the
selection updated continuously.
- Do the same as above, dragging to above the window. The text and line
+
+ 2. With the lines still selected, click on a line number above the
+ selected lines. Only the line whose number was clicked should be
+ selected.
+
+ 3. Repeat step #1, dragging to above the window. The text and line
numbers should gradually scroll up, with the selection updated
- continuously."""),
+ continuously.
+
+ 4. Repeat step #2, clicking a line number below the selection."""),
}
_multi_call_spec = {
diff --git a/Lib/idlelib/idle_test/test_sidebar.py b/Lib/idlelib/idle_test/test_sidebar.py
index 07e8f2e..0f5b4c7 100644
--- a/Lib/idlelib/idle_test/test_sidebar.py
+++ b/Lib/idlelib/idle_test/test_sidebar.py
@@ -240,7 +240,6 @@ class LineNumbersTest(unittest.TestCase):
self.assert_sidebar_n_lines(1)
self.assertEqual(get_width(), 1)
- @unittest.skipIf(platform == 'darwin', 'test tk version dependent')
def test_click_selection(self):
self.linenumber.show_sidebar()
self.text.insert('1.0', 'one\ntwo\nthree\nfour\n')
@@ -254,44 +253,47 @@ class LineNumbersTest(unittest.TestCase):
self.assertEqual(self.get_selection(), ('2.0', '3.0'))
- @unittest.skipIf(platform == 'darwin', 'test tk version dependent')
- def test_drag_selection_down(self):
- self.linenumber.show_sidebar()
- self.text.insert('1.0', 'one\ntwo\nthree\nfour\nfive\n')
- self.root.update()
+ def simulate_drag(self, start_line, end_line):
+ start_x, start_y = self.get_line_screen_position(start_line)
+ end_x, end_y = self.get_line_screen_position(end_line)
- # Drag from the second line to the fourth line.
- start_x, start_y = self.get_line_screen_position(2)
- end_x, end_y = self.get_line_screen_position(4)
self.linenumber.sidebar_text.event_generate('<Button-1>',
x=start_x, y=start_y)
- self.linenumber.sidebar_text.event_generate('<B1-Motion>',
- x=start_x, y=start_y)
- self.linenumber.sidebar_text.event_generate('<B1-Motion>',
- x=end_x, y=end_y)
+ self.root.update()
+
+ def lerp(a, b, steps):
+ """linearly interpolate from a to b (inclusive) in equal steps"""
+ last_step = steps - 1
+ for i in range(steps):
+ yield ((last_step - i) / last_step) * a + (i / last_step) * b
+
+ for x, y in zip(
+ map(int, lerp(start_x, end_x, steps=11)),
+ map(int, lerp(start_y, end_y, steps=11)),
+ ):
+ self.linenumber.sidebar_text.event_generate('<B1-Motion>', x=x, y=y)
+ self.root.update()
+
self.linenumber.sidebar_text.event_generate('<ButtonRelease-1>',
x=end_x, y=end_y)
self.root.update()
+
+ def test_drag_selection_down(self):
+ self.linenumber.show_sidebar()
+ self.text.insert('1.0', 'one\ntwo\nthree\nfour\nfive\n')
+ self.root.update()
+
+ # Drag from the second line to the fourth line.
+ self.simulate_drag(2, 4)
self.assertEqual(self.get_selection(), ('2.0', '5.0'))
- @unittest.skipIf(platform == 'darwin', 'test tk version dependent')
def test_drag_selection_up(self):
self.linenumber.show_sidebar()
self.text.insert('1.0', 'one\ntwo\nthree\nfour\nfive\n')
self.root.update()
# Drag from the fourth line to the second line.
- start_x, start_y = self.get_line_screen_position(4)
- end_x, end_y = self.get_line_screen_position(2)
- self.linenumber.sidebar_text.event_generate('<Button-1>',
- x=start_x, y=start_y)
- self.linenumber.sidebar_text.event_generate('<B1-Motion>',
- x=start_x, y=start_y)
- self.linenumber.sidebar_text.event_generate('<B1-Motion>',
- x=end_x, y=end_y)
- self.linenumber.sidebar_text.event_generate('<ButtonRelease-1>',
- x=end_x, y=end_y)
- self.root.update()
+ self.simulate_drag(4, 2)
self.assertEqual(self.get_selection(), ('2.0', '5.0'))
def test_scroll(self):