Skip to content

Commit

Permalink
Merge pull request #626 from fukatani/fix/raise-error-if-no-sample
Browse files Browse the repository at this point in the history
Raises error if no sample found.
  • Loading branch information
fukatani authored Dec 5, 2019
2 parents 446f27c + 533c2e9 commit f084863
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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')

0 comments on commit f084863

Please sign in to comment.