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

Multi line Python source #38

Closed
tmeghe opened this issue Feb 12, 2018 · 2 comments
Closed

Multi line Python source #38

tmeghe opened this issue Feb 12, 2018 · 2 comments

Comments

@tmeghe
Copy link

tmeghe commented Feb 12, 2018

Is there a work-around to test (small) multi-line Python code ? For instance, small functions (5 lines).

@zopieux
Copy link
Member

zopieux commented Feb 12, 2018

Just use escaped (as in JSON escaped) newlines in the source string:

import sys

sys.stdout.write("hello world\n")

becomes (note the double escape for the \n in the string):

{"source": "import sys\n\nsys.stdout.write(\"hello world\\n\")\n"}

Of course you could use a real JSON serializer instead of writing such strings by hand. You can use the httpie tool do ease this process, for instance:

$ http POST localhost:42920/run \
    lang=python tests:='[{"stdin": "foo"}]' \
    source=@script.py

@seirl seirl closed this as completed Feb 12, 2018
@zopieux
Copy link
Member

zopieux commented Feb 12, 2018

b5543d4 fixes the fact that a content-type header is required in curl(1).

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

3 participants