| 1 | Skip tests which requires network connections.
|
| 2 |
|
| 3 | |
| 4 | |
| 5 | @@ -1,9 +1,12 @@
|
| 6 | import unittest
|
| 7 |
|
| 8 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 9 | from onlinejudge import dispatch, service
|
| 10 |
|
| 11 | +print("XXX: Network accessible is" , NETWORK_ACCESSIBLE)
|
| 12 |
|
| 13 | class DispatchAtCoderTest(unittest.TestCase):
|
| 14 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 15 | def test_problem_from_url(self):
|
| 16 | problem = dispatch.problem_from_url('https://atcoder.jp/contests/arc001/tasks/arc001_1')
|
| 17 | self.assertIsInstance(problem, service.atcoder.AtCoderProblem)
|
| 18 | diff --git a/tests/login_service.py b/tests/login_service.py
|
| 19 | index 263673a..186443d 100644
|
| 20 | |
| 21 | |
| 22 | @@ -6,6 +6,7 @@ import unittest
|
| 23 | from typing import *
|
| 24 |
|
| 25 | from onlinejudge_api.main import main
|
| 26 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 27 |
|
| 28 | ATCODER_USERNAME = 'ATCODER_USERNAME'
|
| 29 | ATCODER_PASSWORD = 'ATCODER_PASSWORD'
|
| 30 | @@ -45,6 +46,7 @@ class LoginServiceAtCoderTest(unittest.TestCase):
|
| 31 | actual = main(['--cookie', str(cookie_path), 'login-service', url], debug=True)
|
| 32 | self.assertEqual(expected, actual)
|
| 33 |
|
| 34 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 35 | def test_login_failure(self) -> None:
|
| 36 | url = 'https://atcoder.jp/'
|
| 37 | expected = {"status": "error", "messages": ["onlinejudge.type.LoginError: failed to login"], "result": None}
|
| 38 | @@ -70,6 +72,7 @@ class LoginServiceCodeforcesTest(unittest.TestCase):
|
| 39 | actual = main(['--cookie', str(cookie_path), 'login-service', url], debug=True)
|
| 40 | self.assertEqual(expected, actual)
|
| 41 |
|
| 42 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 43 | def test_login_failure(self) -> None:
|
| 44 | url = 'https://codeforces.com/'
|
| 45 | expected = {'status': 'error', 'messages': ['onlinejudge.type.LoginError: Invalid handle or password.'], 'result': None}
|
| 46 | diff --git a/tests/service_anarchygolf.py b/tests/service_anarchygolf.py
|
| 47 | index 9c30096..d0e7922 100644
|
| 48 | |
| 49 | |
| 50 | @@ -2,6 +2,7 @@ import unittest
|
| 51 |
|
| 52 | from onlinejudge.service.anarchygolf import AnarchyGolfProblem, AnarchyGolfService
|
| 53 | from onlinejudge.type import TestCase
|
| 54 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 55 |
|
| 56 |
|
| 57 | class AnarchyGolfServiceTest(unittest.TestCase):
|
| 58 | @@ -10,6 +11,7 @@ class AnarchyGolfServiceTest(unittest.TestCase):
|
| 59 | self.assertIsInstance(AnarchyGolfService.from_url('http://golf.shinh.org/p.rb?Indent+Space+Alignment'), AnarchyGolfService)
|
| 60 |
|
| 61 |
|
| 62 | +@unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 63 | class AnarchyGolfProblemTest(unittest.TestCase):
|
| 64 | def test_download_sample_cases(self):
|
| 65 | self.assertEqual(AnarchyGolfProblem.from_url('http://golf.shinh.org/p.rb?last+non+zero').download_sample_cases(), [
|
| 66 | diff --git a/tests/service_aoj.py b/tests/service_aoj.py
|
| 67 | index 0ee4eb6..e17dbb7 100644
|
| 68 | |
| 69 | |
| 70 | @@ -2,6 +2,7 @@ import unittest
|
| 71 |
|
| 72 | from onlinejudge.service.aoj import AOJArenaProblem, AOJProblem, AOJService
|
| 73 | from onlinejudge.type import TestCase
|
| 74 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 75 |
|
| 76 |
|
| 77 | class AOJSerivceTest(unittest.TestCase):
|
| 78 | @@ -20,6 +21,7 @@ class AOJProblemTest(unittest.TestCase):
|
| 79 | self.assertEqual(AOJProblem.from_url('https://onlinejudge.u-aizu.ac.jp/challenges/sources/JAG/Spring/2394?year=2011').problem_id, '2394')
|
| 80 | self.assertIsNone(AOJProblem.from_url('https://onlinejudge.u-aizu.ac.jp/services/room.html#RitsCamp19Day2/problems/A'))
|
| 81 |
|
| 82 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 83 | def test_download_sample_cases(self):
|
| 84 | self.assertEqual(AOJProblem.from_url('http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A').download_sample_cases(), [
|
| 85 | TestCase(name='sample-1', input_name='1', input_data=b'5 12\n0 1 4\n0 2 3\n1 1 2\n1 3 4\n1 1 4\n1 3 2\n0 1 3\n1 2 4\n1 3 0\n0 0 4\n1 0 2\n1 3 0\n', output_name='1', output_data=b'0\n0\n1\n1\n1\n0\n1\n1\n'),
|
| 86 | @@ -39,6 +41,7 @@ class AOJProblemTest(unittest.TestCase):
|
| 87 | TestCase(name='sample-1', input_name='1', input_data=b'4\n0 0\n10 0\n10 10\n0 10\n3\n0 0\n1 0\n0 1\n0\n', output_name='1', output_data=b'Case 1: 14.142135624\nCase 2: 1.41421356\n'),
|
| 88 | ])
|
| 89 |
|
| 90 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 91 | def test_download_sample_cases_not_registered(self):
|
| 92 | # see: https://github.com/kmyk/online-judge-tools/issues/207
|
| 93 | self.assertEqual(AOJProblem.from_url('https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1399').download_sample_cases(), [
|
| 94 | @@ -57,11 +60,13 @@ class AOJArenaProblemTest(unittest.TestCase):
|
| 95 | self.assertEqual(AOJArenaProblem.from_url('https://onlinejudge.u-aizu.ac.jp/services/room.html#ACPC2018Day2/problems/d').alphabet, 'D')
|
| 96 | self.assertIsNone(AOJArenaProblem.from_url('http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A'))
|
| 97 |
|
| 98 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 99 | def test_download_sample_cases(self):
|
| 100 | self.assertEqual(AOJArenaProblem.from_url('https://onlinejudge.u-aizu.ac.jp/services/room.html#yupro/problems/A').download_sample_cases(), [
|
| 101 | TestCase(name='sample-1', input_name='1', input_data=b'koukyoukoukokukikou\nabrakadabra\nacmicpc\njapaque\nhelloworld\n#\n', output_name='1', output_data=b'0\n2\n4\n5\n7\n'),
|
| 102 | ])
|
| 103 |
|
| 104 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 105 | def test_download_sample_cases_not_registered(self):
|
| 106 | # see: https://github.com/kmyk/online-judge-tools/issues/207
|
| 107 | self.assertEqual(AOJArenaProblem.from_url('https://onlinejudge.u-aizu.ac.jp/services/room.html#RitsCamp18Day3/problems/B').download_sample_cases(), [
|
| 108 | diff --git a/tests/service_atcoder.py b/tests/service_atcoder.py
|
| 109 | index e7a1b1d..81b6650 100644
|
| 110 | |
| 111 | |
| 112 | @@ -6,9 +6,10 @@ import requests
|
| 113 |
|
| 114 | from onlinejudge.service.atcoder import AtCoderContest, AtCoderProblem, AtCoderProblemDetailedData, AtCoderService, AtCoderSubmission
|
| 115 | from onlinejudge.type import TestCase
|
| 116 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 117 |
|
| 118 |
|
| 119 | -class AtCoderSerivceTest(unittest.TestCase):
|
| 120 | +class AtCoderServiceTest(unittest.TestCase):
|
| 121 | def test_from_url(self):
|
| 122 | self.assertIsInstance(AtCoderService.from_url('https://atcoder.jp/'), AtCoderService)
|
| 123 | self.assertIsInstance(AtCoderService.from_url('https://beta.atcoder.jp/'), AtCoderService)
|
| 124 | @@ -16,6 +17,7 @@ class AtCoderSerivceTest(unittest.TestCase):
|
| 125 | self.assertIsInstance(AtCoderService.from_url('https://atcoder.jp/contests/agc001/submissions/806160'), AtCoderService)
|
| 126 | self.assertIsNone(AtCoderService.from_url('https://codeforces.com/'))
|
| 127 |
|
| 128 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 129 | def test_iterate_contests(self):
|
| 130 | contests = list(AtCoderService().iterate_contests())
|
| 131 | contest_ids = [contest.contest_id for contest in contests]
|
| 132 | @@ -38,6 +40,7 @@ class AtCoderContestTest(unittest.TestCase):
|
| 133 | self.assertEqual(AtCoderContest.from_url('https://atcoder.jp/contests/agc030').contest_id, 'agc030')
|
| 134 | self.assertIsNone(AtCoderContest.from_url('https://atcoder.jp/contests/'))
|
| 135 |
|
| 136 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 137 | def test_load_details(self):
|
| 138 | contest = AtCoderContest.from_url('https://atcoder.jp/contests/keyence2019')
|
| 139 | time.sleep(0.5)
|
| 140 | @@ -67,11 +70,13 @@ class AtCoderContestTest(unittest.TestCase):
|
| 141 | self.assertEqual(data.rated_range, '-')
|
| 142 | self.assertEqual(data.penalty.total_seconds(), 5 * 60)
|
| 143 |
|
| 144 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 145 | def test_get_penalty_a_singular_form(self):
|
| 146 | contest = AtCoderContest.from_url('https://atcoder.jp/contests/chokudai_S002')
|
| 147 | time.sleep(0.5)
|
| 148 | self.assertEqual(contest.download_data().penalty.total_seconds(), 60) # Penalty is written as "1 minute", not "1 minutes"
|
| 149 |
|
| 150 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 151 | def test_list_problems(self):
|
| 152 | contest = AtCoderContest.from_url('https://atcoder.jp/contests/agc028')
|
| 153 | time.sleep(0.5)
|
| 154 | @@ -94,6 +99,7 @@ class AtCoderContestTest(unittest.TestCase):
|
| 155 | time.sleep(0.5)
|
| 156 | self.assertEqual(problems[6].problem_id, 'agc028_f2')
|
| 157 |
|
| 158 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 159 | def test_list_problems_with_float_values(self):
|
| 160 | """
|
| 161 | .. seealso:
|
| 162 | @@ -112,6 +118,7 @@ class AtCoderContestTest(unittest.TestCase):
|
| 163 | time.sleep(0.5)
|
| 164 | self.assertEqual(problems[1].download_data().memory_limit_byte, 512 * 1000 * 1000)
|
| 165 |
|
| 166 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 167 | def test_list_problems_time_limit_is_less_than_msec(self):
|
| 168 | contest = AtCoderContest.from_url('https://atcoder.jp/contests/joi2019ho')
|
| 169 | time.sleep(0.5)
|
| 170 | @@ -127,6 +134,7 @@ class AtCoderContestTest(unittest.TestCase):
|
| 171 | time.sleep(0.5)
|
| 172 | self.assertEqual(problems[4].download_data().time_limit_msec, 2000)
|
| 173 |
|
| 174 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 175 | def test_list_problems_memory_limit_is_zero(self):
|
| 176 | contest = AtCoderContest.from_url('https://atcoder.jp/contests/future-contest-2019-final-open')
|
| 177 | time.sleep(0.5)
|
| 178 | @@ -144,6 +152,7 @@ class AtCoderContestTest(unittest.TestCase):
|
| 179 | self.assertEqual(submissions[0].get_url(), 'https://atcoder.jp/contests/code-festival-2014-exhibition-open/submissions/272697')
|
| 180 | self.assertEqual(submissions[1].get_url(), 'https://atcoder.jp/contests/code-festival-2014-exhibition-open/submissions/272700')
|
| 181 |
|
| 182 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 183 | def test_get_contest_without_penalty(self):
|
| 184 | contest = AtCoderContest.from_url('https://atcoder.jp/contests/otemae2019')
|
| 185 | time.sleep(0.5)
|
| 186 | @@ -188,6 +197,7 @@ class AtCoderProblemTest(unittest.TestCase):
|
| 187 | self.assertEqual(AtCoderProblem.from_url('https://kupc2014.contest.atcoder.jp/tasks/kupc2014_d'), AtCoderProblem.from_url('https://atcoder.jp/contests/kupc2014/tasks/kupc2014_d'))
|
| 188 | self.assertNotEqual(AtCoderProblem.from_url('https://kupc2014.contest.atcoder.jp/tasks/kupc2014_d'), AtCoderProblem.from_url('https://atcoder.jp/contests/agc030/tasks/agc030_c'))
|
| 189 |
|
| 190 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 191 | def test_load_details(self):
|
| 192 | problem = AtCoderProblem.from_url('https://atcoder.jp/contests/abc118/tasks/abc118_a')
|
| 193 | time.sleep(0.5)
|
| 194 | @@ -198,18 +208,21 @@ class AtCoderProblemTest(unittest.TestCase):
|
| 195 | self.assertEqual(data.memory_limit_byte, 1024 * 1000 * 1000)
|
| 196 | self.assertEqual(data.score, 100)
|
| 197 |
|
| 198 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 199 | def test_get_alphabet(self):
|
| 200 | time.sleep(0.5)
|
| 201 | self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/agc028/tasks/agc028_f').download_data().alphabet, 'F')
|
| 202 | time.sleep(0.5)
|
| 203 | self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/agc028/tasks/agc028_f2').download_data().alphabet, 'F2')
|
| 204 |
|
| 205 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 206 | def test_get_score(self):
|
| 207 | time.sleep(0.5)
|
| 208 | self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/future-contest-2018-final/tasks/future_contest_2018_final_a').download_data().score, 50000000)
|
| 209 | time.sleep(0.5)
|
| 210 | self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/abc001/tasks/abc001_4').download_data().score, None)
|
| 211 |
|
| 212 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 213 | def test_get_score_latex(self):
|
| 214 | """
|
| 215 | .. seealso::
|
| 216 | @@ -219,12 +232,14 @@ class AtCoderProblemTest(unittest.TestCase):
|
| 217 | time.sleep(0.5)
|
| 218 | self.assertIsNone(AtCoderProblem.from_url('https://atcoder.jp/contests/wupc2019/tasks/wupc2019_a').download_data().score)
|
| 219 |
|
| 220 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 221 | def test_get_time_limit_is_less_than_msec(self):
|
| 222 | time.sleep(0.5)
|
| 223 | self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/joi2019ho/tasks/joi2019ho_c').download_data().time_limit_msec, 500)
|
| 224 | time.sleep(0.5)
|
| 225 | self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/future-contest-2019-qual/tasks/future_contest_2019_qual_b').download_data().time_limit_msec, 0)
|
| 226 |
|
| 227 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 228 | def test_get_memory_limit_is_zero(self):
|
| 229 | time.sleep(0.5)
|
| 230 | self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/future-contest-2019-qual/tasks/future_contest_2019_qual_b').download_data().memory_limit_byte, 0)
|
| 231 | @@ -247,6 +262,7 @@ class AtCoderSubmissionTest(unittest.TestCase):
|
| 232 | self.assertEqual(AtCoderSubmission.from_url('https://qupc2014.contest.atcoder.jp/submissions/1444440').submission_id, 1444440)
|
| 233 |
|
| 234 |
|
| 235 | +@unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 236 | class AtCoderProblemDataTest(unittest.TestCase):
|
| 237 | def test_from_html_very_old(self):
|
| 238 | url = 'https://atcoder.jp/contests/utpc2011/tasks/utpc2011_1'
|
| 239 | @@ -479,6 +495,7 @@ class AtCoderProblemDataTest(unittest.TestCase):
|
| 240 | ])
|
| 241 |
|
| 242 |
|
| 243 | +@unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 244 | class AtCoderProblemGetInputFormatTest(unittest.TestCase):
|
| 245 | def test_normal(self):
|
| 246 | """
|
| 247 | diff --git a/tests/service_codechef.py b/tests/service_codechef.py
|
| 248 | index c65f08d..0a538e4 100644
|
| 249 | |
| 250 | |
| 251 | @@ -2,9 +2,10 @@ import unittest
|
| 252 |
|
| 253 | from onlinejudge.service.codechef import CodeChefProblem, CodeChefService
|
| 254 | from onlinejudge.type import TestCase
|
| 255 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 256 |
|
| 257 |
|
| 258 | -class CodeChefSerivceTest(unittest.TestCase):
|
| 259 | +class CodeChefServiceTest(unittest.TestCase):
|
| 260 | def test_from_url(self):
|
| 261 | self.assertIsInstance(CodeChefService.from_url('https://www.codechef.com/'), CodeChefService)
|
| 262 | self.assertIsNone(CodeChefService.from_url('https://www.facebook.com/'))
|
| 263 | @@ -15,6 +16,7 @@ class CodeChefProblemTest(unittest.TestCase):
|
| 264 | self.assertEqual(CodeChefProblem.from_url('https://www.codechef.com/COOK113A/problems/DAND').contest_id, 'COOK113A')
|
| 265 | self.assertEqual(CodeChefProblem.from_url('https://www.codechef.com/COOK113A/problems/DAND').problem_id, 'DAND')
|
| 266 |
|
| 267 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 268 | def test_download_samples_chfgcd(self):
|
| 269 | url = 'https://www.codechef.com/COOK131B/problems/CHFGCD'
|
| 270 | expected = [
|
| 271 | @@ -23,6 +25,7 @@ class CodeChefProblemTest(unittest.TestCase):
|
| 272 | self.assertEqual(CodeChefProblem.from_url(url).download_sample_cases(), expected)
|
| 273 |
|
| 274 | # TODO: support problems with an old format
|
| 275 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 276 | @unittest.expectedFailure
|
| 277 | def test_download_samples_dand(self):
|
| 278 | url = 'https://www.codechef.com/COOK113A/problems/DAND'
|
| 279 | @@ -32,6 +35,7 @@ class CodeChefProblemTest(unittest.TestCase):
|
| 280 | self.assertEqual(CodeChefProblem.from_url(url).download_sample_cases(), expected)
|
| 281 |
|
| 282 | # TODO: support problems with an old format
|
| 283 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 284 | @unittest.expectedFailure
|
| 285 | def test_download_samples_cntset(self):
|
| 286 | url = 'https://www.codechef.com/PLIN2020/problems/CNTSET'
|
| 287 | @@ -41,6 +45,7 @@ class CodeChefProblemTest(unittest.TestCase):
|
| 288 | self.assertEqual(CodeChefProblem.from_url(url).download_sample_cases(), expected)
|
| 289 |
|
| 290 | # TODO: support problems with an old format
|
| 291 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 292 | @unittest.expectedFailure
|
| 293 | def test_download_samples_acesqn(self):
|
| 294 | url = 'https://www.codechef.com/CNES2017/problems/ACESQN'
|
| 295 | diff --git a/tests/service_codeforces.py b/tests/service_codeforces.py
|
| 296 | index 39eb452..0dbc6ad 100644
|
| 297 | |
| 298 | |
| 299 | @@ -2,6 +2,7 @@
|
| 300 | import unittest
|
| 301 |
|
| 302 | from onlinejudge.service.codeforces import CodeforcesContest, CodeforcesProblem, CodeforcesService
|
| 303 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 304 |
|
| 305 |
|
| 306 | class CodeforcesSerivceTest(unittest.TestCase):
|
| 307 | @@ -25,6 +26,7 @@ class CodeforcesContestTest(unittest.TestCase):
|
| 308 | self.assertEqual(CodeforcesContest.from_url('http://m3.codeforces.com/contest/1333').get_url(), CodeforcesContest.from_url('https://codeforces.com/contest/1333').get_url())
|
| 309 | self.assertIsNone(CodeforcesContest.from_url('http://m4.codeforces.com/contest/1333'))
|
| 310 |
|
| 311 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 312 | def test_list_problems_data(self):
|
| 313 | contest = CodeforcesContest.from_url('https://codeforces.com/contest/1157')
|
| 314 | problems = contest.list_problem_data()
|
| 315 | @@ -38,6 +40,7 @@ class CodeforcesContestTest(unittest.TestCase):
|
| 316 | self.assertEqual(problems[6].tags, ['constructive algorithms', 'dp', 'greedy', 'two pointers'])
|
| 317 | self.assertEqual(problems[7].tags, ['brute force', 'constructive algorithms'])
|
| 318 |
|
| 319 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 320 | def test_list_problems(self):
|
| 321 | contest = CodeforcesContest.from_url('https://codeforces.com/contest/1157')
|
| 322 | problems = contest.list_problems()
|
| 323 | @@ -46,6 +49,7 @@ class CodeforcesContestTest(unittest.TestCase):
|
| 324 | self.assertEqual(problems[6].get_url(), 'https://codeforces.com/contest/1157/problem/F')
|
| 325 | self.assertEqual(problems[7].download_data().tags, ['brute force', 'constructive algorithms'])
|
| 326 |
|
| 327 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 328 | def test_download_data(self):
|
| 329 | contest = CodeforcesContest.from_url('http://codeforces.com/contest/1200')
|
| 330 | data = contest.download_data()
|
| 331 | @@ -57,6 +61,7 @@ class CodeforcesContestTest(unittest.TestCase):
|
| 332 | self.assertEqual(data.type, 'CF')
|
| 333 |
|
| 334 |
|
| 335 | +@unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 336 | class CodeforcesProblemTest(unittest.TestCase):
|
| 337 | def test_from_url(self):
|
| 338 | self.assertEqual(CodeforcesProblem.from_url('http://codeforces.com/problemset/problem/700/B').contest_id, 700)
|
| 339 | diff --git a/tests/service_google.py b/tests/service_google.py
|
| 340 | index d26220d..2cc8544 100644
|
| 341 | |
| 342 | |
| 343 | @@ -3,6 +3,7 @@ import unittest
|
| 344 |
|
| 345 | from onlinejudge.service.google import GoogleCodeJamProblem, GoogleCodeJamService
|
| 346 | from onlinejudge.type import TestCase
|
| 347 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 348 |
|
| 349 |
|
| 350 | class GoogleCodeJamSerivceTest(unittest.TestCase):
|
| 351 | @@ -42,6 +43,7 @@ class GoogleCodeJamProblemTest(unittest.TestCase):
|
| 352 | self.assertEqual(problem.contest_id, '8404486')
|
| 353 | self.assertEqual(problem.problem_id, 'p0')
|
| 354 |
|
| 355 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 356 | def test_download_samples_codejam(self):
|
| 357 | problem = GoogleCodeJamProblem.from_url('https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/000000000020993c')
|
| 358 | sample_input = textwrap.dedent("""\
|
| 359 | @@ -76,6 +78,7 @@ class GoogleCodeJamProblemTest(unittest.TestCase):
|
| 360 | ),
|
| 361 | ])
|
| 362 |
|
| 363 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 364 | def test_download_samples_kickstart(self):
|
| 365 | problem = GoogleCodeJamProblem.from_url('https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc7/00000000001d3f56')
|
| 366 | sample_input = textwrap.dedent("""\
|
| 367 | @@ -102,6 +105,7 @@ class GoogleCodeJamProblemTest(unittest.TestCase):
|
| 368 | ),
|
| 369 | ])
|
| 370 |
|
| 371 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 372 | def test_download_multiple_samples(self):
|
| 373 | problem = GoogleCodeJamProblem.from_url('https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc7/00000000001d3ff3')
|
| 374 | sample_input1 = textwrap.dedent("""\
|
| 375 | diff --git a/tests/service_library_checker.py b/tests/service_library_checker.py
|
| 376 | index d731df2..e1c9a6d 100644
|
| 377 | |
| 378 | |
| 379 | @@ -6,6 +6,7 @@ import unittest
|
| 380 | import onlinejudge.utils
|
| 381 | from onlinejudge.service.library_checker import LibraryCheckerProblem, LibraryCheckerService
|
| 382 | from onlinejudge.type import TestCase
|
| 383 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 384 |
|
| 385 |
|
| 386 | @contextlib.contextmanager
|
| 387 | @@ -30,12 +31,14 @@ class LibraryCheckerProblemTest(unittest.TestCase):
|
| 388 | self.assertEqual(LibraryCheckerProblem.from_url('https://judge.yosupo.jp/problem/point_add_range_sum').problem_id, 'point_add_range_sum')
|
| 389 |
|
| 390 | @unittest.skipIf(os.name == 'nt', "Library Checker is not supported on Windows")
|
| 391 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 392 | def test_download_samples(self):
|
| 393 | self.assertEqual(LibraryCheckerProblem.from_url('https://judge.yosupo.jp/problem/unionfind').download_sample_cases(), [
|
| 394 | TestCase(name='example_00', input_name='example_00.in', input_data=b'4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 1 2\n0 0 2\n1 1 3\n', output_name='example_00.out', output_data=b'0\n1\n0\n1\n'),
|
| 395 | ])
|
| 396 |
|
| 397 | @unittest.skipIf(os.name == 'nt', "Library Checker is not supported on Windows")
|
| 398 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 399 | def test_pull_repository(self):
|
| 400 | # reset
|
| 401 | LibraryCheckerService.is_repository_updated = False
|
| 402 | diff --git a/tests/service_spoj.py b/tests/service_spoj.py
|
| 403 | index 804b1c2..b39947f 100644
|
| 404 | |
| 405 | |
| 406 | @@ -2,6 +2,7 @@ import unittest
|
| 407 |
|
| 408 | from onlinejudge.service.spoj import SPOJProblem, SPOJService
|
| 409 | from onlinejudge.type import TestCase
|
| 410 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 411 |
|
| 412 |
|
| 413 | class SPOJSerivceTest(unittest.TestCase):
|
| 414 | @@ -14,11 +15,13 @@ class SPOJProblemTest(unittest.TestCase):
|
| 415 | def test_from_url(self):
|
| 416 | self.assertEqual(SPOJProblem.from_url('https://www.spoj.com/problems/ACARGO/').problem_id, 'ACARGO')
|
| 417 |
|
| 418 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 419 | def test_download_samples(self):
|
| 420 | self.assertEqual(SPOJProblem.from_url('https://www.spoj.com/problems/ACARGO/').download_sample_cases(), [
|
| 421 | TestCase(name='sample-1', input_name='Sample Input:', input_data=b'3 5\n0\n1\n3\n2 3\n0\n1\n5 20\n2\n7\n12\n9\n13\n0 0\n', output_name='Sample Output:', output_data=b'1\n0\n10\n'),
|
| 422 | ])
|
| 423 |
|
| 424 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 425 | def test_download_samples_todo(self):
|
| 426 | # No samples found.
|
| 427 | self.assertFalse(SPOJProblem.from_url('https://www.spoj.com/problems/MKLABELS/').download_sample_cases())
|
| 428 | diff --git a/tests/service_yukicoder.py b/tests/service_yukicoder.py
|
| 429 | index 658fea2..b971743 100644
|
| 430 | |
| 431 | |
| 432 | @@ -4,6 +4,7 @@ import unittest
|
| 433 | from onlinejudge.service.yukicoder import YukicoderContest, YukicoderProblem, YukicoderService
|
| 434 | from onlinejudge.type import *
|
| 435 | from tests.implementation_utils import get_handmade_sample_cases
|
| 436 | +from tests.utils import NETWORK_ACCESSIBLE
|
| 437 |
|
| 438 |
|
| 439 | class YukicoderServiceTest(unittest.TestCase):
|
| 440 | @@ -20,6 +21,7 @@ class YukicoderProblemTest(unittest.TestCase):
|
| 441 | self.assertEqual(YukicoderProblem.from_url('http://yukicoder.me/problems/no/123/').problem_no, 123)
|
| 442 | self.assertEqual(YukicoderProblem.from_url('http://yukicoder.me/problems/123').problem_id, 123)
|
| 443 |
|
| 444 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 445 | def test_download_sample_cases(self):
|
| 446 | self.assertEqual(YukicoderProblem.from_url('http://yukicoder.me/problems/no/9000').download_sample_cases(), [
|
| 447 | TestCase(name='sample-1', input_name='サンプル1 入力', input_data=b'yukicoder\n', output_name='サンプル1 出力', output_data=b'Hello World!\n'),
|
| 448 | @@ -45,6 +47,7 @@ class YukicoderProblemTest(unittest.TestCase):
|
| 449 | TestCase(name='sample-4', input_name='サンプル4 入力', input_data=b'\n', output_name='サンプル4 出力', output_data=b'1\n'),
|
| 450 | ])
|
| 451 |
|
| 452 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 453 | def test_download_sample_cases_issue_355(self):
|
| 454 | # see https://github.com/kmyk/online-judge-tools/issues/355
|
| 455 | self.assertEqual(YukicoderProblem.from_url('https://yukicoder.me/problems/no/649').download_sample_cases(), [
|
| 456 | @@ -54,6 +57,7 @@ class YukicoderProblemTest(unittest.TestCase):
|
| 457 | TestCase(name='sample-4', input_name='サンプル4 入力', input_data=b'1 1\n2\n', output_name='サンプル4 出力', output_data=b'-1\n'),
|
| 458 | ])
|
| 459 |
|
| 460 | + @unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 461 | def test_download_sample_cases_issue_192(self):
|
| 462 | # see https://github.com/kmyk/online-judge-tools/issues/192
|
| 463 | self.assertEqual(YukicoderProblem.from_url('https://yukicoder.me/problems/no/750').download_sample_cases(), [
|
| 464 | @@ -128,6 +132,7 @@ class YukicoderProblemTest(unittest.TestCase):
|
| 465 | ])
|
| 466 |
|
| 467 |
|
| 468 | +@unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 469 | class YukicoderContestTest(unittest.TestCase):
|
| 470 | def test_from_url(self):
|
| 471 | self.assertEqual(YukicoderContest.from_url('https://yukicoder.me/contests/276').contest_id, 276)
|
| 472 | @@ -144,6 +149,7 @@ class YukicoderContestTest(unittest.TestCase):
|
| 473 | ])
|
| 474 |
|
| 475 |
|
| 476 | +@unittest.skipIf(not NETWORK_ACCESSIBLE, "Network access required but not available")
|
| 477 | class YukicoderProblemGetInputFormatTest(unittest.TestCase):
|
| 478 | def test_normal(self):
|
| 479 | self.assertEqual(YukicoderProblem.from_url('https://yukicoder.me/problems/no/1').get_input_format(), '\\(N\\)\n\\(C\\)\n\\(V\\)\n\\(S_1\\ S_2\\ S_3\\ \\dots\\ S_V\\)\n\\(T_1\\ T_2\\ T_3\\ \\dots\\ T_V\\)\n\\(Y_1\\ Y_2\\ Y_3\\ \\dots\\ Y_V\\)\n\\(M_1\\ M_2\\ M_3\\ \\dots\\ M_V\\)\n')
|
| 480 | diff --git a/tests/utils.py b/tests/utils.py
|
| 481 | index 6a34fa3..e858f70 100644
|
| 482 | |
| 483 | |
| 484 | @@ -1,3 +1,8 @@
|
| 485 | +import os
|
| 486 | +import socket
|
| 487 | +
|
| 488 | +import requests
|
| 489 | +
|
| 490 | import onlinejudge.dispatch as dispatch
|
| 491 | from onlinejudge_api.main import main
|
| 492 |
|
| 493 | @@ -12,3 +17,15 @@ def is_logged_in(url: str, *, memo={}) -> bool:
|
| 494 | result = main(['login-service', '--check', url], debug=True)
|
| 495 | memo[url] = bool((result.get('result') or {}).get('loggedIn'))
|
| 496 | return memo[url]
|
| 497 | +
|
| 498 | +
|
| 499 | +def can_reach_internet():
|
| 500 | + """Check if we can actually reach the internet"""
|
| 501 | + try:
|
| 502 | + socket.create_connection(("google.com", 443), timeout=5)
|
| 503 | + return True
|
| 504 | + except Exception:
|
| 505 | + return False
|
| 506 | +
|
| 507 | +
|
| 508 | +NETWORK_ACCESSIBLE = os.getenv("RUN_NETWORK_TESTS", "1") == "1" and can_reach_internet()
|
| 509 | --
|
| 510 | 2.51.0
|
| 511 |
|