Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4d92158

Browse files
authoredJun 19, 2018
bpo-33855: Still more edits and minimal tests for IDLE (pythonGH-7784)
Part 3 of 3, continuing PR python#7689. This covers 14 idlelib modules and their tests, rpc to zoomheight except for run (already done) and tooltip (being done separately).
1 parent 00f9edb commit 4d92158

36 files changed

+356
-95
lines changed
 

‎Lib/idlelib/autoexpand.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ def getprevword(self):
9292

9393

9494
if __name__ == '__main__':
95-
import unittest
96-
unittest.main('idlelib.idle_test.test_autoexpand', verbosity=2)
95+
from unittest import main
96+
main('idlelib.idle_test.test_autoexpand', verbosity=2)

‎Lib/idlelib/codecontext.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ def config_timer_event(self):
233233
CodeContext.reload()
234234

235235

236-
if __name__ == "__main__": # pragma: no cover
237-
import unittest
238-
unittest.main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False)
236+
if __name__ == "__main__":
237+
from unittest import main
238+
main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False)
239+
240+
# Add htest.

‎Lib/idlelib/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ def dumpCfg(cfg):
925925
print('\nlines = ', line, ', crc = ', crc, sep='')
926926

927927
if __name__ == '__main__':
928-
import unittest
929-
unittest.main('idlelib.idle_test.test_config',
930-
verbosity=2, exit=False)
931-
#_dump()
928+
from unittest import main
929+
main('idlelib.idle_test.test_config', verbosity=2, exit=False)
930+
931+
# Run revised _dump() as htest?

‎Lib/idlelib/config_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ def bind_ok(self, keys):
291291

292292

293293
if __name__ == '__main__':
294-
import unittest
295-
unittest.main('idlelib.idle_test.test_config_key', verbosity=2, exit=False)
294+
from unittest import main
295+
main('idlelib.idle_test.test_config_key', verbosity=2, exit=False)
296296

297297
from idlelib.idle_test.htest import run
298298
run(GetKeysDialog)

‎Lib/idlelib/configdialog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,8 +2269,8 @@ def _configure_canvas(event):
22692269

22702270

22712271
if __name__ == '__main__':
2272-
import unittest
2273-
unittest.main('idlelib.idle_test.test_configdialog',
2274-
verbosity=2, exit=False)
2272+
from unittest import main
2273+
main('idlelib.idle_test.test_configdialog', verbosity=2, exit=False)
2274+
22752275
from idlelib.idle_test.htest import run
22762276
run(ConfigDialog)

‎Lib/idlelib/idle_test/test_codecontext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from idlelib import codecontext
44
import unittest
5-
from unittest import mock
65
from test.support import requires
76
from tkinter import Tk, Frame, Text, TclError
87

8+
from unittest import mock
99
import re
1010
from idlelib import config
1111

‎Lib/idlelib/idle_test/test_rpc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"Test rpc, coverage 20%."
2+
3+
from idlelib import rpc
4+
import unittest
5+
6+
import marshal
7+
8+
9+
class CodePicklerTest(unittest.TestCase):
10+
11+
def test_pickle_unpickle(self):
12+
def f(): return a + b + c
13+
func, (cbytes,) = rpc.pickle_code(f.__code__)
14+
self.assertIs(func, rpc.unpickle_code)
15+
self.assertIn(b'test_rpc.py', cbytes)
16+
code = rpc.unpickle_code(cbytes)
17+
self.assertEqual(code.co_names, ('a', 'b', 'c'))
18+
19+
def test_code_pickler(self):
20+
self.assertIn(type((lambda:None).__code__),
21+
rpc.CodePickler.dispatch_table)
22+
23+
def test_dumps(self):
24+
def f(): pass
25+
# The main test here is that pickling code does not raise.
26+
self.assertIn(b'test_rpc.py', rpc.dumps(f.__code__))
27+
28+
29+
if __name__ == '__main__':
30+
unittest.main(verbosity=2)

‎Lib/idlelib/idle_test/test_rstrip.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
"Test rstrip, coverage 100%."
2+
3+
from idlelib import rstrip
14
import unittest
2-
import idlelib.rstrip as rs
35
from idlelib.idle_test.mock_idle import Editor
46

57
class rstripTest(unittest.TestCase):
68

79
def test_rstrip_line(self):
810
editor = Editor()
911
text = editor.text
10-
do_rstrip = rs.RstripExtension(editor).do_rstrip
12+
do_rstrip = rstrip.RstripExtension(editor).do_rstrip
1113

1214
do_rstrip()
1315
self.assertEqual(text.get('1.0', 'insert'), '')
@@ -20,12 +22,12 @@ def test_rstrip_line(self):
2022

2123
def test_rstrip_multiple(self):
2224
editor = Editor()
23-
# Uncomment following to verify that test passes with real widgets.
24-
## from idlelib.editor import EditorWindow as Editor
25-
## from tkinter import Tk
26-
## editor = Editor(root=Tk())
25+
# Comment above, uncomment 3 below to test with real Editor & Text.
26+
#from idlelib.editor import EditorWindow as Editor
27+
#from tkinter import Tk
28+
#editor = Editor(root=Tk())
2729
text = editor.text
28-
do_rstrip = rs.RstripExtension(editor).do_rstrip
30+
do_rstrip = rstrip.RstripExtension(editor).do_rstrip
2931

3032
original = (
3133
"Line with an ending tab \n"
@@ -45,5 +47,7 @@ def test_rstrip_multiple(self):
4547
do_rstrip()
4648
self.assertEqual(text.get('1.0', 'insert'), stripped)
4749

50+
51+
4852
if __name__ == '__main__':
49-
unittest.main(verbosity=2, exit=False)
53+
unittest.main(verbosity=2)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"Test runscript, coverage 16%."
2+
3+
from idlelib import runscript
4+
import unittest
5+
from test.support import requires
6+
from tkinter import Tk
7+
from idlelib.editor import EditorWindow
8+
9+
10+
class ScriptBindingTest(unittest.TestCase):
11+
12+
@classmethod
13+
def setUpClass(cls):
14+
requires('gui')
15+
cls.root = Tk()
16+
cls.root.withdraw()
17+
18+
@classmethod
19+
def tearDownClass(cls):
20+
cls.root.update_idletasks()
21+
for id in cls.root.tk.call('after', 'info'):
22+
cls.root.after_cancel(id) # Need for EditorWindow.
23+
cls.root.destroy()
24+
del cls.root
25+
26+
def test_init(self):
27+
ew = EditorWindow(root=self.root)
28+
sb = runscript.ScriptBinding(ew)
29+
ew._close()
30+
31+
32+
if __name__ == '__main__':
33+
unittest.main(verbosity=2)

‎Lib/idlelib/idle_test/test_scrolledlist.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
''' Test idlelib.scrolledlist.
1+
"Test scrolledlist, coverage 38%."
22

3-
Coverage: 39%
4-
'''
5-
from idlelib import scrolledlist
3+
from idlelib.scrolledlist import ScrolledList
4+
import unittest
65
from test.support import requires
76
requires('gui')
8-
import unittest
97
from tkinter import Tk
108

119

@@ -22,7 +20,7 @@ def tearDownClass(cls):
2220

2321

2422
def test_init(self):
25-
scrolledlist.ScrolledList(self.root)
23+
ScrolledList(self.root)
2624

2725

2826
if __name__ == '__main__':

‎Lib/idlelib/idle_test/test_search.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
"""Test SearchDialog class in idlelib.search.py"""
1+
"Test search, coverage 69%."
2+
3+
from idlelib import search
4+
import unittest
5+
from test.support import requires
6+
requires('gui')
7+
from tkinter import Tk, Text, BooleanVar
8+
from idlelib import searchengine
29

310
# Does not currently test the event handler wrappers.
411
# A usage test should simulate clicks and check highlighting.
512
# Tests need to be coordinated with SearchDialogBase tests
613
# to avoid duplication.
714

8-
from test.support import requires
9-
requires('gui')
10-
11-
import unittest
12-
import tkinter as tk
13-
from tkinter import BooleanVar
14-
import idlelib.searchengine as se
15-
import idlelib.search as sd
16-
1715

1816
class SearchDialogTest(unittest.TestCase):
1917

2018
@classmethod
2119
def setUpClass(cls):
22-
cls.root = tk.Tk()
20+
cls.root = Tk()
2321

2422
@classmethod
2523
def tearDownClass(cls):
2624
cls.root.destroy()
2725
del cls.root
2826

2927
def setUp(self):
30-
self.engine = se.SearchEngine(self.root)
31-
self.dialog = sd.SearchDialog(self.root, self.engine)
28+
self.engine = searchengine.SearchEngine(self.root)
29+
self.dialog = search.SearchDialog(self.root, self.engine)
3230
self.dialog.bell = lambda: None
33-
self.text = tk.Text(self.root)
31+
self.text = Text(self.root)
3432
self.text.insert('1.0', 'Hello World!')
3533

3634
def test_find_again(self):

‎Lib/idlelib/idle_test/test_searchbase.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
'''tests idlelib.searchbase.
1+
"Test searchbase, coverage 98%."
2+
# The only thing not covered is inconsequential --
3+
# testing skipping of suite when self.needwrapbutton is false.
24

3-
Coverage: 99%. The only thing not covered is inconsequential --
4-
testing skipping of suite when self.needwrapbutton is false.
5-
'''
65
import unittest
76
from test.support import requires
87
from tkinter import Tk, Frame ##, BooleanVar, StringVar
@@ -22,6 +21,7 @@
2221
## se.BooleanVar = BooleanVar
2322
## se.StringVar = StringVar
2423

24+
2525
class SearchDialogBaseTest(unittest.TestCase):
2626

2727
@classmethod

‎Lib/idlelib/idle_test/test_searchengine.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
'''Test functions and SearchEngine class in idlelib.searchengine.py.'''
1+
"Test searchengine, coverage 99%."
22

3-
# With mock replacements, the module does not use any gui widgets.
4-
# The use of tk.Text is avoided (for now, until mock Text is improved)
5-
# by patching instances with an index function returning what is needed.
6-
# This works because mock Text.get does not use .index.
7-
8-
import re
3+
from idlelib import searchengine as se
94
import unittest
105
# from test.support import requires
116
from tkinter import BooleanVar, StringVar, TclError # ,Tk, Text
127
import tkinter.messagebox as tkMessageBox
13-
from idlelib import searchengine as se
148
from idlelib.idle_test.mock_tk import Var, Mbox
159
from idlelib.idle_test.mock_tk import Text as mockText
10+
import re
11+
12+
# With mock replacements, the module does not use any gui widgets.
13+
# The use of tk.Text is avoided (for now, until mock Text is improved)
14+
# by patching instances with an index function returning what is needed.
15+
# This works because mock Text.get does not use .index.
16+
# The tkinter imports are used to restore searchengine.
1617

1718
def setUpModule():
1819
# Replace s-e module tkinter imports other than non-gui TclError.
@@ -326,4 +327,4 @@ def test_search_backward(self):
326327

327328

328329
if __name__ == '__main__':
329-
unittest.main(verbosity=2, exit=2)
330+
unittest.main(verbosity=2)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"Test stackviewer, coverage 19%."
2+
3+
from idlelib import stackviewer
4+
import unittest
5+
from test.support import requires
6+
from tkinter import Tk
7+
8+
9+
class Test(unittest.TestCase):
10+
11+
@classmethod
12+
def setUpClass(cls):
13+
requires('gui')
14+
cls.root = Tk()
15+
cls.root.withdraw()
16+
17+
@classmethod
18+
def tearDownClass(cls):
19+
cls.root.update_idletasks()
20+
## for id in cls.root.tk.call('after', 'info'):
21+
## cls.root.after_cancel(id) # Need for EditorWindow.
22+
cls.root.destroy()
23+
del cls.root
24+
25+
def test_init(self):
26+
try:
27+
zzz
28+
except NameError as e:
29+
ex = e
30+
# Test runners suppress setting of sys.last_xyx, which stackviewer needs.
31+
# Revise stackviewer so following works.
32+
# stackviewer.StackBrowser(self.root, ex=exc)
33+
34+
35+
if __name__ == '__main__':
36+
unittest.main(verbosity=2)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"Test statusbar, coverage 100%."
2+
3+
from idlelib import statusbar
4+
import unittest
5+
from test.support import requires
6+
from tkinter import Tk
7+
8+
9+
class Test(unittest.TestCase):
10+
11+
@classmethod
12+
def setUpClass(cls):
13+
requires('gui')
14+
cls.root = Tk()
15+
cls.root.withdraw()
16+
17+
@classmethod
18+
def tearDownClass(cls):
19+
cls.root.update_idletasks()
20+
cls.root.destroy()
21+
del cls.root
22+
23+
def test_init(self):
24+
bar = statusbar.MultiStatusBar(self.root)
25+
self.assertEqual(bar.labels, {})
26+
27+
def test_set_label(self):
28+
bar = statusbar.MultiStatusBar(self.root)
29+
bar.set_label('left', text='sometext', width=10)
30+
self.assertIn('left', bar.labels)
31+
left = bar.labels['left']
32+
self.assertEqual(left['text'], 'sometext')
33+
self.assertEqual(left['width'], 10)
34+
bar.set_label('left', text='revised text')
35+
self.assertEqual(left['text'], 'revised text')
36+
bar.set_label('right', text='correct text')
37+
self.assertEqual(bar.labels['right']['text'], 'correct text')
38+
39+
40+
if __name__ == '__main__':
41+
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)
Please sign in to comment.