diff --git a/docs/index.html b/docs/index.html index 656bbbd46..47333d4b1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -351,7 +351,19 @@

View status of a submission with ID 78 +
+
+

View stdout file of a submission with ID 78

+
+
+
Run this command
+
+ evalai submission 78 stdout + + +
+
/div>

Get all the phase splits of the challenge 1 with phase 4

diff --git a/evalai/submissions.py b/evalai/submissions.py index ac8bccf62..a10b03f25 100644 --- a/evalai/submissions.py +++ b/evalai/submissions.py @@ -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 ( @@ -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( diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 19d9fc3e4..0ee201a14 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -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. diff --git a/tests/data/submission_response.py b/tests/data/submission_response.py index e9ee30474..935797d82 100644 --- a/tests/data/submission_response.py +++ b/tests/data/submission_response.py @@ -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": { diff --git a/tests/test_submissions.py b/tests/test_submissions.py index 02f65fc76..ee3936ce9 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -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)