|
2 | 2 | import shutil
|
3 | 3 | import tempfile
|
4 | 4 | import unittest
|
| 5 | +from unittest import mock |
5 | 6 | from os.path import relpath
|
6 | 7 | from logging import getLogger
|
7 | 8 |
|
8 | 9 | from atcodertools.client.atcoder import AtCoderClient
|
9 | 10 | from atcodertools.codegen.code_style_config import CodeStyleConfig
|
10 | 11 | from atcodertools.config.config import Config
|
11 | 12 | from atcodertools.config.etc_config import EtcConfig
|
12 |
| -from atcodertools.tools.envgen import prepare_contest, main |
| 13 | +from atcodertools.tools.envgen import prepare_contest, main, EnvironmentInitializationError |
13 | 14 |
|
14 | 15 | logger = getLogger(__name__)
|
15 | 16 |
|
@@ -76,6 +77,38 @@ def test_backup(self):
|
76 | 77 | )
|
77 | 78 | self.assertDirectoriesEqual(answer_data_dir_path, self.temp_dir)
|
78 | 79 |
|
| 80 | + @mock.patch('time.sleep') |
| 81 | + def test_prepare_contest_aborts_after_max_retry_attempts(self, mock_sleep): |
| 82 | + mock_client = mock.Mock(spec=AtCoderClient) |
| 83 | + mock_client.download_problem_list.return_value = [] |
| 84 | + self.assertRaises( |
| 85 | + EnvironmentInitializationError, |
| 86 | + prepare_contest, |
| 87 | + mock_client, |
| 88 | + "agc029", |
| 89 | + Config( |
| 90 | + code_style_config=CodeStyleConfig( |
| 91 | + workspace_dir=self.temp_dir, |
| 92 | + template_file=TEMPLATE_PATH, |
| 93 | + lang="cpp", |
| 94 | + ), |
| 95 | + etc_config=EtcConfig( |
| 96 | + in_example_format="input_{}.txt", |
| 97 | + out_example_format="output_{}.txt" |
| 98 | + )) |
| 99 | + ) |
| 100 | + self.assertEqual(mock_sleep.call_count, 10) |
| 101 | + mock_sleep.assert_has_calls([mock.call(1.5), |
| 102 | + mock.call(3.0), |
| 103 | + mock.call(6.0), |
| 104 | + mock.call(12.0), |
| 105 | + mock.call(24.0), |
| 106 | + mock.call(48.0), |
| 107 | + mock.call(60.0), |
| 108 | + mock.call(60.0), |
| 109 | + mock.call(60.0), |
| 110 | + mock.call(60.0)]) |
| 111 | + |
79 | 112 | def assertDirectoriesEqual(self, expected_dir_path, dir_path):
|
80 | 113 | files1 = get_all_rel_file_paths(expected_dir_path)
|
81 | 114 | files2 = get_all_rel_file_paths(dir_path)
|
|
0 commit comments