From 95eb39794d3903891b23bb894ce08b5fb4bcdf26 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 03:01:26 +0900 Subject: [PATCH 1/7] Add command to display the stderr data from submission in terminal --- evalai/submissions.py | 13 +++++++++++++ evalai/utils/submissions.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/evalai/submissions.py b/evalai/submissions.py index ac8bccf62..8f331c6b9 100644 --- a/evalai/submissions.py +++ b/evalai/submissions.py @@ -19,6 +19,7 @@ from evalai.utils.submissions import ( display_submission_details, display_submission_result, + display_submission_stderr, convert_bytes_to, ) from evalai.utils.urls import URLS @@ -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..0c08e8fee 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -281,6 +281,23 @@ 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() + echo(requests.get(response['stderr_file']).text) + 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. From 8c49c9ac3f1436decc9706ae52fe019d60bc86a0 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 03:09:09 +0900 Subject: [PATCH 2/7] Add tests --- tests/data/submission_response.py | 23 +++++++++++++++ tests/test_submissions.py | 47 +++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) 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..2c25c71c1 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -20,7 +20,6 @@ class TestGetSubmissionDetails(BaseTestClass): def setup(self): - self.submission = json.loads(submission_response.submission_result) url = "{}{}" @@ -101,6 +100,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 = "Test 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) @@ -272,7 +315,7 @@ def test_make_submission_for_docker_based_challenge_teardown(): @responses.activate def test_make_submission_for_docker_based_challenge( - self, test_make_submission_for_docker_based_challenge_setup + self, test_make_submission_for_docker_based_challenge_setup ): registry_port, image_tag = ( test_make_submission_for_docker_based_challenge_setup From 328ceb174eca6ebb97da5b02921ad3654b1fddca Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 03:09:52 +0900 Subject: [PATCH 3/7] Reorder imports --- evalai/submissions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evalai/submissions.py b/evalai/submissions.py index 8f331c6b9..9b563392e 100644 --- a/evalai/submissions.py +++ b/evalai/submissions.py @@ -17,10 +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, display_submission_stderr, - convert_bytes_to, ) from evalai.utils.urls import URLS from evalai.utils.config import ( From 856bbab609915dbd28a039971197604d669a6923 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 03:18:18 +0900 Subject: [PATCH 4/7] Add an example of this command to docs --- docs/index.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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

From 95ad2889f1c2347b016d9e6805c369a3a851a5bf Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 03:27:44 +0900 Subject: [PATCH 5/7] Enhance output of this command --- evalai/utils/submissions.py | 10 +++++++++- tests/test_submissions.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 0c08e8fee..205cf88e6 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -287,7 +287,15 @@ def display_submission_stderr(submission_id): """ try: response = submission_details_request(submission_id).json() - echo(requests.get(response['stderr_file']).text) + 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( diff --git a/tests/test_submissions.py b/tests/test_submissions.py index 2c25c71c1..4278d7449 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -129,7 +129,7 @@ def setup(self): @responses.activate def test_display_submission_stderr(self): - expected = "Test Submission Stderr File" + expected = "The content of stderr file:\nTest Submission Stderr File" runner = CliRunner() result = runner.invoke(submission, ["10", "stderr"]) response = result.output.strip() From 5e36d896d867a44e6c098bdd3c8a45dadded36c2 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 03:45:07 +0900 Subject: [PATCH 6/7] Revert unintended changes --- tests/test_submissions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_submissions.py b/tests/test_submissions.py index 4278d7449..918c14a6f 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -20,6 +20,7 @@ class TestGetSubmissionDetails(BaseTestClass): def setup(self): + self.submission = json.loads(submission_response.submission_result) url = "{}{}" @@ -315,7 +316,7 @@ def test_make_submission_for_docker_based_challenge_teardown(): @responses.activate def test_make_submission_for_docker_based_challenge( - self, test_make_submission_for_docker_based_challenge_setup + self, test_make_submission_for_docker_based_challenge_setup ): registry_port, image_tag = ( test_make_submission_for_docker_based_challenge_setup From d58511be787f67fc23276a19f9975d2d2e501039 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Wed, 15 Jan 2020 15:01:40 +0900 Subject: [PATCH 7/7] Add trailing commas --- evalai/utils/submissions.py | 4 ++-- tests/test_submissions.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 205cf88e6..ae71488b6 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -292,7 +292,7 @@ def display_submission_stderr(submission_id): style( "\nThe content of stderr file:", bold=True, - fg="green" + fg="green", ) ) echo(stderr_content) @@ -301,7 +301,7 @@ def display_submission_stderr(submission_id): style( "\nThe Submission does not have stderr file.", bold=True, - fg="red" + fg="red", ) ) diff --git a/tests/test_submissions.py b/tests/test_submissions.py index 918c14a6f..219822a94 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -125,7 +125,7 @@ def setup(self): responses.GET, url.format(API_HOST_URL, URLS.get_submission.value).format("9"), json=self.submission_without_stderr, - status=200 + status=200, ) @responses.activate