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

Add command to display the stdout.txt data in terminal #247

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
15 changes: 14 additions & 1 deletion evalai/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
from evalai.utils.common import notify_user
from evalai.utils.requests import make_request
from evalai.utils.submissions import (
convert_bytes_to,
display_submission_details,
display_submission_result,
convert_bytes_to,
display_submission_stdout,
)
from evalai.utils.urls import URLS
from evalai.utils.config import (
Expand Down Expand Up @@ -63,6 +64,18 @@ def result(ctx):
display_submission_result(ctx.submission_id)


@submission.command()
@click.pass_obj
def stdout(ctx):
"""
Display stdout file of the submission
"""
"""
Invoked by `evalai submission SUBMISSION_ID stdout`.
"""
display_submission_stdout(ctx.submission_id)


@click.command()
@click.argument("IMAGE", nargs=1)
@click.option(
Expand Down
8 changes: 8 additions & 0 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ def display_submission_result(submission_id):
)


def display_submission_stdout(submission_id):
"""
Function to display stdout file of a particular submission
"""
response = submission_details_request(submission_id).json()
echo(requests.get(response['stdout_file']).text)


def convert_bytes_to(byte, to, bsize=1024):
"""
Convert bytes to KB, MB, GB etc.
Expand Down
2 changes: 1 addition & 1 deletion tests/data/submission_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"publication_url": null,
"status": "submitted",
"stderr_file": null,
"stdout_file": null,
"stdout_file": "http://testserver/media/submission_files/submission_9/stdout.txt",
"submission_result_file": "http://testserver/media/submission_files/submission_9/result.json",
"submitted_at": "2018-06-08T09:24:09.866590Z",
"when_made_public": null
Expand Down
15 changes: 15 additions & 0 deletions tests/test_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def setup(self):
status=200,
)

responses.add(
responses.GET,
self.submission["stdout_file"],
body="Test Submission Stdout File",
status=200,
)

@responses.activate
def test_display_submission_details(self):
team_title = "\n{}".format(self.submission["participant_team_name"])
Expand Down Expand Up @@ -100,6 +107,14 @@ def test_display_submission_result(self):
response = result.output.strip()
assert response == expected

@responses.activate
def test_display_submission_stdout(self):
expected = "Test Submission Stdout File"
runner = CliRunner()
result = runner.invoke(submission, ["9", "stdout"])
response = result.output.strip()
assert response == expected


class TestMakeSubmission(BaseTestClass):
def setup(self):
Expand Down