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
17 changes: 17 additions & 0 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@ def display_submission_result(submission_id):
)


def display_submission_stdout(submission_id):
"""
Function to display stdout file of a particular submission
"""
try:
response = submission_details_request(submission_id).json()
echo(requests.get(response['stdout_file']).text)
except requests.exceptions.MissingSchema:
echo(
style(
"\nThe Submission does not have stdout file.",
bold=True,
fg="red",
)
)


def convert_bytes_to(byte, to, bsize=1024):
"""
Convert bytes to KB, MB, GB etc.
Expand Down
23 changes: 23 additions & 0 deletions tests/data/submission_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@
"when_made_public": null
}"""

submission_result_with_stdout_and_stderr_file = """
{
"challenge_phase": 7,
"created_by": 4,
"execution_time": "None",
"id": 10,
"input_file": "http://testserver/media/submission_files/submission_10/2224fb89-6828-\
47f4-b170-1279290ad900.json",
"is_public": false,
"method_description": null,
"method_name": null,
"participant_team": 3,
"participant_team_name": "Host_83644_Team",
"project_url": null,
"publication_url": null,
"status": "submitted",
"stderr_file": "http://testserver/media/submission_files/submission_10/stderr.txt",
"stdout_file": "http://testserver/media/submission_files/submission_10/stdout.txt",
"submission_result_file": "http://testserver/media/submission_files/submission_10/result.json",
"submitted_at": "2018-06-08T09:24:09.866590Z",
"when_made_public": null
}"""

aws_credentials = """
{
"success": {
Expand Down
44 changes: 44 additions & 0 deletions tests/test_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,50 @@ def test_display_submission_result(self):
assert response == expected


class TestDisplaySubmissionStdout(BaseTestClass):
def setup(self):
self.submission_with_stdout = json.loads(submission_response.submission_result_with_stdout_and_stderr_file)
self.submission_without_stdout = json.loads(submission_response.submission_result)

url = "{}{}"
responses.add(
responses.GET,
url.format(API_HOST_URL, URLS.get_submission.value).format("10"),
json=self.submission_with_stdout,
status=200
)

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

responses.add(
responses.GET,
url.format(API_HOST_URL, URLS.get_submission.value).format("9"),
json=self.submission_without_stdout,
status=200
)

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

@responses.activate
def test_display_submission_stdout_when_submission_does_not_have_stdout_file(self):
expected = "The Submission does not have stdout file."
runner = CliRunner()
result = runner.invoke(submission, ["9", "stdout"])
response = result.output.strip()
assert response == expected


class TestMakeSubmission(BaseTestClass):
def setup(self):
self.submission = json.loads(submission_response.submission_result)
Expand Down