Skip to content

Commit

Permalink
Move store from check functions to make
Browse files Browse the repository at this point in the history
Nikita-Barabanov committed Aug 25, 2023
1 parent bc8f4a1 commit 78851a9
Showing 4 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions hworker/check/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Universal check function"""

from .runtime import runtime
from .validate import validate
from ..depot.objects import Check, Solution, CheckCategoryEnum
from .runtime import runtime_wo_store
from .validate import validate_wo_store
from ..depot.objects import Check, Solution, CheckCategoryEnum, CheckResult


def check(checker: Check, solution: Solution, check_num: int = 0) -> None:
def check(checker: Check, solution: Solution, check_num: int = 0) -> CheckResult:
"""Universal check run on given solution
:param checker: check object
@@ -15,6 +15,6 @@ def check(checker: Check, solution: Solution, check_num: int = 0) -> None:
"""
match checker.category:
case CheckCategoryEnum.runtime:
runtime(checker, solution, check_num)
return runtime_wo_store(checker, solution, check_num)
case CheckCategoryEnum.validate:
validate(checker, solution, check_num)
return validate_wo_store(checker, solution, check_num)
4 changes: 2 additions & 2 deletions hworker/check/runtime.py
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ def python_runner(
return po, result.stderr.read(), exit_code


def check_wo_store(checker: Check, solution: Solution, check_num: int = 0) -> CheckResult:
def runtime_wo_store(checker: Check, solution: Solution, check_num: int = 0) -> CheckResult:
"""Run checker on a given solution and returns result object
:param checker: check object
@@ -139,7 +139,7 @@ def runtime(checker: Check, solution: Solution, check_num: int = 0) -> None:
"""
get_logger(__name__).debug(f"Checking solution {solution.ID} with {checker.ID} checker")
if checker.category == CheckCategoryEnum.runtime:
result = check_wo_store(checker, solution, check_num)
result = runtime_wo_store(checker, solution, check_num)
store(result)
else:
get_logger(__name__).warning(f"The {checker.ID} object given to check is not a checker")
8 changes: 5 additions & 3 deletions hworker/make/__init__.py
Original file line number Diff line number Diff line change
@@ -66,8 +66,9 @@ def get_solution(hw: Homework) -> Solution:
if not path.startswith(get_check_name()):
content[path] = path_content
print(hw.content.get(f"{get_check_name()}/{get_remote_name()}", b"").decode("utf-8"))
remote_checks = loads(hw.content.get(f"{get_check_name()}/{get_remote_name()}", b"").decode("utf-8")).get("remote",
{})
remote_checks = loads(hw.content.get(f"{get_check_name()}/{get_remote_name()}", b"").decode("utf-8")).get(
"remote", {}
)
own_checks = {check.ID: [] for check in get_checks(hw)}
config_checks = get_task_info(hw.TASK_ID).get("checks", {})
solution_id = f"{hw.USER_ID}:{hw.TASK_ID}"
@@ -114,7 +115,8 @@ def check_solution(solution: Solution) -> None:
get_logger(__name__).debug(f"Run all checks of {solution.ID} solution")
for check_name in solution.checks:
checker = search(Check, Criteria("ID", "==", check_name), actual=True, first=True)
check(checker, solution)
check_result = check(checker, solution)
store(check_result)


def check_all_solutions() -> None:
4 changes: 2 additions & 2 deletions tests/test_check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for check.runtime"""

from .user_config import user_config
from hworker.check.runtime import python_runner, check_wo_store
from hworker.check.runtime import python_runner, runtime_wo_store
from hworker.check.validate import validate_wo_store
from hworker.depot.objects import Check, Solution, CheckResult, CheckCategoryEnum, VerdictEnum

@@ -48,7 +48,7 @@ def test_checker(self, user_config):
USER_ID="user_ID",
TASK_ID="task_ID",
)
result = check_wo_store(checker, solution)
result = runtime_wo_store(checker, solution)

assert result == CheckResult(
ID=checker.ID + solution.ID,

0 comments on commit 78851a9

Please sign in to comment.