diff --git a/onlinejudge/_implementation/command/download.py b/onlinejudge/_implementation/command/download.py index 9c169ae3..515aeb5b 100644 --- a/onlinejudge/_implementation/command/download.py +++ b/onlinejudge/_implementation/command/download.py @@ -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() diff --git a/tests/command_download_invalid.py b/tests/command_download_invalid.py index 039bdf72..aa23b656 100644 --- a/tests/command_download_invalid.py +++ b/tests/command_download_invalid.py @@ -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): @@ -14,6 +16,9 @@ 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') + 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', [ {