diff --git a/evalai/utils/challenges.py b/evalai/utils/challenges.py index c64817238..8bb16db71 100644 --- a/evalai/utils/challenges.py +++ b/evalai/utils/challenges.py @@ -49,7 +49,8 @@ def display_challenges(url): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -93,7 +94,8 @@ def display_ongoing_challenge_list(): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -135,7 +137,8 @@ def get_participant_or_host_teams(url): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -159,7 +162,8 @@ def get_participant_or_host_team_challenges(url, teams): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() challenges += response['results'] @@ -249,7 +253,8 @@ def display_challenge_details(challenge): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -293,7 +298,8 @@ def display_challenge_phase_list(challenge_id): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -363,7 +369,8 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -415,7 +422,8 @@ def display_challenge_phase_split_list(challenge_id): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) phase_splits = response.json() @@ -461,7 +469,8 @@ def display_leaderboard(challenge_id, phase_split_id): else: echo(err) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 3ef0611e1..0ba4da90e 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -44,9 +44,12 @@ def make_submission(challenge_id, phase_id, file, submission_metadata={}): fg="red", bold=True)) else: echo(err) + if "input_file" in response.json(): + echo(style(response.json()["input_file"][0], fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() echo(style("\nYour file {} with the ID {} is successfully submitted.\n".format(file.name, response["id"]), @@ -113,7 +116,8 @@ def display_my_submission_details(challenge_id, phase_id, start_date, end_date): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -161,7 +165,8 @@ def display_submission_details(submission_id): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() diff --git a/evalai/utils/teams.py b/evalai/utils/teams.py index 492b56df7..6c295e7f2 100644 --- a/evalai/utils/teams.py +++ b/evalai/utils/teams.py @@ -56,7 +56,8 @@ def display_teams(is_host): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) response = response.json() @@ -105,7 +106,8 @@ def create_team(team_name, team_url, is_host): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) if response.status_code == 201: @@ -146,7 +148,8 @@ def participate_in_a_challenge(challenge_id, participant_team_id): echo(err) sys.exit(1) except requests.exceptions.RequestException as err: - echo(err) + echo(style("\nCould not establish a connection to EvalAI." + " Please check the Host URL.\n", bold=True, fg="red")) sys.exit(1) if response.status_code == 201: diff --git a/tests/test_requests.py b/tests/test_requests.py index e555a4cb2..7fc7083be 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -129,6 +129,24 @@ def test_display_participant_and_host_challenge_lists_for_http_error_404(self): url = "{}{}".format(API_HOST_URL, URLS.host_teams.value) assert response == self.expected.format(url) + @responses.activate + def test_display_challenge_phase_detail_for_object_does_not_exist(self): + runner = CliRunner() + result = runner.invoke(challenge, ['10', 'phase', '20']) + response = result.output.rstrip() + url = "{}{}".format(API_HOST_URL, URLS.challenge_phase_detail.value) + expected = self.expected.format(url).format('10', '20') + assert response == expected + + @responses.activate + def test_display_challenge_phase_list_for_object_does_not_exist(self): + runner = CliRunner() + result = runner.invoke(challenge, ['10', 'phases']) + response = result.output.rstrip() + url = "{}{}".format(API_HOST_URL, URLS.challenge_phase_list.value) + expected = self.expected.format(url).format('10') + assert response == expected + @responses.activate def test_display_participant_team_for_http_error_404(self): runner = CliRunner() @@ -537,7 +555,7 @@ def test_create_team_for_request_exception(self): def test_participate_in_a_challenge_for_request_exception(self): runner = CliRunner() result = runner.invoke(challenge, ['2', 'participate', '3']) - assert result.output.strip() == "..." + assert result.exit_code == 1 @responses.activate def test_display_challenge_phase_list_for_request_exception(self): @@ -555,7 +573,7 @@ def test_display_challenge_phase_detail_for_request_exception(self): def test_display_my_submission_details_for_request_exception(self): runner = CliRunner() result = runner.invoke(challenge, ['3', 'phase', '7', 'submissions']) - assert result.output.strip() == "..." + assert result.exit_code == 1 @responses.activate def test_display_submission_details_for_request_exception(self): @@ -571,26 +589,22 @@ def test_make_submission_for_request_exception(self): f.write('1 2 3 4 5 6') result = runner.invoke(challenge, ['1', 'phase', '2', 'submit', "--file", "test_file.txt"], input="N") - response = result.output.rstrip() - expected = "Do you want to include the Submission Details? [y/N]: N\n{}".format("...") - assert response == expected + assert result.exit_code == 1 @responses.activate def test_display_challenge_phase_split_list_for_request_exception(self): runner = CliRunner() result = runner.invoke(challenge, ['1', 'phase', '2', 'splits']) - response = result.output.strip() - assert response == "..." + assert result.exit_code == 1 @responses.activate def test_display_leaderboard_for_request_exception(self): runner = CliRunner() result = runner.invoke(challenge, ['2', 'leaderboard', '1']) - response = result.output.strip() - assert response == "..." + assert result.exit_code == 1 @responses.activate def test_display_challenge_details_for_request_exception(self): runner = CliRunner() result = runner.invoke(challenge, ["1"]) - assert result.output.strip() == "..." + assert result.exit_code == 1