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

Commit 8e88ec1

Browse files
committed
Fixed bug when a #COPY is not found
Fixed other minor issues
1 parent de276d3 commit 8e88ec1

11 files changed

Lines changed: 78 additions & 31 deletions

File tree

python/formats/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def __init__(self, name: str, source_file: Optional[SourceFile],
6767
self.source_file = source_file
6868

6969
def __repr__(self):
70-
return "<Generator %s [%s]>" % (self.name, " ".join(self.args_spec))
70+
return "<Generator %s [%s]>" % (self.name,
71+
" ".join(self.args_spec or []))
7172

7273

7374
class Validator:

python/formats/ioi_format.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from task_maker.config import Config
1313
from task_maker.uis.ioi_finish_ui import IOIFinishUI
1414
from task_maker.uis.ioi_curses_ui import IOICursesUI
15-
from task_maker.uis.ioi import IOIUIInterface
15+
from task_maker.uis.ioi import IOIUIInterface, TestcaseGenerationStatus
1616
from task_maker.formats import ScoreMode, Subtask, TestCase, Task, \
1717
list_files, Validator, Generator, get_options, VALIDATION_INPUT_NAME, \
1818
gen_grader_map, get_write_input_file, get_write_output_file, TaskType, \
@@ -100,8 +100,8 @@ def create_subtask(subtask_num: int, testcases: Dict[int, TestCase],
100100
current_testcases = {}
101101
current_score = float(line[4:].strip())
102102
continue
103-
if line.startswith("#COPY: "):
104-
testcase = TestCase(None, validator, [], [], line[7:].strip(),
103+
if line.startswith("#COPY:"):
104+
testcase = TestCase(None, validator, [], [], line[6:].strip(),
105105
None, get_write_input_file(testcase_num),
106106
get_write_output_file(testcase_num))
107107
else:
@@ -119,6 +119,8 @@ def create_subtask(subtask_num: int, testcases: Dict[int, TestCase],
119119
current_testcases[testcase_num] = testcase
120120
testcase_num += 1
121121

122+
if subtask_num == -1:
123+
subtask_num = 0
122124
create_subtask(subtask_num, current_testcases, current_score)
123125
# Hack for when subtasks are not specified.
124126
if len(subtasks) == 1 and subtasks[0].max_score == 0:
@@ -160,8 +162,8 @@ def create_task_from_yaml(data: Dict[str, Any]) -> Task:
160162
output_file = get_options(data, ["outfile"], "output.txt")
161163

162164
task = Task(name, title, {}, None, [], None, time_limit, memory_limit,
163-
input_file if input_file else "", output_file
164-
if output_file else "", TaskType.Batch)
165+
input_file if input_file else "",
166+
output_file if output_file else "", TaskType.Batch)
165167
return task
166168

167169

@@ -221,12 +223,12 @@ def create_task(config: Config):
221223

222224
if checker is not None:
223225
target = os.path.join(os.path.dirname(checker), "checker")
224-
task.checker = SourceFile.from_file(checker, task.name, True,
225-
target, Arch.DEFAULT, {})
226+
task.checker = SourceFile.from_file(checker, task.name, True, target,
227+
Arch.DEFAULT, {})
226228
if manager is not None:
227229
target = os.path.join(os.path.dirname(checker), "manager")
228-
task.checker = SourceFile.from_file(manager, task.name, True,
229-
target, Arch.DEFAULT, {})
230+
task.checker = SourceFile.from_file(manager, task.name, True, target,
231+
Arch.DEFAULT, {})
230232

231233
sols = [] # type: List[Solution]
232234
for solution in solutions:
@@ -287,9 +289,10 @@ def evaluate_task(frontend: Frontend, task: Task, solutions: List[Solution],
287289
return ui_interface
288290

289291

290-
def generate_inputs(frontend, task: Task, interface: IOIUIInterface,
291-
config: Config) -> (Dict[Tuple[int, int], File], Dict[
292-
Tuple[int, int], File], Dict[Tuple[int, int], File]):
292+
def generate_inputs(
293+
frontend, task: Task, interface: IOIUIInterface, config: Config
294+
) -> (Dict[Tuple[int, int], File], Dict[Tuple[int, int], File],
295+
Dict[Tuple[int, int], File]):
293296
def add_non_solution(source: SourceFile):
294297
if not source.prepared:
295298
source.prepare(frontend, config)
@@ -307,19 +310,27 @@ def add_non_solution(source: SourceFile):
307310

308311
# static input file
309312
if testcase.input_file:
310-
inputs[testcase_id] = frontend.provideFile(
311-
testcase.input_file, "Static input %d" % tc_num, False)
312-
if testcase.validator:
313-
val = testcase.validator.source_file.execute(
314-
frontend, "Validation of input %d" % tc_num,
315-
testcase.validator.get_args(testcase, subtask, tc_num,
316-
st_num + 1))
317-
if config.cache == CacheMode.NOTHING:
318-
val.disableCache()
319-
val.addInput(VALIDATION_INPUT_NAME, inputs[testcase_id])
320-
validations[testcase_id] = val.stdout(False)
321-
322-
interface.add_validation(st_num, tc_num, val)
313+
try:
314+
inputs[testcase_id] = frontend.provideFile(
315+
testcase.input_file, "Static input %d" % tc_num, False)
316+
317+
if testcase.validator:
318+
val = testcase.validator.source_file.execute(
319+
frontend, "Validation of input %d" % tc_num,
320+
testcase.validator.get_args(
321+
testcase, subtask, tc_num, st_num + 1))
322+
if config.cache == CacheMode.NOTHING:
323+
val.disableCache()
324+
val.addInput(VALIDATION_INPUT_NAME,
325+
inputs[testcase_id])
326+
validations[testcase_id] = val.stdout(False)
327+
328+
interface.add_validation(st_num, tc_num, val)
329+
except RuntimeError as ex:
330+
interface.add_error(str(ex))
331+
interface.subtasks[st_num][
332+
tc_num].status = TestcaseGenerationStatus.FAILURE
333+
continue
323334
# generate input file
324335
else:
325336
add_non_solution(testcase.generator.source_file)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#COPY: where/am/i.txt
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
3+
print(42)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
3+
print(42)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python3
2+
3+
print(42)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: with_invalid_copy
2+
title: Testing task-maker
3+
time_limit: 1
4+
memory_limit: 64

python/tests/test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def run_tests(task_name, file):
4242
"--temp-dir='{}/temp' " \
4343
"--pidfile='{}/worker.pid' " \
4444
"--name=local " \
45-
"--server=127.0.0.1:7070".format(temp_dir,
46-
temp_dir,
47-
temp_dir)
45+
"--server=127.0.0.1:7070".format(temp_dir, temp_dir, temp_dir)
4846
global interface
4947
interface = run(config)
5048
exitcode = pytest.main([

python/tests/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def __init__(self, name: str, desc: str, timelimit: float, memlimit: int):
9898
self.validation_errors = None # type: Optional[str]
9999
self.solution_errors = None # type: Optional[str]
100100
self.checker_errors = None # type: Optional[str]
101+
self.errors = None # type: Optional[str]
101102
self.name = name
102103
self.desc = desc
103104
self.timelimit = timelimit
@@ -132,6 +133,9 @@ def set_solution_errors(self, errors: str):
132133
def set_checker_errors(self, errors: str):
133134
self.checker_errors = errors
134135

136+
def set_errors(self, errors: str):
137+
self.errors = errors
138+
135139
def run_checks(self):
136140
task = interface.task
137141
assert task.name == self.name
@@ -148,6 +152,8 @@ def run_checks(self):
148152
testcase for subtask in interface.subtasks.values()
149153
for testcase in subtask.values()
150154
]
155+
if self.errors:
156+
assert self.errors in interface.errors
151157
if not self.generation_errors:
152158
for testcase in testcases:
153159
if testcase.generation_result:

python/tests/with_invalid_copy.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
3+
from task_maker.tests.test import run_tests
4+
5+
6+
def test_task():
7+
from task_maker.tests.utils import TestInterface
8+
interface = TestInterface("with_invalid_copy", "Testing task-maker", 1, 65536)
9+
interface.set_errors("Read where/am/i.txt: No such file or directory")
10+
interface.run_checks()
11+
12+
13+
if __name__ == "__main__":
14+
run_tests("with_invalid_copy", __file__)

0 commit comments

Comments
 (0)