Skip to content

Commit

Permalink
test: post_test hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
FlickerSoul committed Nov 2, 2023
1 parent 777e4ad commit b4317f0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/assets/problems/assess_post_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from gapper import post_test, problem, test_cases
from gapper.core.result_synthesizer import ResultSynthesizer
from gapper.core.test_result import TestResult


def check_at_least_half_is_correct(
synthesizer: ResultSynthesizer, result_proxy: TestResult
) -> None:
if (
sum(result.is_passed for result in synthesizer.results)
> len(synthesizer.results) // 2
):
result_proxy.set_max_score(0)
result_proxy.set_pass_status("passed")

result_proxy.set_extra_points(5)


@test_cases.singular_param_iter([i for i in range(10)], gap_max_score=1)
@post_test(check_at_least_half_is_correct)
@problem()
def square(x: int | float) -> int | float:
return x**2


__problem_config__ = {
"is_script": False,
"check_stdout": False,
"mock_input": False,
"captured_context": (),
}
2 changes: 2 additions & 0 deletions tests/assets/submissions/assess_post_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def square(x: int | float) -> int | float:
return x**2
24 changes: 24 additions & 0 deletions tests/test_result_synthesizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest

from gapper.core.problem import Problem
from gapper.core.result_synthesizer import ResultSynthesizer
from gapper.core.test_result import TestResult
from tests.conftest import _make_problem_name


def test_post_test(request: pytest.FixtureRequest) -> None:
problem: Problem = request.getfixturevalue(
_make_problem_name("assess_post_tests.py")
)
results = [
TestResult("test result", pass_status="passed", max_score=1, score=1)
for _ in range(10)
]
old_len = len(results)
old_score = sum(result.score for result in results)
syn = ResultSynthesizer(
results=results, post_tests=problem.post_tests, total_score=10
).run_post_tests()

assert len(results) == old_len + 1
assert syn.synthesize_score() == old_score + 5

0 comments on commit b4317f0

Please sign in to comment.