diff --git a/docs/index.html b/docs/index.html index 656bbbd46..6fd8e1071 100644 --- a/docs/index.html +++ b/docs/index.html @@ -352,6 +352,19 @@

View status of a submission with ID 78 +
+
+

View stderr file of a submission with ID 78

+
+
+
+
Run this comand
+
+ evalai submission 78 stderr + + +
+

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

diff --git a/evalai/submissions.py b/evalai/submissions.py index ac8bccf62..9b563392e 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_stderr, ) 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 stderr(ctx): + """ + Display stderr file of the submission + """ + """ + Invoked by `evalai submission SUBMISSION_ID stderr`. + """ + display_submission_stderr(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..ae71488b6 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -281,6 +281,31 @@ def display_submission_result(submission_id): ) +def display_submission_stderr(submission_id): + """ + Function to display stderr file of a particular submission + """ + try: + response = submission_details_request(submission_id).json() + stderr_content = requests.get(response['stderr_file']).text + echo( + style( + "\nThe content of stderr file:", + bold=True, + fg="green", + ) + ) + echo(stderr_content) + except requests.exceptions.MissingSchema: + echo( + style( + "\nThe Submission does not have stderr 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..219822a94 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 TestDisplaySubmissionStderr(BaseTestClass): + def setup(self): + self.submission_with_stderr = json.loads(submission_response.submission_result_with_stdout_and_stderr_file) + self.submission_without_stderr = 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_stderr, + status=200, + ) + + responses.add( + responses.GET, + self.submission_with_stderr["stderr_file"], + body="Test Submission Stderr File", + status=200, + ) + + responses.add( + responses.GET, + url.format(API_HOST_URL, URLS.get_submission.value).format("9"), + json=self.submission_without_stderr, + status=200, + ) + + @responses.activate + def test_display_submission_stderr(self): + expected = "The content of stderr file:\nTest Submission Stderr File" + runner = CliRunner() + result = runner.invoke(submission, ["10", "stderr"]) + response = result.output.strip() + assert response == expected + + @responses.activate + def test_display_submission_stderr_when_submission_does_not_have_stderr_file(self): + expected = "The Submission does not have stderr file." + runner = CliRunner() + result = runner.invoke(submission, ["9", "stderr"]) + response = result.output.strip() + assert response == expected + + class TestMakeSubmission(BaseTestClass): def setup(self): self.submission = json.loads(submission_response.submission_result)