Repository: kmyk/online-judge-tools
Pull request #449 (2019-06-15 02:07:33)

NONE: fix a bug of AtCoderSubmission() for submissions whose status is CE
CE なケースに対する提出の詳細を取得しようとすると落ちます。修正してテストも追加します。


Patch:
diff --git a/onlinejudge/service/atcoder.py b/onlinejudge/service/atcoder.py
index b3118f8..bbece48 100644
--- a/onlinejudge/service/atcoder.py
+++ b/onlinejudge/service/atcoder.py
@@ -830,7 +830,16 @@ class AtCoderSubmission(onlinejudge.type.Submission):
         source_code = soup.find(id='submission-code')
         self._source_code = source_code.text.encode()
 
-        submission_info, test_cases_summary, test_cases_data = soup.find_all('table')
+        # get tables
+        tables = soup.find_all('table')
+        if len(tables) == 3:
+            submission_info, test_cases_summary, test_cases_data = tables
+        elif len(tables) == 1:
+            submission_info, = tables
+            test_cases_summary = None
+            test_cases_data = None
+        else:
+            assert False
 
         # Submission Info
         data = {}  # type: Dict[str, str]
@@ -864,10 +873,12 @@ class AtCoderSubmission(onlinejudge.type.Submission):
             self.compile_error = compile_error.text
 
         # Test Cases
-        trs = test_cases_summary.find('tbody').find_all('tr')
-        self._test_sets = [AtCoderSubmissionTestSet._from_table_row(tr) for tr in trs]
-        trs = test_cases_data.find('tbody').find_all('tr')
-        self._test_cases = [AtCoderSubmissionTestCaseResult._from_table_row(tr) for tr in trs]
+        if test_cases_summary is not None:
+            trs = test_cases_summary.find('tbody').find_all('tr')
+            self._test_sets = [AtCoderSubmissionTestSet._from_table_row(tr) for tr in trs]
+        if test_cases_data is not None:
+            trs = test_cases_data.find('tbody').find_all('tr')
+            self._test_cases = [AtCoderSubmissionTestCaseResult._from_table_row(tr) for tr in trs]
 
     def get_problem(self, session: Optional[requests.Session] = None) -> AtCoderProblem:
         if self._problem_id is None:


Test patch:
diff --git a/tests/service_atcoder.py b/tests/service_atcoder.py
index d761af4..ffa6f12 100644
--- a/tests/service_atcoder.py
+++ b/tests/service_atcoder.py
@@ -178,9 +178,38 @@ class AtCoderSubmissionTest(unittest.TestCase):
         self.assertEqual(submission.get_language_name(), 'C++14 (GCC 5.4.1)')
         self.assertEqual(submission.get_score(), 800)
         self.assertEqual(submission.get_code_size(), 1457)
+        self.assertEqual(submission.get_status(), 'AC')
         self.assertEqual(submission.get_exec_time_msec(), 85)
         self.assertEqual(submission.get_memory_byte(), 3328 * 1000)
 
+    def test_submission_info_compile_error(self):
+        submission = AtCoderSubmission.from_url('https://atcoder.jp/contests/abc124/submissions/4943518')
+        self.assertEqual(submission.get_submission_time().year, 2019)
+        self.assertEqual(submission.get_submission_time().month, 4)
+        self.assertEqual(submission.get_submission_time().day, 13)
+        self.assertEqual(submission.get_user_id(), 'pekempey')
+        self.assertEqual(submission.get_problem().problem_id, 'abc124_d')
+        self.assertEqual(submission.get_language_name(), 'Rust (1.15.1)')
+        self.assertEqual(submission.get_score(), 0)
+        self.assertEqual(submission.get_code_size(), 787)
+        self.assertEqual(submission.get_status(), 'CE')
+        self.assertEqual(submission.get_exec_time_msec(), None)
+        self.assertEqual(submission.get_memory_byte(), None)
+
+    def test_submission_info_compile_warnings(self):
+        submission = AtCoderSubmission.from_url('https://atcoder.jp/contests/agc032/submissions/4675493')
+        self.assertEqual(submission.get_submission_time().year, 2019)
+        self.assertEqual(submission.get_submission_time().month, 3)
+        self.assertEqual(submission.get_submission_time().day, 23)
+        self.assertEqual(submission.get_user_id(), 'yutaka1999')
+        self.assertEqual(submission.get_problem().problem_id, 'agc032_e')
+        self.assertEqual(submission.get_language_name(), 'C++14 (GCC 5.4.1)')
+        self.assertEqual(submission.get_score(), 0)
+        self.assertEqual(submission.get_code_size(), 1682)
+        self.assertEqual(submission.get_status(), 'WA')
+        self.assertEqual(submission.get_exec_time_msec(), 392)
+        self.assertEqual(submission.get_memory_byte(), 7168 * 1000)
+
     def test_get_test_sets(self):
         submission = AtCoderSubmission.from_url('https://atcoder.jp/contests/arc028/submissions/223928')
         test_cases = submission.get_test_sets()