AtCoderStudyBooster 0.3__py3-none-any.whl → 0.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- atcdr/download.py +251 -240
- atcdr/generate.py +184 -193
- atcdr/login.py +133 -0
- atcdr/logout.py +24 -0
- atcdr/main.py +24 -17
- atcdr/markdown.py +22 -22
- atcdr/open.py +30 -30
- atcdr/submit.py +297 -0
- atcdr/test.py +358 -364
- atcdr/util/execute.py +52 -52
- atcdr/util/filetype.py +71 -71
- atcdr/util/gpt.py +102 -96
- atcdr/util/parse.py +206 -0
- atcdr/util/problem.py +94 -91
- atcdr/util/session.py +140 -0
- atcoderstudybooster-0.3.1.dist-info/METADATA +205 -0
- atcoderstudybooster-0.3.1.dist-info/RECORD +21 -0
- {atcoderstudybooster-0.3.dist-info → atcoderstudybooster-0.3.1.dist-info}/WHEEL +1 -1
- atcdr/util/cost.py +0 -120
- atcoderstudybooster-0.3.dist-info/METADATA +0 -96
- atcoderstudybooster-0.3.dist-info/RECORD +0 -17
- {atcoderstudybooster-0.3.dist-info → atcoderstudybooster-0.3.1.dist-info}/entry_points.txt +0 -0
atcdr/test.py
CHANGED
@@ -4,12 +4,13 @@ import tempfile
|
|
4
4
|
import time
|
5
5
|
from dataclasses import dataclass, field
|
6
6
|
from enum import Enum
|
7
|
-
from typing import Dict,
|
7
|
+
from typing import Dict, List, Optional, Tuple, Union
|
8
8
|
|
9
|
-
from
|
10
|
-
from rich.
|
9
|
+
from rich.console import Group, RenderableType
|
10
|
+
from rich.live import Live
|
11
11
|
from rich.markup import escape
|
12
12
|
from rich.panel import Panel
|
13
|
+
from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn
|
13
14
|
from rich.rule import Rule
|
14
15
|
from rich.style import Style
|
15
16
|
from rich.syntax import Syntax
|
@@ -18,421 +19,414 @@ from rich.text import Text
|
|
18
19
|
|
19
20
|
from atcdr.util.execute import execute_files
|
20
21
|
from atcdr.util.filetype import (
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
COMPILED_LANGUAGES,
|
23
|
+
INTERPRETED_LANGUAGES,
|
24
|
+
Lang,
|
25
|
+
detect_language,
|
26
|
+
lang2str,
|
26
27
|
)
|
28
|
+
from atcdr.util.parse import ProblemHTML
|
27
29
|
|
28
30
|
|
29
31
|
@dataclass
|
30
32
|
class TestCase:
|
31
|
-
|
32
|
-
|
33
|
+
input: str
|
34
|
+
output: str
|
33
35
|
|
34
36
|
|
35
37
|
@dataclass
|
36
38
|
class LabeledTestCase:
|
37
|
-
|
38
|
-
|
39
|
+
label: str
|
40
|
+
case: TestCase
|
39
41
|
|
40
42
|
|
41
43
|
class ResultStatus(Enum):
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
AC = 'Accepted'
|
45
|
+
WA = 'Wrong Answer'
|
46
|
+
TLE = 'Time Limit Exceeded'
|
47
|
+
MLE = 'Memory Limit Exceeded'
|
48
|
+
RE = 'Runtime Error'
|
49
|
+
CE = 'Compilation Error'
|
50
|
+
WJ = 'Juding ...'
|
49
51
|
|
50
52
|
|
51
53
|
@dataclass
|
52
54
|
class TestCaseResult:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
output: str
|
56
|
+
executed_time: Union[int, None]
|
57
|
+
# memory_usage: Union[int, None]
|
58
|
+
passed: ResultStatus
|
57
59
|
|
58
60
|
|
59
61
|
@dataclass
|
60
62
|
class LabeledTestCaseResult:
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
label: str
|
64
|
+
testcase: TestCase
|
65
|
+
result: TestCaseResult
|
64
66
|
|
65
67
|
|
66
68
|
@dataclass
|
67
69
|
class TestInformation:
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
70
|
+
lang: Lang
|
71
|
+
sourcename: str
|
72
|
+
case_number: int
|
73
|
+
results: List[ResultStatus] = field(default_factory=list)
|
74
|
+
compiler_message: str = ''
|
75
|
+
compile_time: Optional[int] = None
|
76
|
+
_summary: Optional[ResultStatus] = None
|
77
|
+
|
78
|
+
@property
|
79
|
+
def summary(self) -> ResultStatus:
|
80
|
+
if self._summary:
|
81
|
+
return self._summary
|
82
|
+
else:
|
83
|
+
priority_order = [
|
84
|
+
ResultStatus.CE,
|
85
|
+
ResultStatus.RE,
|
86
|
+
ResultStatus.WA,
|
87
|
+
ResultStatus.TLE,
|
88
|
+
ResultStatus.MLE,
|
89
|
+
ResultStatus.WJ,
|
90
|
+
ResultStatus.AC,
|
91
|
+
]
|
92
|
+
priority_dict = {
|
93
|
+
status: index + 1 for index, status in enumerate(priority_order)
|
94
|
+
}
|
95
|
+
summary = min(
|
96
|
+
self.results,
|
97
|
+
key=lambda status: priority_dict[status],
|
98
|
+
default=ResultStatus.WJ,
|
99
|
+
)
|
100
|
+
|
101
|
+
if len(self.results) == self.case_number:
|
102
|
+
return summary
|
103
|
+
|
104
|
+
return ResultStatus.WJ if summary == ResultStatus.AC else summary
|
105
|
+
|
106
|
+
@summary.setter
|
107
|
+
def summary(self, value: ResultStatus) -> None:
|
108
|
+
self._summary = value
|
109
|
+
|
110
|
+
def update(
|
111
|
+
self, updator: Union[TestCaseResult, LabeledTestCaseResult, ResultStatus]
|
112
|
+
) -> None:
|
113
|
+
match updator:
|
114
|
+
case TestCaseResult():
|
115
|
+
self.results.append(updator.passed)
|
116
|
+
case LabeledTestCaseResult():
|
117
|
+
self.results.append(updator.result.passed)
|
118
|
+
case ResultStatus():
|
119
|
+
self.results.append(updator)
|
120
|
+
|
121
|
+
def __iadd__(
|
122
|
+
self, other: Union[TestCaseResult, LabeledTestCaseResult, ResultStatus]
|
123
|
+
) -> 'TestInformation':
|
124
|
+
self.update(other)
|
125
|
+
return self
|
126
|
+
|
127
|
+
|
128
|
+
class TestRunner:
|
129
|
+
def __init__(self, path: str, lcases: List[LabeledTestCase]) -> None:
|
130
|
+
self.source = path
|
131
|
+
self.lcases = iter(lcases)
|
132
|
+
self.info = TestInformation(
|
133
|
+
lang=detect_language(self.source),
|
134
|
+
sourcename=path,
|
135
|
+
case_number=len(lcases),
|
136
|
+
)
|
137
|
+
|
138
|
+
def __iter__(self):
|
139
|
+
lang = self.info.lang
|
140
|
+
if lang in COMPILED_LANGUAGES:
|
141
|
+
exe_path, compile_result, compile_time = run_compile(self.source, lang)
|
142
|
+
self.info.compiler_message = compile_result.stderr
|
143
|
+
self.info.compile_time = compile_time
|
144
|
+
if compile_result.returncode != 0:
|
145
|
+
self.info.results = [ResultStatus.CE]
|
146
|
+
return iter([])
|
147
|
+
|
148
|
+
self.cmd = [
|
149
|
+
arg.format(source_path=self.source, exec_path=exe_path)
|
150
|
+
for arg in LANGUAGE_RUN_COMMANDS[lang]
|
151
|
+
]
|
152
|
+
self.exe = exe_path
|
153
|
+
run_code(self.cmd, TestCase(input='', output='')) # バイナリーの慣らし運転
|
154
|
+
elif lang in INTERPRETED_LANGUAGES:
|
155
|
+
self.cmd = [
|
156
|
+
arg.format(source_path=self.source)
|
157
|
+
for arg in LANGUAGE_RUN_COMMANDS[lang]
|
158
|
+
]
|
159
|
+
self.exe = None
|
160
|
+
else:
|
161
|
+
raise ValueError(f'{lang}の適切な言語のランナーが見つかりませんでした.')
|
162
|
+
|
163
|
+
return self
|
164
|
+
|
165
|
+
def __next__(self):
|
166
|
+
try:
|
167
|
+
lcase = next(self.lcases)
|
168
|
+
result = run_code(self.cmd, lcase.case)
|
169
|
+
self.info += result
|
170
|
+
return LabeledTestCaseResult(lcase.label, lcase.case, result)
|
171
|
+
except StopIteration:
|
172
|
+
if self.exe and os.path.exists(self.exe):
|
173
|
+
os.remove(self.exe)
|
174
|
+
raise
|
106
175
|
|
107
176
|
|
108
177
|
def run_code(cmd: list, case: TestCase) -> TestCaseResult:
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
178
|
+
start_time = time.time()
|
179
|
+
try:
|
180
|
+
proc = subprocess.run(
|
181
|
+
cmd, input=case.input, text=True, capture_output=True, timeout=4
|
182
|
+
)
|
183
|
+
end_time = time.time()
|
184
|
+
executed_time = int((end_time - start_time) * 1000)
|
185
|
+
except subprocess.TimeoutExpired as e_proc:
|
186
|
+
end_time = time.time()
|
187
|
+
executed_time = int((end_time - start_time) * 1000)
|
188
|
+
stdout_text = e_proc.stdout.decode('utf-8') if e_proc.stdout is not None else ''
|
189
|
+
stderr_text = e_proc.stderr.decode('utf-8') if e_proc.stderr is not None else ''
|
190
|
+
text = stdout_text + '\n' + stderr_text
|
191
|
+
return TestCaseResult(
|
192
|
+
output=text, executed_time=executed_time, passed=ResultStatus.TLE
|
193
|
+
)
|
194
|
+
|
195
|
+
# プロセスの終了コードを確認し、異常終了ならREを返す
|
196
|
+
if proc.returncode != 0:
|
197
|
+
return TestCaseResult(
|
198
|
+
output=proc.stdout + '\n' + proc.stderr,
|
199
|
+
executed_time=executed_time,
|
200
|
+
passed=ResultStatus.RE,
|
201
|
+
)
|
202
|
+
|
203
|
+
# 実際の出力と期待される出力を比較
|
204
|
+
actual_output = proc.stdout.strip()
|
205
|
+
expected_output = case.output.strip()
|
206
|
+
|
207
|
+
if actual_output != expected_output:
|
208
|
+
return TestCaseResult(
|
209
|
+
output=actual_output,
|
210
|
+
executed_time=executed_time,
|
211
|
+
passed=ResultStatus.WA,
|
212
|
+
)
|
213
|
+
else:
|
214
|
+
return TestCaseResult(
|
215
|
+
output=actual_output, executed_time=executed_time, passed=ResultStatus.AC
|
216
|
+
)
|
146
217
|
|
147
218
|
|
148
219
|
LANGUAGE_RUN_COMMANDS: Dict[Lang, list] = {
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
220
|
+
Lang.PYTHON: ['python3', '{source_path}'],
|
221
|
+
Lang.JAVASCRIPT: ['node', '{source_path}'],
|
222
|
+
Lang.C: ['{exec_path}'],
|
223
|
+
Lang.CPP: ['{exec_path}'],
|
224
|
+
Lang.RUST: ['{exec_path}'],
|
225
|
+
Lang.JAVA: ['java', os.path.splitext(os.path.basename('{source_path}'))[0]],
|
155
226
|
}
|
156
227
|
|
157
228
|
LANGUAGE_COMPILE_COMMANDS: Dict[Lang, list] = {
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
229
|
+
Lang.C: ['gcc', '{source_path}', '-o', '{exec_path}'],
|
230
|
+
Lang.CPP: ['g++', '{source_path}', '-o', '{exec_path}'],
|
231
|
+
Lang.RUST: ['rustc', '{source_path}', '-o', '{exec_path}'],
|
232
|
+
Lang.JAVA: ['javac', '{source_path}'],
|
162
233
|
}
|
163
234
|
|
164
235
|
|
165
|
-
def run_compile(
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
def judge_code_from(
|
180
|
-
lcases: List[LabeledTestCase], path: str
|
181
|
-
) -> Generator[
|
182
|
-
Union[LabeledTestCaseResult, TestInformation], # type: ignore
|
183
|
-
None,
|
184
|
-
None,
|
185
|
-
]:
|
186
|
-
lang = detect_language(path)
|
187
|
-
if lang in COMPILED_LANGUAGES:
|
188
|
-
exe_path, compile_result, compile_time = run_compile(path, lang)
|
189
|
-
if compile_result.returncode != 0:
|
190
|
-
yield TestInformation(
|
191
|
-
lang=lang,
|
192
|
-
sourcename=path,
|
193
|
-
case_number=len(lcases),
|
194
|
-
result_summary=ResultStatus.CE,
|
195
|
-
compiler_message=compile_result.stderr,
|
196
|
-
)
|
197
|
-
return
|
198
|
-
else:
|
199
|
-
yield TestInformation(
|
200
|
-
lang=lang,
|
201
|
-
sourcename=path,
|
202
|
-
case_number=len(lcases),
|
203
|
-
compiler_message=compile_result.stderr,
|
204
|
-
compile_time=compile_time,
|
205
|
-
)
|
206
|
-
|
207
|
-
cmd = [
|
208
|
-
arg.format(exec_path=exe_path) for arg in LANGUAGE_RUN_COMMANDS[lang]
|
209
|
-
]
|
210
|
-
|
211
|
-
for lcase in lcases:
|
212
|
-
yield LabeledTestCaseResult(
|
213
|
-
lcase.label, lcase.case, run_code(cmd, lcase.case)
|
214
|
-
)
|
215
|
-
|
216
|
-
if os.path.exists(exe_path):
|
217
|
-
os.remove(exe_path)
|
218
|
-
|
219
|
-
elif lang in INTERPRETED_LANGUAGES:
|
220
|
-
yield TestInformation(
|
221
|
-
lang=lang,
|
222
|
-
sourcename=path,
|
223
|
-
case_number=len(lcases),
|
224
|
-
)
|
225
|
-
cmd = [arg.format(source_path=path) for arg in LANGUAGE_RUN_COMMANDS[lang]]
|
226
|
-
for lcase in lcases:
|
227
|
-
yield LabeledTestCaseResult(
|
228
|
-
lcase.label, lcase.case, run_code(cmd, lcase.case)
|
229
|
-
)
|
230
|
-
else:
|
231
|
-
raise ValueError('適切な言語が見つかりませんでした.')
|
236
|
+
def run_compile(
|
237
|
+
path: str, lang: Lang
|
238
|
+
) -> Tuple[str, subprocess.CompletedProcess, Optional[int]]:
|
239
|
+
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
240
|
+
exec_path = tmp.name
|
241
|
+
cmd = [
|
242
|
+
arg.format(source_path=path, exec_path=exec_path)
|
243
|
+
for arg in LANGUAGE_COMPILE_COMMANDS[lang]
|
244
|
+
]
|
245
|
+
start_time = time.time()
|
246
|
+
compile_result = subprocess.run(cmd, capture_output=True, text=True)
|
247
|
+
compile_time = int((time.time() - start_time) * 1000)
|
248
|
+
|
249
|
+
return exec_path, compile_result, compile_time
|
232
250
|
|
233
251
|
|
234
252
|
COLOR_MAP = {
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
253
|
+
ResultStatus.AC: 'green',
|
254
|
+
ResultStatus.WA: 'red',
|
255
|
+
ResultStatus.TLE: 'yellow',
|
256
|
+
ResultStatus.MLE: 'yellow',
|
257
|
+
ResultStatus.RE: 'yellow',
|
258
|
+
ResultStatus.CE: 'yellow',
|
259
|
+
ResultStatus.WJ: 'grey',
|
242
260
|
}
|
243
261
|
|
244
262
|
STATUS_TEXT_MAP = {
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
263
|
+
ResultStatus.AC: Text.assemble(
|
264
|
+
('\u2713 ', 'green'),
|
265
|
+
(
|
266
|
+
f'{ResultStatus.AC.value}',
|
267
|
+
Style(bgcolor=COLOR_MAP[ResultStatus.AC], bold=True),
|
268
|
+
),
|
269
|
+
),
|
270
|
+
ResultStatus.WA: Text(
|
271
|
+
f'\u00d7 {ResultStatus.WA.value}', style=COLOR_MAP[ResultStatus.WA]
|
272
|
+
),
|
273
|
+
ResultStatus.TLE: Text(
|
274
|
+
f'\u00d7 {ResultStatus.TLE.value}', style=COLOR_MAP[ResultStatus.TLE]
|
275
|
+
),
|
276
|
+
ResultStatus.MLE: Text(
|
277
|
+
f'\u00d7 {ResultStatus.MLE.value}', style=COLOR_MAP[ResultStatus.MLE]
|
278
|
+
),
|
279
|
+
ResultStatus.RE: Text(
|
280
|
+
f'\u00d7 {ResultStatus.RE.value}', style=COLOR_MAP[ResultStatus.RE]
|
281
|
+
),
|
282
|
+
ResultStatus.CE: Text(
|
283
|
+
f'\u00d7 {ResultStatus.CE.value}', style=COLOR_MAP[ResultStatus.CE]
|
284
|
+
),
|
285
|
+
ResultStatus.WJ: Text(
|
286
|
+
f'\u23f3 {ResultStatus.WJ.value}', style=COLOR_MAP[ResultStatus.WJ]
|
287
|
+
),
|
270
288
|
}
|
271
289
|
|
272
290
|
|
273
|
-
def create_renderable_test_info(
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
)
|
313
|
-
test_info.resultlist.append(test_result)
|
314
|
-
|
315
|
-
priority_order = [
|
316
|
-
ResultStatus.RE,
|
317
|
-
ResultStatus.WA,
|
318
|
-
ResultStatus.TLE,
|
319
|
-
ResultStatus.MLE,
|
320
|
-
ResultStatus.WJ,
|
321
|
-
ResultStatus.AC,
|
322
|
-
]
|
323
|
-
|
324
|
-
# 現在の結果の中で最も高い優先順位のステータスを見つける
|
325
|
-
highest_priority_status = (
|
326
|
-
test_info.result_summary
|
327
|
-
) # デフォルトはWJまたは現在のサマリー
|
328
|
-
for result in test_info.resultlist:
|
329
|
-
status = result.result.passed
|
330
|
-
if priority_order.index(status) < priority_order.index(highest_priority_status):
|
331
|
-
highest_priority_status = status
|
332
|
-
|
333
|
-
# 特殊ケース: すべてのテストケースがACである場合(途中でも)
|
334
|
-
if all(result.result.passed == ResultStatus.AC for result in test_info.resultlist):
|
335
|
-
test_info.result_summary = ResultStatus.AC
|
336
|
-
else:
|
337
|
-
test_info.result_summary = highest_priority_status
|
291
|
+
def create_renderable_test_info(
|
292
|
+
test_info: TestInformation, progress: Optional[Progress] = None
|
293
|
+
) -> RenderableType:
|
294
|
+
components = []
|
295
|
+
|
296
|
+
success_count = sum(1 for result in test_info.results if result == ResultStatus.AC)
|
297
|
+
total_count = test_info.case_number
|
298
|
+
|
299
|
+
status_text = STATUS_TEXT_MAP[test_info.summary]
|
300
|
+
|
301
|
+
header_text = Text.assemble(
|
302
|
+
Text.from_markup(f'[cyan]{test_info.sourcename}[/]のテスト \n'),
|
303
|
+
Text.from_markup(
|
304
|
+
f'[italic #0f0f0f]コンパイルにかかった時間: [not italic cyan]{test_info.compile_time}[/] ms[/]\n'
|
305
|
+
)
|
306
|
+
if test_info.compile_time
|
307
|
+
else Text(''),
|
308
|
+
status_text,
|
309
|
+
Text.from_markup(
|
310
|
+
f' [{COLOR_MAP[test_info.summary]} bold]{success_count}[/] / [white bold]{total_count}[/]'
|
311
|
+
),
|
312
|
+
)
|
313
|
+
|
314
|
+
if progress:
|
315
|
+
components.append(Panel(Group(header_text, progress), expand=False))
|
316
|
+
else:
|
317
|
+
components.append(Panel(header_text, expand=False))
|
318
|
+
|
319
|
+
if test_info.compiler_message:
|
320
|
+
rule = Rule(
|
321
|
+
title='コンパイラーのメッセージ',
|
322
|
+
style=COLOR_MAP[ResultStatus.CE],
|
323
|
+
)
|
324
|
+
components.append(rule)
|
325
|
+
error_message = Syntax(
|
326
|
+
test_info.compiler_message, lang2str(test_info.lang), line_numbers=False
|
327
|
+
)
|
328
|
+
components.append(error_message)
|
329
|
+
|
330
|
+
return Group(*components)
|
338
331
|
|
339
332
|
|
340
333
|
def create_renderable_test_result(
|
341
|
-
|
342
|
-
|
334
|
+
i: int,
|
335
|
+
test_result: LabeledTestCaseResult,
|
343
336
|
) -> RenderableType:
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
337
|
+
rule = Rule(
|
338
|
+
title=f'No.{i+1} {test_result.label}',
|
339
|
+
style=COLOR_MAP[test_result.result.passed],
|
340
|
+
)
|
341
|
+
|
342
|
+
# 以下の部分は if-else ブロックの外に移動
|
343
|
+
status_header = Text.assemble(
|
344
|
+
'ステータス ',
|
345
|
+
STATUS_TEXT_MAP[test_result.result.passed], # status_text をここに追加
|
346
|
+
)
|
347
|
+
|
348
|
+
execution_time_text = None
|
349
|
+
if test_result.result.executed_time is not None:
|
350
|
+
execution_time_text = Text.from_markup(
|
351
|
+
f'実行時間 [cyan]{test_result.result.executed_time}[/cyan] ms'
|
352
|
+
)
|
353
|
+
|
354
|
+
table = Table(show_header=True, header_style='bold')
|
355
|
+
table.add_column('入力', style='cyan', min_width=10)
|
356
|
+
|
357
|
+
if test_result.result.passed != ResultStatus.AC:
|
358
|
+
table.add_column(
|
359
|
+
'出力',
|
360
|
+
style=COLOR_MAP[test_result.result.passed],
|
361
|
+
min_width=10,
|
362
|
+
overflow='fold',
|
363
|
+
)
|
364
|
+
table.add_column('正解の出力', style=COLOR_MAP[ResultStatus.AC], min_width=10)
|
365
|
+
table.add_row(
|
366
|
+
escape(test_result.testcase.input),
|
367
|
+
escape(test_result.result.output),
|
368
|
+
escape(test_result.testcase.output),
|
369
|
+
)
|
370
|
+
else:
|
371
|
+
table.add_column(
|
372
|
+
'出力', style=COLOR_MAP[test_result.result.passed], min_width=10
|
373
|
+
)
|
374
|
+
table.add_row(
|
375
|
+
escape(test_result.testcase.input), escape(test_result.result.output)
|
376
|
+
)
|
377
|
+
|
378
|
+
components = [
|
379
|
+
rule,
|
380
|
+
status_header,
|
381
|
+
execution_time_text if execution_time_text else '',
|
382
|
+
table,
|
383
|
+
]
|
384
|
+
|
385
|
+
return Group(*components)
|
386
|
+
|
387
|
+
|
388
|
+
def render_results(test: TestRunner) -> None:
|
389
|
+
progress = Progress(
|
390
|
+
SpinnerColumn(style='white', spinner_name='circleHalves'),
|
391
|
+
TextColumn('{task.description}'),
|
392
|
+
SpinnerColumn(style='white', spinner_name='simpleDots'),
|
393
|
+
BarColumn(),
|
394
|
+
)
|
395
|
+
task_id = progress.add_task(description='テスト進行中', total=test.info.case_number)
|
396
|
+
|
397
|
+
current_display = [create_renderable_test_info(test.info, progress)]
|
398
|
+
|
399
|
+
with Live(Group(*current_display)) as live:
|
400
|
+
for i, result in enumerate(test):
|
401
|
+
progress.advance(task_id, advance=1)
|
402
|
+
current_display[-1] = create_renderable_test_info(test.info, progress)
|
403
|
+
current_display.insert(-1, (create_renderable_test_result(i, result)))
|
404
|
+
live.update(Group(*current_display))
|
405
|
+
|
406
|
+
progress.update(task_id, description='テスト完了') # 完了メッセージに更新
|
407
|
+
current_display[-1] = create_renderable_test_info(test.info, progress)
|
408
|
+
live.update(Group(*current_display))
|
415
409
|
|
416
410
|
|
417
411
|
def run_test(path_of_code: str) -> None:
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
412
|
+
html_paths = [f for f in os.listdir('.') if f.endswith('.html')]
|
413
|
+
if not html_paths:
|
414
|
+
print(
|
415
|
+
'問題のファイルが見つかりません。\n問題のファイルが存在するディレクトリーに移動してから実行してください。'
|
416
|
+
)
|
417
|
+
return
|
424
418
|
|
425
|
-
|
426
|
-
|
419
|
+
with open(html_paths[0], 'r') as file:
|
420
|
+
html = file.read()
|
427
421
|
|
428
|
-
|
429
|
-
|
430
|
-
|
422
|
+
lcases = ProblemHTML(html).load_labeled_testcase()
|
423
|
+
test = TestRunner(path_of_code, lcases)
|
424
|
+
render_results(test)
|
431
425
|
|
432
426
|
|
433
427
|
def test(*args: str) -> None:
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
428
|
+
execute_files(
|
429
|
+
*args,
|
430
|
+
func=run_test,
|
431
|
+
target_filetypes=INTERPRETED_LANGUAGES + COMPILED_LANGUAGES,
|
432
|
+
)
|