summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test/test_calltips.py
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2018-06-15 22:20:55 (GMT)
committerGitHub <noreply@github.com>2018-06-15 22:20:55 (GMT)
commitee5ef309c7e2daef1248730145408f700732c42e (patch)
treeb2de419dbdaf439eacb2295e767882384469d5fe /Lib/idlelib/idle_test/test_calltips.py
parent6c5a4b315664f21bffc36ff6987fb4c4d1590897 (diff)
downloadcpython-ee5ef309c7e2daef1248730145408f700732c42e.zip
cpython-ee5ef309c7e2daef1248730145408f700732c42e.tar.gz
cpython-ee5ef309c7e2daef1248730145408f700732c42e.tar.bz2
bpo-33855: Minimally test all IDLE modules. (GH-7689)
Create a template for minimally testing a tkinter-using module by importing it and instantiating its class(es). Add a test file for all non-startup IDLE modules. Edit existing files and update coverage. This is part 1 of 3, covering the 21 autocomplete to help modules and touching 33 idlelib files.
Diffstat (limited to 'Lib/idlelib/idle_test/test_calltips.py')
-rw-r--r--Lib/idlelib/idle_test/test_calltips.py56
1 files changed, 36 insertions, 20 deletions
diff --git a/Lib/idlelib/idle_test/test_calltips.py b/Lib/idlelib/idle_test/test_calltips.py
index a58229d..2cf0e18 100644
--- a/Lib/idlelib/idle_test/test_calltips.py
+++ b/Lib/idlelib/idle_test/test_calltips.py
@@ -1,9 +1,12 @@
+"Test calltips, coverage 60%"
+
+from idlelib import calltips
import unittest
-import idlelib.calltips as ct
import textwrap
import types
-default_tip = ct._default_callable_argspec
+default_tip = calltips._default_callable_argspec
+
# Test Class TC is used in multiple get_argspec test methods
class TC():
@@ -31,9 +34,11 @@ class TC():
@staticmethod
def sm(b): 'doc'
+
tc = TC()
+signature = calltips.get_argspec # 2.7 and 3.x use different functions
+
-signature = ct.get_argspec # 2.7 and 3.x use different functions
class Get_signatureTest(unittest.TestCase):
# The signature function must return a string, even if blank.
# Test a variety of objects to be sure that none cause it to raise
@@ -54,14 +59,18 @@ class Get_signatureTest(unittest.TestCase):
self.assertEqual(signature(obj), out)
if List.__doc__ is not None:
- gtest(List, '(iterable=(), /)' + ct._argument_positional + '\n' +
- List.__doc__)
+ gtest(List, '(iterable=(), /)' + calltips._argument_positional
+ + '\n' + List.__doc__)
gtest(list.__new__,
- '(*args, **kwargs)\nCreate and return a new object. See help(type) for accurate signature.')
+ '(*args, **kwargs)\n'
+ 'Create and return a new object. '
+ 'See help(type) for accurate signature.')
gtest(list.__init__,
- '(self, /, *args, **kwargs)' + ct._argument_positional + '\n' +
- 'Initialize self. See help(type(self)) for accurate signature.')
- append_doc = ct._argument_positional + "\nAppend object to the end of the list."
+ '(self, /, *args, **kwargs)'
+ + calltips._argument_positional + '\n' +
+ 'Initialize self. See help(type(self)) for accurate signature.')
+ append_doc = (calltips._argument_positional
+ + "\nAppend object to the end of the list.")
gtest(list.append, '(self, object, /)' + append_doc)
gtest(List.append, '(self, object, /)' + append_doc)
gtest([].append, '(object, /)' + append_doc)
@@ -70,12 +79,17 @@ class Get_signatureTest(unittest.TestCase):
gtest(SB(), default_tip)
import re
p = re.compile('')
- gtest(re.sub, '''(pattern, repl, string, count=0, flags=0)\nReturn the string obtained by replacing the leftmost
+ gtest(re.sub, '''\
+(pattern, repl, string, count=0, flags=0)
+Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the Match object and must return''')
- gtest(p.sub, '''(repl, string, count=0)\nReturn the string obtained by replacing the leftmost non-overlapping occurrences o...''')
+ gtest(p.sub, '''\
+(repl, string, count=0)
+Return the string obtained by replacing the leftmost \
+non-overlapping occurrences o...''')
def test_signature_wrap(self):
if textwrap.TextWrapper.__doc__ is not None:
@@ -88,7 +102,7 @@ a callable, it's passed the Match object and must return''')
def test_docline_truncation(self):
def f(): pass
f.__doc__ = 'a'*300
- self.assertEqual(signature(f), '()\n' + 'a' * (ct._MAX_COLS-3) + '...')
+ self.assertEqual(signature(f), '()\n' + 'a' * (calltips._MAX_COLS-3) + '...')
def test_multiline_docstring(self):
# Test fewer lines than max.
@@ -107,7 +121,7 @@ bytes() -> empty bytes object''')
# Test more than max lines
def f(): pass
f.__doc__ = 'a\n' * 15
- self.assertEqual(signature(f), '()' + '\na' * ct._MAX_LINES)
+ self.assertEqual(signature(f), '()' + '\na' * calltips._MAX_LINES)
def test_functions(self):
def t1(): 'doc'
@@ -135,8 +149,9 @@ bytes() -> empty bytes object''')
def test_bound_methods(self):
# test that first parameter is correctly removed from argspec
doc = '\ndoc' if TC.__doc__ is not None else ''
- for meth, mtip in ((tc.t1, "()"), (tc.t4, "(*args)"), (tc.t6, "(self)"),
- (tc.__call__, '(ci)'), (tc, '(ci)'), (TC.cm, "(a)"),):
+ for meth, mtip in ((tc.t1, "()"), (tc.t4, "(*args)"),
+ (tc.t6, "(self)"), (tc.__call__, '(ci)'),
+ (tc, '(ci)'), (TC.cm, "(a)"),):
self.assertEqual(signature(meth), mtip + doc)
def test_starred_parameter(self):
@@ -153,7 +168,7 @@ bytes() -> empty bytes object''')
class Test:
def __call__(*, a): pass
- mtip = ct._invalid_method
+ mtip = calltips._invalid_method
self.assertEqual(signature(C().m2), mtip)
self.assertEqual(signature(Test()), mtip)
@@ -161,7 +176,7 @@ bytes() -> empty bytes object''')
# test that re works to delete a first parameter name that
# includes non-ascii chars, such as various forms of A.
uni = "(A\u0391\u0410\u05d0\u0627\u0905\u1e00\u3042, a)"
- assert ct._first_param.sub('', uni) == '(a)'
+ assert calltips._first_param.sub('', uni) == '(a)'
def test_no_docstring(self):
def nd(s):
@@ -194,9 +209,10 @@ bytes() -> empty bytes object''')
class Get_entityTest(unittest.TestCase):
def test_bad_entity(self):
- self.assertIsNone(ct.get_entity('1/0'))
+ self.assertIsNone(calltips.get_entity('1/0'))
def test_good_entity(self):
- self.assertIs(ct.get_entity('int'), int)
+ self.assertIs(calltips.get_entity('int'), int)
+
if __name__ == '__main__':
- unittest.main(verbosity=2, exit=False)
+ unittest.main(verbosity=2)