Skip to content

Commit 04235ef

Browse files
committed
Bug fixes
1 parent 220ff1b commit 04235ef

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/sio3pack/django/sinolpack/handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def _save_config(self):
4646
)
4747

4848
def _save_model_solutions(self):
49-
for order, (kind, solution) in enumerate(self.package.model_solutions):
49+
for order, ms in enumerate(self.package.model_solutions):
50+
kind = ms["kind"]
51+
solution = ms["file"]
5052
instance = SinolpackModelSolution(
5153
package=self.db_package,
5254
name=solution.filename,

src/sio3pack/packages/sinolpack/model.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33
import tempfile
4+
from typing import Any
45

56
import yaml
67

@@ -27,8 +28,8 @@ class Sinolpack(Package):
2728
:param dict[str, File] lang_statements: A dictionary of problem
2829
statements, where keys are language codes and values are files.
2930
:param dict[str, Any] config: Configuration of the problem.
30-
:param list[tuple[ModelSolutionKind, File]] model_solutions: A list
31-
of model solutions, where each element is a tuple containing
31+
:param list[dict[str, Any]] model_solutions: A list
32+
of model solutions, where each element is a dict containing
3233
a model solution kind and a file.
3334
:param list[File] additional_files: A list of additional files for
3435
the problem.
@@ -253,9 +254,9 @@ def main_model_solution_regex(self):
253254
extensions = self.get_submittable_extensions()
254255
return rf"^{self.short_name}\.({'|'.join(extensions)})"
255256

256-
def _get_model_solutions(self) -> list[tuple[ModelSolutionKind, File]]:
257+
def _get_model_solutions(self) -> list[dict[str, Any]]:
257258
"""
258-
Returns a list of model solutions, where each element is a tuple of model solution kind and filename.
259+
Returns a list of model solutions, where each element is a dict of model solution kind and filename.
259260
"""
260261
if not os.path.exists(self.get_prog_dir()):
261262
return []
@@ -268,22 +269,23 @@ def _get_model_solutions(self) -> list[tuple[ModelSolutionKind, File]]:
268269
match = re.match(regex, file)
269270
if match and os.path.isfile(os.path.join(self.get_prog_dir(), file)):
270271
file = LocalFile(os.path.join(self.get_prog_dir(), file))
271-
model_solutions.append((ModelSolutionKind.from_regex(match.group(1)), file))
272+
model_solutions.append({"file": file, "kind": ModelSolutionKind.from_regex(match.group(1))})
272273
if re.match(main_regex, file.filename):
273274
main_solution = file
274275

275276
self.main_model_solution = main_solution
276277
return model_solutions
277278

278279
def sort_model_solutions(
279-
self, model_solutions: list[tuple[ModelSolutionKind, File]]
280-
) -> list[tuple[ModelSolutionKind, File]]:
280+
self, model_solutions: list[dict[str, Any]]
281+
) -> list[dict[str, Any]]:
281282
"""
282283
Sorts model solutions by kind.
283284
"""
284285

285286
def sort_key(model_solution):
286-
kind, file = model_solution
287+
kind: ModelSolutionKind = model_solution['kind']
288+
file: LocalFile = model_solution['file']
287289
return kind.value, naturalsort_key(file.filename[: file.filename.index(".")])
288290

289291
return list(sorted(model_solutions, key=sort_key))

src/sio3pack/packages/sinolpack/workflows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def _get_run_test_workflow(self) -> Workflow:
624624
reactive=True,
625625
input_registers=["r:run_test_res_<TEST_ID>", "r:checker_res_<TEST_ID>"],
626626
output_registers=["r:grade_res_<TEST_ID>"],
627-
objects=[user_out_obj],
627+
objects=[chk_out_obj],
628628
script=lua.get_script("grade_test"),
629629
)
630630
wf.add_task(grade)

src/sio3pack/test/test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
class Test:
55
"""
6-
Represents an input or output test.
76
Represents an input and output test.
87
"""
98

@@ -12,5 +11,3 @@ def __init__(self, test_id: str, in_file: File, out_file: File, group: str):
1211
self.in_file = in_file
1312
self.out_file = out_file
1413
self.group = group
15-
16-
pass

tests/test_django/test_sio3pack/test_sinolpack.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def test_model_solutions(get_archived_package):
5555
model_solutions = package.model_solutions
5656
db_model_solutions = SinolpackModelSolution.objects.filter(package=db_package)
5757
assert len(model_solutions) == db_model_solutions.count()
58-
for order, (kind, solution) in enumerate(model_solutions):
58+
for order, msdict in enumerate(model_solutions):
59+
kind = msdict["kind"]
60+
solution = msdict["file"]
5961
ms = db_model_solutions.get(order_key=order)
6062
assert ms.name == solution.filename
6163
assert ms.kind == kind

0 commit comments

Comments
 (0)