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

Raises error if no sample found. #626

Merged
Merged
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
3 changes: 3 additions & 0 deletions onlinejudge/_implementation/command/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def download(args: 'argparse.Namespace') -> None:
else:
samples = problem.download_sample_cases(session=sess)

if not samples:
raise onlinejudge.type.SampleParseError("Sample not found")

# append the history for submit command
if not args.dry_run and is_default_format:
history = onlinejudge._implementation.download_history.DownloadHistory()
Expand Down
6 changes: 6 additions & 0 deletions tests/command_download_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import requests.exceptions
import tests.command_download

from onlinejudge.type import SampleParseError


class DownloadInvalid(unittest.TestCase):
def snippet_call_download_raises(self, *args, **kwargs):
Expand All @@ -14,6 +16,10 @@ def snippet_call_download_twice(self, *args, **kwargs):
def test_call_download_invalid(self):
self.snippet_call_download_raises(requests.exceptions.InvalidURL, 'https://not_exist_contest.jp/tasks/001_a')

def test_call_download_no_sample_found(self):
self.snippet_call_download_raises(SampleParseError, 'https://atcoder.jp/contests/tenka1-2013-quala/tasks/tenka1_2013_qualA_a')
self.snippet_call_download_raises(SampleParseError, 'https://open.kattis.com/problems/hello')

def test_call_download_twice(self):
self.snippet_call_download_twice('https://atcoder.jp/contests/abc114/tasks/abc114_c', 'https://atcoder.jp/contests/abc003/tasks/abc003_4', [
{
Expand Down
4 changes: 0 additions & 4 deletions tests/command_download_kattis.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,3 @@ def test_call_download_kattis_hanoi18_a(self):
"output": "YES\nRRUULLD\nNO\nYES\nRD\n"
},
], type='json')

def test_call_download_kattis_hello(self):
# there is no sample cases (and no samples.zip; it returns 404)
self.snippet_call_download('https://open.kattis.com/problems/hello', [], type='json')