From 0e40e52ab689018000fd62de9a52a19de2177ca5 Mon Sep 17 00:00:00 2001 From: fukatani Date: Mon, 2 Dec 2019 22:28:46 +0900 Subject: [PATCH 1/2] Raises error if no sample found. --- onlinejudge/_implementation/command/download.py | 3 +++ tests/command_download_invalid.py | 5 +++++ 2 files changed, 8 insertions(+) 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', [ { From 533c2e9f1efb18560345bdab87aee72d9c7d2a20 Mon Sep 17 00:00:00 2001 From: fukatani Date: Thu, 5 Dec 2019 23:11:05 +0900 Subject: [PATCH 2/2] fix test. --- tests/command_download_invalid.py | 1 + tests/command_download_kattis.py | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/command_download_invalid.py b/tests/command_download_invalid.py index aa23b656..ab64fcb2 100644 --- a/tests/command_download_invalid.py +++ b/tests/command_download_invalid.py @@ -18,6 +18,7 @@ def test_call_download_invalid(self): 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', [ diff --git a/tests/command_download_kattis.py b/tests/command_download_kattis.py index d5ba32b6..53ab44eb 100644 --- a/tests/command_download_kattis.py +++ b/tests/command_download_kattis.py @@ -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')