Skip to content
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

Can't input single newline to process under test #39

Open
aivarannamaa opened this issue Oct 12, 2014 · 5 comments
Open

Can't input single newline to process under test #39

aivarannamaa opened this issue Oct 12, 2014 · 5 comments

Comments

@aivarannamaa
Copy link

When my demo_solution.py is

input()

and demo_tester.py is

from grader import *

@test
def do_test(m):
    m.stdin.put("")

Then python -m grader demo_tester.py demo_solution.py gives me

{
    "success": true,
    "results": [
        {
            "traceback": "Traceback (most recent call last):\n  File \"C:\\Python34\\lib\\site-packages\\grader-0.0.1-py3.4.egg\\grader\\execution_base.py\", line 63, in call_test_function\n    **pre_hook_info[\"extra_kwargs\"]\n  File \"C:\\Python34\\lib\\site-packages\\grader-0.0.1-py3.4.egg\\grader\\core.py\", line 48, in wrapper\n    raise module.caughtException\n  File \"C:\\Python34\\lib\\site-packages\\grader-0.0.1-py3.4.egg\\grader\\program_container.py\", line 38, in run\n    self._exec_code()\n  File \"C:\\Python34\\lib\\site-packages\\grader-0.0.1-py3.4.egg\\grader\\program_container.py\", line 53, in _exec_code\n    exec(code, mod.__dict__)\n  File \"<tested-program>\", line 1, in <module>\nEOFError: EOF when reading a line\n",
            "description": "do_test",
            "error_message": "EOFError: EOF when reading a line",
            "log": [],
            "time": "0.212",
            "success": false
        }
    ]
}

@macobo
Copy link
Owner

macobo commented Oct 12, 2014

Not able to test this at the moment, but I figure this has to do with some assumptions that the built in sys.stdin that we are mocking operates on - it not receiving anything is assumed to be the same as entering EOF.

A workaround for this should be to m.stdin.put("\n") which I would expect to behave much the same.

You can also dig into the python stdio implementation or spec and fix it yourself - I can give you commit access. :)

@aivarannamaa
Copy link
Author

A workaround for this should be to m.stdin.put("\n")

Nope, this results in "\n\n" being sent to stdin.

@macobo
Copy link
Owner

macobo commented Oct 13, 2014

While digging I arrived here - https://github.com/akheron/cpython/blob/d04cd9a21a22a56ec3cb577229808c019217b8e0/Objects/fileobject.c#L107. Not sure what the fix is, but perhaps will help you.

@aivarannamaa
Copy link
Author

A workaround for this should be to m.stdin.put("\n")

Nope, this results in "\n\n" being sent to stdin.

My mistake, I tested it incorrectly. The workaround actually works.

But I also noticed that you're using the same m.stdin object as spoofed stdin (I thought this is just a convenience wrapper). The problem is that it doesn't follow the normal stream contract which says that method readline reads up to and including next newline in the stream (or up to EOF). Current code works as long as one doesn't put a string with newline in the middle and when stdin is read only with input (which strips the (possibly non-existing) trailing newline anyway).

My plan is to replace everywhere in my fork m.stdin.write-s with m.stdin.put-s, redefine SpoofedStdin.write and SpoofedStdin.readline according to stream contract and leave SpoofedStdin.put as a conveniece method which appends "\n"to input automatically.

@macobo
Copy link
Owner

macobo commented Oct 13, 2014

That sounds like a plausibleplan - I'd prefer if you work directly on this repo (gave you access).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants