Skip to content

Commit d039656

Browse files
committed
Make Job.operation an ESOperation rather than its exported dict
1 parent cae78d2 commit d039656

6 files changed

Lines changed: 16 additions & 16 deletions

File tree

cms/grading/Job.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def __init__(self, operation=None,
8383
files=None, managers=None, executables=None):
8484
"""Initialization.
8585
86-
operation (dict|None): the operation, in the format that
87-
ESOperation.to_dict() uses.
86+
operation (ESOperation|None): the operation.
8887
task_type (string|None): the name of the task type.
8988
task_type_parameters (object|None): the parameters for the
9089
creation of the correct task type.
@@ -108,8 +107,6 @@ def __init__(self, operation=None,
108107
in the compilation.
109108
110109
"""
111-
if operation is None:
112-
operation = {}
113110
if task_type is None:
114111
task_type = ""
115112
if sandboxes is None:
@@ -142,7 +139,9 @@ def __init__(self, operation=None,
142139
def export_to_dict(self):
143140
"""Return a dict representing the job."""
144141
res = {
145-
'operation': self.operation,
142+
'operation': (self.operation.to_dict()
143+
if self.operation is not None
144+
else None),
146145
'task_type': self.task_type,
147146
'task_type_parameters': self.task_type_parameters,
148147
'language': self.language,
@@ -185,6 +184,8 @@ def import_from_dict_with_type(data):
185184
@classmethod
186185
def import_from_dict(cls, data):
187186
"""Create a Job from the output of export_to_dict."""
187+
if data['operation'] is not None:
188+
data['operation'] = ESOperation.from_dict(data['operation'])
188189
data['files'] = dict(
189190
(k, File(k, v)) for k, v in iteritems(data['files']))
190191
data['managers'] = dict(
@@ -303,7 +304,7 @@ def from_submission(operation, submission, dataset):
303304
# dict() is required to detach the dictionary that gets added
304305
# to the Job from the control of SQLAlchemy
305306
return CompilationJob(
306-
operation=operation.to_dict(),
307+
operation=operation,
307308
task_type=dataset.task_type,
308309
task_type_parameters=dataset.task_type_parameters,
309310
language=submission.language,
@@ -382,7 +383,7 @@ def from_user_test(operation, user_test, dataset):
382383
dataset.managers[manager_filename]
383384

384385
return CompilationJob(
385-
operation=operation.to_dict(),
386+
operation=operation,
386387
task_type=dataset.task_type,
387388
task_type_parameters=dataset.task_type_parameters,
388389
language=user_test.language,
@@ -527,7 +528,7 @@ def from_submission(operation, submission, dataset):
527528
# dict() is required to detach the dictionary that gets added
528529
# to the Job from the control of SQLAlchemy
529530
return EvaluationJob(
530-
operation=operation.to_dict(),
531+
operation=operation,
531532
task_type=dataset.task_type,
532533
task_type_parameters=dataset.task_type_parameters,
533534
language=submission.language,
@@ -560,8 +561,7 @@ def to_submission(self, sr):
560561
execution_memory=self.plus.get('execution_memory'),
561562
evaluation_shard=self.shard,
562563
evaluation_sandbox=":".join(self.sandboxes),
563-
testcase=sr.dataset.testcases[
564-
self.operation["testcase_codename"]])]
564+
testcase=sr.dataset.testcases[self.operation.testcase_codename])]
565565

566566
@staticmethod
567567
def from_user_test(operation, user_test, dataset):
@@ -608,7 +608,7 @@ def from_user_test(operation, user_test, dataset):
608608
dataset.managers[manager_filename]
609609

610610
return EvaluationJob(
611-
operation=operation.to_dict(),
611+
operation=operation,
612612
task_type=dataset.task_type,
613613
task_type_parameters=dataset.task_type_parameters,
614614
language=user_test.language,

cms/grading/tasktypes/OutputOnly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _uses_checker(self):
107107
@staticmethod
108108
def _get_user_output_filename(job):
109109
return OutputOnly.USER_OUTPUT_FILENAME_TEMPLATE % \
110-
job.operation["testcase_codename"]
110+
job.operation.testcase_codename
111111

112112
def compile(self, job, file_cacher):
113113
"""See TaskType.compile."""

cms/service/EvaluationService.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def action_finished(self, data, shard, error=None):
440440

441441
if job_group_success:
442442
for job in job_group.jobs:
443-
operation = ESOperation.from_dict(job.operation)
443+
operation = job.operation
444444
if job.success:
445445
logger.info("`%s' succeeded.", operation)
446446
else:

cmstaskenv/Test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_testcases(base_dir, solution, language, assume=None):
126126
ESOperation.EVALUATION,
127127
None,
128128
dataset.id,
129-
dataset.testcases[t].codename).to_dict(),
129+
dataset.testcases[t].codename),
130130
language=language.name,
131131
task_type=dataset.task_type,
132132
task_type_parameters=dataset.task_type_parameters,

cmstestsuite/unit_tests/grading/tasktypes/OutputOnlyTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def job(files):
6161
return EvaluationJob(input="digest of input",
6262
output="digest of correct output",
6363
files=files,
64-
operation=operation.to_dict(),
64+
operation=operation,
6565
multithreaded_sandbox=True)
6666

6767
def prepare(self, parameters, files):

cmstestsuite/unit_tests/service/WorkerTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def new_jobs(number_of_jobs, prefix=None):
266266
job_params = [
267267
ESOperation(ESOperation.EVALUATION,
268268
unique_long_id(), unique_long_id(),
269-
unique_unicode_id()).to_dict(),
269+
unique_unicode_id()),
270270
"fake_task_type",
271271
"fake_parameters_%s%d" % (prefix, i)
272272
]

0 commit comments

Comments
 (0)