Skip to content

Commit

Permalink
Improve more code
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Sep 18, 2023
1 parent 9e50541 commit 95f3e3f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
4 changes: 1 addition & 3 deletions tested/internationalization/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ en:
exitcode: "Exitcode %{exitcode}."
core:
unsupported:
language: >-
This exercise can't be solved in this programming language:
%{language}
language: "Unsupported programming language"
compilation: "Compilation"
invalid:
source-code: "Invalid source code"
Expand Down
4 changes: 1 addition & 3 deletions tested/internationalization/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ nl:
exitcode: "Exitcode %{exitcode}."
core:
unsupported:
language: >-
Deze oefening kan niet opgelost worden in deze programmeertaal:
%{language}
language: "Niet-ondersteunde programmeertaal"
compilation: "Compilatie"
invalid:
source-code: "Ongeldige broncode"
Expand Down
21 changes: 14 additions & 7 deletions tested/judge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,40 @@ def judge(bundle: Bundle):
report_update(
bundle.out,
CloseJudgement(
accepted=False,
status=StatusMessage(
enum=Status.INTERNAL_ERROR,
human=get_i18n_string(
"judge.core.unsupported.language",
language=bundle.config.programming_language,
),
human=get_i18n_string("judge.core.unsupported.language"),
),
),
)
_logger.info("Required features not supported.")
return # Not all required features are supported.

# Do the set-up for the judgement.
collector = OutputManager(bundle.out)
collector.add(StartJudgement())

max_time = float(bundle.config.time_limit) * 0.9
start = time.perf_counter()

# Run the linter.
# TODO: move to the back? Or at least limit the time.
# TODO: do this in parallel
run_linter(bundle, collector, max_time)
if time.perf_counter() - start > max_time:
terminate(bundle, collector, Status.TIME_LIMIT_EXCEEDED)
return

_logger.debug("Planning execution")
planned_units = plan_test_suite(bundle)
_judge_planned_units(bundle, collector, planned_units, start, max_time)


def _judge_planned_units(
bundle: Bundle,
collector: OutputManager,
planned_units: list[PlannedExecutionUnit],
start: float,
max_time: float,
):
_logger.debug("Generating files")
common_dir, dependencies, selector = _generate_files(bundle, planned_units)

Expand Down Expand Up @@ -202,6 +207,8 @@ def judge(bundle: Bundle):
terminate(bundle, collector, result_status)
return

# Depending on the result, we might want to do the next execution anyway.

collector.add(CloseJudgement())


Expand Down
16 changes: 0 additions & 16 deletions tests/test_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,22 +545,6 @@ def test_programmed_evaluator_wrong(lang: str, tmp_path: Path, pytestconfig):
assert len(updates.find_all("append-message")) == 1


@pytest.mark.parametrize("language", ALL_LANGUAGES)
def test_context_compilation(language: str, tmp_path: Path, pytestconfig, mocker):
config_ = {"options": {"mode": "context"}}
# Mock the compilation callback to ensure we call it for every context.
lang_class = LANGUAGES[language]
spy = mocker.spy(lang_class, "compilation")
conf = configuration(
pytestconfig, "echo", language, tmp_path, "two.tson", "correct", config_
)
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
assert len(updates.find_all("start-testcase")) == 2
assert updates.find_status_enum() == ["correct"] * 2
assert spy.call_count == 2


@pytest.mark.parametrize("language", ALL_LANGUAGES)
def test_batch_compilation(language: str, tmp_path: Path, pytestconfig, mocker):
config_ = {"options": {"mode": "batch"}}
Expand Down

0 comments on commit 95f3e3f

Please sign in to comment.