Skip to content
Open
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
23 changes: 17 additions & 6 deletions Lib/idlelib/idle_test/test_calltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import types
import re
from idlelib.idle_test.mock_tk import Text
from test.support import MISSING_C_DOCSTRINGS
from test.support import MISSING_C_DOCSTRINGS, requires_docstrings


# Test Class TC is used in multiple get_argspec test methods
Expand Down Expand Up @@ -51,8 +51,7 @@ class Get_argspecTest(unittest.TestCase):
# but a red buildbot is better than a user crash (as has happened).
# For a simple mismatch, change the expected output to the actual.

@unittest.skipIf(MISSING_C_DOCSTRINGS,
"Signature information for builtins requires docstrings")
@requires_docstrings
def test_builtins(self):

def tiptest(obj, out):
Expand Down Expand Up @@ -131,7 +130,9 @@ def baz(s='a'*100, z='b'*100):
"aaaaaaaaaa')"
sbar = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
"aaaaaaaaaa')\nHello Guido"
"aaaaaaaaaa')"
if bar.__doc__ is not None:
sbar += "\nHello Guido"
sbaz = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
"aaaaaaaaaa', z='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"\
Expand Down Expand Up @@ -188,20 +189,30 @@ def t5(a, b=None, *args, **kw): 'doc'

def test_methods(self):
doc = '\ndoc' if TC.__doc__ is not None else ''
for meth in (TC.t1, TC.t2, TC.t3, TC.t4, TC.t5, TC.t6, TC.__call__):
for meth in (TC.t1, TC.t2, TC.t3, TC.t4, TC.t5, TC.t6):
with self.subTest(meth=meth):
self.assertEqual(get_spec(meth), meth.tip + doc)
self.assertEqual(get_spec(TC.cm), "(a)" + doc)
self.assertEqual(get_spec(TC.sm), "(b)" + doc)
# __call__ inherits object.__call__'s docstring when its own is
# missing (build without docstrings or run with -OO).
call_doc = doc or ('\n' + object.__call__.__doc__
if object.__call__.__doc__ else '')
self.assertEqual(get_spec(TC.__call__), TC.__call__.tip + call_doc)

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.t6, "(self)"),
(tc, '(ci)'), (TC.cm, "(a)"),):
with self.subTest(meth=meth, mtip=mtip):
self.assertEqual(get_spec(meth), mtip + doc)
# __call__ inherits object.__call__'s docstring when its own is
# missing (build without docstrings or run with -OO).
call_doc = doc or ('\n' + object.__call__.__doc__
if object.__call__.__doc__ else '')
self.assertEqual(get_spec(tc.__call__), '(ci)' + call_doc)

def test_starred_parameter(self):
# test that starred first parameter is *not* removed from argspec
Expand Down
28 changes: 16 additions & 12 deletions Lib/idlelib/idle_test/test_pyparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def test_set_code(self):
setcode = p.set_code

# Not empty and doesn't end with newline.
with self.assertRaises(AssertionError):
setcode('a')
if __debug__: # Assertions are removed with -O.
with self.assertRaises(AssertionError):
setcode('a')

tests = ('',
'a\n')
Expand Down Expand Up @@ -131,8 +132,9 @@ def test_set_lo(self):
p.set_code(code)

# Previous character is not a newline.
with self.assertRaises(AssertionError):
p.set_lo(5)
if __debug__: # Assertions are removed with -O.
with self.assertRaises(AssertionError):
p.set_lo(5)

# A value of 0 doesn't change self.code.
p.set_lo(0)
Expand Down Expand Up @@ -326,9 +328,10 @@ def test_compute_bracket_indent(self):
)

# Must be C_BRACKET continuation type.
setcode('def function1(self, a, b):\n')
with self.assertRaises(AssertionError):
indent()
if __debug__: # Assertions are removed with -O.
setcode('def function1(self, a, b):\n')
with self.assertRaises(AssertionError):
indent()

for test in tests:
setcode(test.string)
Expand All @@ -345,11 +348,12 @@ def test_compute_backslash_indent(self):
(' """ (\\\n'), # Docstring.
('a = #\\\n'), # Inline comment.
)
for string in errors:
with self.subTest(string=string):
setcode(string)
with self.assertRaises(AssertionError):
indent()
if __debug__: # Assertions are removed with -O.
for string in errors:
with self.subTest(string=string):
setcode(string)
with self.assertRaises(AssertionError):
indent()

TestInfo = namedtuple('TestInfo', ('string', 'spaces'))
tests = (TestInfo('a = (1 + 2) - 5 *\\\n', 4),
Expand Down
3 changes: 2 additions & 1 deletion Lib/idlelib/idle_test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ def test_default_recursion_limit_preserved(self):

def test_fixdoc(self):
# Put here until better place for miscellaneous test.
def func(): "docstring"
def func(): pass
func.__doc__ = "docstring"
run.fixdoc(func, "more")
self.assertEqual(func.__doc__, "docstring\n\nmore")
func.__doc__ = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make IDLE tests pass when running with ``-O`` or ``-OO`` or without
docstrings.
Loading