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

Raise error if sample parse failed. #461

Merged
merged 2 commits into from
Sep 2, 2019
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/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ def main(args: Optional[List[str]] = None) -> None:
log.error(str(e))
log.debug(traceback.format_exc())
sys.exit(1)
except onlinejudge.type.SampleParseError:
log.error('Failed to parse sample.')
sys.exit(1)


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions onlinejudge/_implementation/testcase_zipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def add(self, content: bytes, name: str) -> None:
def get(self) -> List[TestCase]:
if self._dangling is not None:
log.error('dangling sample string: %s', self._dangling[1])
raise SampleParseError
return self._testcases


Expand Down
4 changes: 4 additions & 0 deletions onlinejudge/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class SubmissionError(RuntimeError):
pass


class SampleParseError(RuntimeError):
pass


class Problem(ABC):
"""
:note: :py:class:`Problem` represents just a URL of a problem, without the data of the problem.
Expand Down
6 changes: 6 additions & 0 deletions tests/command_download_atcoder.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 DownloadAtCoderTest(unittest.TestCase):
def snippet_call_download(self, *args, **kwargs):
Expand Down Expand Up @@ -131,3 +133,7 @@ def test_call_download_atcoder_abc003_4(self):

def test_call_download_invalid_url(self):
self.snippet_call_download_raises(requests.exceptions.HTTPError, 'http://abc001.contest.atcoder.jp/tasks/abc001_100')

def test_call_download_413(self):
# This task is not supported.
self.snippet_call_download_raises(SampleParseError, 'https://chokudai001.contest.atcoder.jp/tasks/chokudai_001_a')