Skip to content

bpo-33855: Still more edits and minimal tests for IDLE #7784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/idlelib/autoexpand.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ def getprevword(self):


if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_autoexpand', verbosity=2)
from unittest import main
main('idlelib.idle_test.test_autoexpand', verbosity=2)
8 changes: 5 additions & 3 deletions Lib/idlelib/codecontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def config_timer_event(self):
CodeContext.reload()


if __name__ == "__main__": # pragma: no cover
import unittest
unittest.main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False)
if __name__ == "__main__":
from unittest import main
main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False)

# Add htest.
8 changes: 4 additions & 4 deletions Lib/idlelib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ def dumpCfg(cfg):
print('\nlines = ', line, ', crc = ', crc, sep='')

if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_config',
verbosity=2, exit=False)
#_dump()
from unittest import main
main('idlelib.idle_test.test_config', verbosity=2, exit=False)

# Run revised _dump() as htest?
4 changes: 2 additions & 2 deletions Lib/idlelib/config_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ def bind_ok(self, keys):


if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_config_key', verbosity=2, exit=False)
from unittest import main
main('idlelib.idle_test.test_config_key', verbosity=2, exit=False)

from idlelib.idle_test.htest import run
run(GetKeysDialog)
6 changes: 3 additions & 3 deletions Lib/idlelib/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2269,8 +2269,8 @@ def _configure_canvas(event):


if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_configdialog',
verbosity=2, exit=False)
from unittest import main
main('idlelib.idle_test.test_configdialog', verbosity=2, exit=False)

from idlelib.idle_test.htest import run
run(ConfigDialog)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_codecontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from idlelib import codecontext
import unittest
from unittest import mock
from test.support import requires
from tkinter import Tk, Frame, Text, TclError

from unittest import mock
import re
from idlelib import config

Expand Down
30 changes: 30 additions & 0 deletions Lib/idlelib/idle_test/test_rpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"Test rpc, coverage 20%."

from idlelib import rpc
import unittest

import marshal


class CodePicklerTest(unittest.TestCase):

def test_pickle_unpickle(self):
def f(): return a + b + c
func, (cbytes,) = rpc.pickle_code(f.__code__)
self.assertIs(func, rpc.unpickle_code)
self.assertIn(b'test_rpc.py', cbytes)
code = rpc.unpickle_code(cbytes)
self.assertEqual(code.co_names, ('a', 'b', 'c'))

def test_code_pickler(self):
self.assertIn(type((lambda:None).__code__),
rpc.CodePickler.dispatch_table)

def test_dumps(self):
def f(): pass
# The main test here is that pickling code does not raise.
self.assertIn(b'test_rpc.py', rpc.dumps(f.__code__))


if __name__ == '__main__':
unittest.main(verbosity=2)
20 changes: 12 additions & 8 deletions Lib/idlelib/idle_test/test_rstrip.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"Test rstrip, coverage 100%."

from idlelib import rstrip
import unittest
import idlelib.rstrip as rs
from idlelib.idle_test.mock_idle import Editor

class rstripTest(unittest.TestCase):

def test_rstrip_line(self):
editor = Editor()
text = editor.text
do_rstrip = rs.RstripExtension(editor).do_rstrip
do_rstrip = rstrip.RstripExtension(editor).do_rstrip

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

def test_rstrip_multiple(self):
editor = Editor()
# Uncomment following to verify that test passes with real widgets.
## from idlelib.editor import EditorWindow as Editor
## from tkinter import Tk
## editor = Editor(root=Tk())
# Comment above, uncomment 3 below to test with real Editor & Text.
#from idlelib.editor import EditorWindow as Editor
#from tkinter import Tk
#editor = Editor(root=Tk())
text = editor.text
do_rstrip = rs.RstripExtension(editor).do_rstrip
do_rstrip = rstrip.RstripExtension(editor).do_rstrip

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



if __name__ == '__main__':
unittest.main(verbosity=2, exit=False)
unittest.main(verbosity=2)
33 changes: 33 additions & 0 deletions Lib/idlelib/idle_test/test_runscript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"Test runscript, coverage 16%."

from idlelib import runscript
import unittest
from test.support import requires
from tkinter import Tk
from idlelib.editor import EditorWindow


class ScriptBindingTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()

@classmethod
def tearDownClass(cls):
cls.root.update_idletasks()
for id in cls.root.tk.call('after', 'info'):
cls.root.after_cancel(id) # Need for EditorWindow.
cls.root.destroy()
del cls.root

def test_init(self):
ew = EditorWindow(root=self.root)
sb = runscript.ScriptBinding(ew)
ew._close()


if __name__ == '__main__':
unittest.main(verbosity=2)
10 changes: 4 additions & 6 deletions Lib/idlelib/idle_test/test_scrolledlist.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
''' Test idlelib.scrolledlist.
"Test scrolledlist, coverage 38%."

Coverage: 39%
'''
from idlelib import scrolledlist
from idlelib.scrolledlist import ScrolledList
import unittest
from test.support import requires
requires('gui')
import unittest
from tkinter import Tk


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


def test_init(self):
scrolledlist.ScrolledList(self.root)
ScrolledList(self.root)


if __name__ == '__main__':
Expand Down
26 changes: 12 additions & 14 deletions Lib/idlelib/idle_test/test_search.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
"""Test SearchDialog class in idlelib.search.py"""
"Test search, coverage 69%."

from idlelib import search
import unittest
from test.support import requires
requires('gui')
from tkinter import Tk, Text, BooleanVar
from idlelib import searchengine

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

from test.support import requires
requires('gui')

import unittest
import tkinter as tk
from tkinter import BooleanVar
import idlelib.searchengine as se
import idlelib.search as sd


class SearchDialogTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.root = tk.Tk()
cls.root = Tk()

@classmethod
def tearDownClass(cls):
cls.root.destroy()
del cls.root

def setUp(self):
self.engine = se.SearchEngine(self.root)
self.dialog = sd.SearchDialog(self.root, self.engine)
self.engine = searchengine.SearchEngine(self.root)
self.dialog = search.SearchDialog(self.root, self.engine)
self.dialog.bell = lambda: None
self.text = tk.Text(self.root)
self.text = Text(self.root)
self.text.insert('1.0', 'Hello World!')

def test_find_again(self):
Expand Down
8 changes: 4 additions & 4 deletions Lib/idlelib/idle_test/test_searchbase.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'''tests idlelib.searchbase.
"Test searchbase, coverage 98%."
# The only thing not covered is inconsequential --
# testing skipping of suite when self.needwrapbutton is false.

Coverage: 99%. The only thing not covered is inconsequential --
testing skipping of suite when self.needwrapbutton is false.
'''
import unittest
from test.support import requires
from tkinter import Tk, Frame ##, BooleanVar, StringVar
Expand All @@ -22,6 +21,7 @@
## se.BooleanVar = BooleanVar
## se.StringVar = StringVar


class SearchDialogBaseTest(unittest.TestCase):

@classmethod
Expand Down
19 changes: 10 additions & 9 deletions Lib/idlelib/idle_test/test_searchengine.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'''Test functions and SearchEngine class in idlelib.searchengine.py.'''
"Test searchengine, coverage 99%."

# With mock replacements, the module does not use any gui widgets.
# The use of tk.Text is avoided (for now, until mock Text is improved)
# by patching instances with an index function returning what is needed.
# This works because mock Text.get does not use .index.

import re
from idlelib import searchengine as se
import unittest
# from test.support import requires
from tkinter import BooleanVar, StringVar, TclError # ,Tk, Text
import tkinter.messagebox as tkMessageBox
from idlelib import searchengine as se
from idlelib.idle_test.mock_tk import Var, Mbox
from idlelib.idle_test.mock_tk import Text as mockText
import re

# With mock replacements, the module does not use any gui widgets.
# The use of tk.Text is avoided (for now, until mock Text is improved)
# by patching instances with an index function returning what is needed.
# This works because mock Text.get does not use .index.
# The tkinter imports are used to restore searchengine.

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


if __name__ == '__main__':
unittest.main(verbosity=2, exit=2)
unittest.main(verbosity=2)
36 changes: 36 additions & 0 deletions Lib/idlelib/idle_test/test_stackviewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"Test stackviewer, coverage 19%."

from idlelib import stackviewer
import unittest
from test.support import requires
from tkinter import Tk


class Test(unittest.TestCase):

@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()

@classmethod
def tearDownClass(cls):
cls.root.update_idletasks()
## for id in cls.root.tk.call('after', 'info'):
## cls.root.after_cancel(id) # Need for EditorWindow.
cls.root.destroy()
del cls.root

def test_init(self):
try:
zzz
except NameError as e:
ex = e
# Test runners suppress setting of sys.last_xyx, which stackviewer needs.
# Revise stackviewer so following works.
# stackviewer.StackBrowser(self.root, ex=exc)


if __name__ == '__main__':
unittest.main(verbosity=2)
41 changes: 41 additions & 0 deletions Lib/idlelib/idle_test/test_statusbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"Test statusbar, coverage 100%."

from idlelib import statusbar
import unittest
from test.support import requires
from tkinter import Tk


class Test(unittest.TestCase):

@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()

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

def test_init(self):
bar = statusbar.MultiStatusBar(self.root)
self.assertEqual(bar.labels, {})

def test_set_label(self):
bar = statusbar.MultiStatusBar(self.root)
bar.set_label('left', text='sometext', width=10)
self.assertIn('left', bar.labels)
left = bar.labels['left']
self.assertEqual(left['text'], 'sometext')
self.assertEqual(left['width'], 10)
bar.set_label('left', text='revised text')
self.assertEqual(left['text'], 'revised text')
bar.set_label('right', text='correct text')
self.assertEqual(bar.labels['right']['text'], 'correct text')


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