Issue2082

classification
Title: Unexpected (Pdb) prompt during regression tests
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jeff.allen Nosy List: jeff.allen
Priority: Keywords:

Created on 2013-09-05.06:39:54 by jeff.allen, last changed 2013-09-16.23:21:05 by jeff.allen.

Messages
msg8099 (view) Author: Jeff Allen (jeff.allen) Date: 2013-09-05.06:39:53
Certain regression tests hang unexpectedly, producing a (Pdb) prompt. The test will continue if you enter an end-of-file (^Z on Windows) which to some tests is a failure.

I noticed this while working on the restructured Jython console, and for a while thought I had induced it, but it is present in the baseline, back to at least tag 2.7b1 and after a clean build. (Regression tests have never run smoothly for me on Windows.)

Affected Python tests are:
test.test_doctest
test.test_pdb
These show up in "ant regrtest". Unsticking the test with ctrl-Z\n is counted as a test failure. It seems that the test function compares the
responses to a "script" of  pdb interactions at a pretended console. The only divergence I can see is an extra blank line at the end.

The only affected Java test is:
org.python.jsr223.ScriptEngineTest

This does not show up in "ant javatest", but only when run as:
>java -cp dist/*;dist/javalib/* org.junit.runner.JUnitCore org.python.jsr223.ScriptEngineTest
And running this with the input piped from NUL (the always-empty stream in Windows) causes it to run to completion, although the (Pdb) prompt still appears.

In the Python tests, typical behaviour is:
>dist\bin\jython -m test.test_doctest
doctest (doctest) ... 66 tests with zero failures
(Pdb)   <--- ctrl-Z  + return entered here
**********************************************************************
File "C:\hg\jython-int\dist\Lib\test\test_doctest.py", line 1758, in test.test_doctest.test_debug
Failed example:
    try: doctest.debug_src(s)
    finally: sys.stdin = real_stdin
Expected:
    > <string>(1)<module>()
    (Pdb) next
    12
    --Return--
    > <string>(1)<module>()->None
    (Pdb) print x
    12
    (Pdb) continue
Got:
    > <string>(1)<module>()
    <BLANKLINE>
(Pdb)

Switching to the plain InteractiveConsole causes the Python tests to run smoothly, but does not affect matters in the Java test.
msg8111 (view) Author: Jeff Allen (jeff.allen) Date: 2013-09-09.22:11:11
Ok, I have to own up to this one. The mechanism of the problem is that these tests replace sys.stdin and sys.stdout, and then call raw_input('(Pdb)') which is supposed to use the replacement streams.

In the present implementation, raw_input(prompt) is handled by the console class directly, so replacing sys.stdin/stdout does not intercept it. This direct delegation happens even with the PlainConsole. I did this so that the console library (JLine or Readline) could be aware of the prompt, which it needs to be in order to position the cursor correctly - one of the things this design fixed.

Prior to my change, the JLineConsole would replace raw_input() with a method it implemented directly, and this is why test_pdb and test_doctest fail the same way in versions before my change. (But they don't fail when the console is InteractiveConsole.) This hijacking was incorrect, and now I've generalised it.

Replacing sys.stdin/stdout is not uncommon in Python, so it should work in Jython as it does in CPython. I'll see what I can do to restore that for all consoles, achieving correct line editing some other way.
msg8116 (view) Author: Jeff Allen (jeff.allen) Date: 2013-09-14.22:51:52
I've fixed this now (and pushed the change set) for test_pdb and test_doctest. I still get the prompt with ScriptEngineTest when run individually under java, but not run as a batch. I'll leave open while I investigate.
msg8119 (view) Author: Jeff Allen (jeff.allen) Date: 2013-09-16.23:21:05
No, that's ok. The (Pdb) prompt is what that script is supposed to do. We just don't see it inside the junit ant target. Compare:

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pdb import set_trace
>>> set_trace()
--Return--
> <stdin>(1)<module>()->None
(Pdb)

Now able to close with a clear conscience. Actual test failures fixed in:
http://hg.python.org/jython/rev/80927ba94032
History
Date User Action Args
2013-09-16 23:21:05jeff.allensetstatus: open -> closed
resolution: fixed
messages: + msg8119
2013-09-14 22:51:53jeff.allensetmessages: + msg8116
2013-09-09 22:11:11jeff.allensetassignee: jeff.allen
messages: + msg8111
2013-09-05 06:39:54jeff.allencreate