Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 7494fd0

Browse files
committed
Fixed bug with sanity_check in tasks without a generator
1 parent 594764f commit 7494fd0

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

Diff for: python/sanity_checks/ioi.py

+40-33
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,17 @@ def _get_statement_path():
4646

4747

4848
def _get_statement_tex():
49-
return list_files(
50-
["statement/*.tex", "testo/*.tex"], valid_extensions=[".tex"])
49+
return list_files(["statement/*.tex", "testo/*.tex"],
50+
valid_extensions=[".tex"])
5151

5252

5353
def _check_git_has_file(path: str) -> Optional[bool]:
5454
# git is not installed
5555
if not find_executable("git"):
5656
return None
57-
proc = subprocess.run(
58-
["git", "ls-files", "--", path],
59-
stderr=subprocess.DEVNULL,
60-
stdout=subprocess.PIPE)
57+
proc = subprocess.run(["git", "ls-files", "--", path],
58+
stderr=subprocess.DEVNULL,
59+
stdout=subprocess.PIPE)
6160
# this is not a git repository
6261
if proc.returncode != 0:
6362
return None
@@ -142,8 +141,8 @@ def get_stderr(stderr):
142141
interface.printer.text(log_prefix + "STDERR\n" + stderr + "\n")
143142

144143
execution.notifyStart(notify_start)
145-
execution.getResult(get_result, skipped)
146144
execution.stderr(False).getContentsAsString(get_stderr)
145+
execution.getResult(get_result, skipped)
147146

148147

149148
def _setup_checker_callback(interface: IOIUIInterface, checking: Execution,
@@ -185,8 +184,8 @@ def get_stdout(stdout):
185184
interface.add_warning(description + " does not score any points")
186185

187186
checking.notifyStart(notify_start)
188-
checking.getResult(get_result, skipped)
189187
checking.stdout(False).getContentsAsString(get_stdout)
188+
checking.getResult(get_result, skipped)
190189

191190

192191
def check_att_folder(task: IOITask, solutions: List[Solution],
@@ -254,20 +253,24 @@ def check_sample_cases(task: IOITask, frontend: Frontend, config: Config,
254253
Check if the sample cases in the statement are valid and the output is
255254
correct
256255
"""
257-
inputs = list_files(
258-
[
259-
"statement/input*.txt", "statement/{}.input*.txt".format(
260-
task.name), "testo/input*.txt", "testo/{}.input*.txt".format(
261-
task.name)
262-
],
263-
valid_extensions=[".txt"])
264-
outputs = list_files(
265-
[
266-
"statement/output*.txt", "statement/{}.output*.txt".format(
267-
task.name), "testo/output*.txt", "testo/{}.output*.txt".format(
268-
task.name)
269-
],
270-
valid_extensions=[".txt"])
256+
# Communication tasks does not have output files
257+
if task.task_type != TaskType.Batch:
258+
return
259+
260+
# without official solution we cannot solve the input files
261+
if not task.official_solution:
262+
return
263+
264+
inputs = list_files([
265+
"statement/input*.txt", "statement/{}.input*.txt".format(task.name),
266+
"testo/input*.txt", "testo/{}.input*.txt".format(task.name)
267+
],
268+
valid_extensions=[".txt"])
269+
outputs = list_files([
270+
"statement/output*.txt", "statement/{}.output*.txt".format(task.name),
271+
"testo/output*.txt", "testo/{}.output*.txt".format(task.name)
272+
],
273+
valid_extensions=[".txt"])
271274
num_to_input = dict() # type: Dict[int, str]
272275
num_to_output = dict() # type: Dict[int, str]
273276
num_to_input_file = dict() # type: Dict[int, File]
@@ -282,11 +285,11 @@ def check_sample_cases(task: IOITask, frontend: Frontend, config: Config,
282285
continue
283286
sample_num = int(match.group(1))
284287
num_to_input[sample_num] = infile
285-
# skip the validations if there is no default validator
286-
if not task.default_val:
287-
break
288288
num_to_input_file[sample_num] = frontend.provideFile(
289289
infile, "Sample input {}".format(infile), False)
290+
# skip the validation if there is no default validator
291+
if not task.default_val:
292+
continue
290293
validation = task.default_val.source_file.execute(
291294
frontend, "Validation of sample input {}".format(infile),
292295
[VALIDATION_INPUT_NAME, "0"])
@@ -299,9 +302,13 @@ def check_sample_cases(task: IOITask, frontend: Frontend, config: Config,
299302
interface, validation,
300303
"Validation of sample input {}".format(infile))
301304

302-
# Communication tasks does not have output files
303-
if task.task_type != TaskType.Batch:
304-
return
305+
# if the output files were not yet generated (e.g. when they are just
306+
# copied), the solution is not prepared
307+
if not task.official_solution.prepared:
308+
task.official_solution.prepare(frontend, config)
309+
if task.official_solution.language.need_compilation:
310+
# TODO at some point use a centralized system to run the files
311+
task.official_solution.compilation.getResult(lambda res: res)
305312

306313
for outfile in outputs:
307314
match = re.match(r".*output(\d+).txt", outfile)
@@ -314,14 +321,14 @@ def check_sample_cases(task: IOITask, frontend: Frontend, config: Config,
314321
num_to_output[sample_num] = outfile
315322
num_to_output_file[sample_num] = frontend.provideFile(
316323
outfile, "Sample output {}".format(outfile), False)
317-
# without official solution we cannot solve the input
318-
if not task.official_solution:
319-
break
320324
solving = task.official_solution.execute(
321325
frontend, "Solving sample output {}".format(outfile), [])
322326
if config.cache != CacheMode.ALL:
323327
solving.disableCache()
324-
solving.addInput("wait_for_validation", num_to_validation[sample_num])
328+
# if the validator is not present we don't wait for it
329+
if sample_num in num_to_validation:
330+
solving.addInput("wait_for_validation",
331+
num_to_validation[sample_num])
325332
if task.input_file:
326333
solving.addInput(task.input_file, num_to_input_file[sample_num])
327334
else:
@@ -397,7 +404,7 @@ def sanity_pre_checks(task: IOITask, solutions: List[Solution],
397404
check_att_folder(task, solutions, interface)
398405
check_sol_folder(solutions, interface)
399406
check_statement(task, interface)
400-
# check_sample_cases(task, frontend, config, interface)
407+
check_sample_cases(task, frontend, config, interface)
401408
check_symlinks(interface)
402409

403410

Diff for: python/solution.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def get_checker_execution(frontend: Frontend, config: Config, task: IOITask,
1515
output: File, correct_output: File,
1616
message: str) -> Execution:
1717
if checker:
18+
checker.prepare(frontend, config)
1819
check = checker.execute(frontend, message,
1920
["input", "output", "contestant_output"])
2021
check.addInput("input", input)
@@ -128,9 +129,9 @@ def evaluate(
128129
pipes_sol_2_m_names.append("pipe_sol%d_2_m" % p)
129130

130131
executions = []
131-
for p_in, p_out, p_in_name, p_out_name in zip(
132-
pipes_m_2_sol, pipes_sol_2_m, pipes_m_2_sol_names,
133-
pipes_sol_2_m_names):
132+
for p, p_in, p_out, p_in_name, p_out_name in enumerate(
133+
zip(pipes_m_2_sol, pipes_sol_2_m, pipes_m_2_sol_names,
134+
pipes_sol_2_m_names)):
134135
exec = self.solution.execute(
135136
frontend, "Evaluation of %s (process %d) on testcase %d" %
136137
(self.solution.name, p, testcase),

0 commit comments

Comments
 (0)