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 stderr data from submission in terminal #252

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,19 @@ <h4 class="code-container-style"><b>View status of a submission with ID 78</b></
</a>
</div>
</div>
<div class="row">
<div class="col-md-12" id="code-label">
<h4 class="code-container-style"><b>View stderr file of a submission with ID 78</b></h4>
</div>
</div>
<div class="command code-margin">
<div class="label">Run this comand</div>
<div class="text codebg">
<span id="viewSubmissionStderrWithID">evalai submission 78 stderr</span>
<a class="copy-btn" onclick="CopyToClipboard('viewSubmissionStderrWithID')" data-toggle="tooltip" data-placement="top" title="copy to clipboard"><i class="fas fa-copy"></i>
</a>
</div>
</div>
<div class="row">
<div class="col-md-12" id="code-label">
<h4 class="code-container-style"><b>Get all the phase splits of the challenge 1 with phase 4</b></h4>
Expand Down
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_stderr,
)
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 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(
Expand Down
25 changes: 25 additions & 0 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 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)
Expand Down