Skip to content

Commit

Permalink
Re-add fallback to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Sep 18, 2023
1 parent 95f3e3f commit 666668f
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 165 deletions.
40 changes: 20 additions & 20 deletions tested/dodona.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
import json
from enum import StrEnum, auto, unique
from typing import IO, Literal, Optional, Union
from typing import IO, Literal, Union

from attrs import define
from cattrs.preconf.json import make_converter
Expand All @@ -30,10 +30,10 @@ class Permission(StrEnum):
class ExtendedMessage:
description: str
format: str = "text"
permission: Optional[Permission] = None
permission: Permission | None = None


Message = Union[ExtendedMessage, str]
Message = ExtendedMessage | str

BadgeCount = int

Expand Down Expand Up @@ -66,7 +66,7 @@ class StatusMessage:
"""Describes the outcome of the judgement."""

enum: Status
human: Optional[str] = None
human: str | None = None


@define
Expand All @@ -84,16 +84,16 @@ class StartTab:
"""

title: str
hidden: Optional[bool] = None
hidden: bool | None = None
command: Literal["start-tab"] = "start-tab"
permission: Optional[Permission] = None
permission: Permission | None = None


@define
class StartContext:
"""Start on a new context."""

description: Optional[Message] = None
description: Message | None = None
command: Literal["start-context"] = "start-context"


Expand All @@ -110,8 +110,8 @@ class StartTest:
"""Start on a new test with a given channel answer."""

expected: str
channel: Optional[str] = None
description: Optional[Message] = None
channel: str | None = None
description: Message | None = None
command: Literal["start-test"] = "start-test"


Expand All @@ -137,11 +137,11 @@ class AnnotateCode:

row: Index
text: str
externalUrl: Optional[str] = None
column: Optional[Index] = None
type: Optional[Severity] = None
rows: Optional[Index] = None
columns: Optional[Index] = None
externalUrl: str | None = None
column: Index | None = None
type: Severity | None = None
rows: Index | None = None
columns: Index | None = None
command: Literal["annotate-code"] = "annotate-code"


Expand All @@ -154,7 +154,7 @@ class CloseTest:

generated: str
status: StatusMessage
accepted: Optional[bool] = None
accepted: bool | None = None
command: Literal["close-test"] = "close-test"


Expand All @@ -165,7 +165,7 @@ class CloseTestcase:
overwrite this.
"""

accepted: Optional[bool] = None
accepted: bool | None = None
command: Literal["close-testcase"] = "close-testcase"


Expand All @@ -176,15 +176,15 @@ class CloseContext:
overwrite this.
"""

accepted: Optional[bool] = None
accepted: bool | None = None
command: Literal["close-context"] = "close-context"


@define
class CloseTab:
"""Close the current tab."""

badge_count: Optional[BadgeCount] = None
badge_count: BadgeCount | None = None
command: Literal["close-tab"] = "close-tab"


Expand All @@ -196,8 +196,8 @@ class CloseJudgement:
tests, but you can overwrite this.
"""

accepted: Optional[bool] = None
status: Optional[StatusMessage] = None
accepted: bool | None = None
status: StatusMessage | None = None
command: Literal["close-judgement"] = "close-judgement"


Expand Down
18 changes: 9 additions & 9 deletions tested/judge/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ class OutputManager:
__slots__ = [
"finalized",
"open_stack",
"closed",
"currently_open",
"out",
]

finalized: bool
open_stack: list[str]
closed: Tuple[int, int, int]
currently_open: Tuple[int, int, int]
out: IO

def __init__(self, out: IO):
self.finalized = False
self.open_stack = []
self.closed = (0, 0, 0)
self.currently_open = (0, 0, 0)
self.out = out

def add_all(self, commands: Iterable[Update]):
Expand All @@ -73,18 +73,18 @@ def add(self, command: Update, index: Optional[int] = None):
self.open_stack.append(type_)
elif action == "close":
previous = self.open_stack.pop()
assert previous == type_, "Closing a different update type"
assert previous == type_, f"Closing {type_}, but expected {previous}"

# If the output should be counted or not.
if index is not None:
if isinstance(command, CloseTab):
self.closed = (index + 1, 0, 0)
self.currently_open = (index + 1, 0, 0)
elif isinstance(command, CloseContext):
tabs, _, _ = self.closed
self.closed = (tabs, index + 1, 0)
tabs, _, _ = self.currently_open
self.currently_open = (tabs, index + 1, 0)
elif isinstance(command, CloseTestcase):
tabs, contexts, _ = self.closed
self.closed = (tabs, contexts, index + 1)
tabs, contexts, _ = self.currently_open
self.currently_open = (tabs, contexts, index + 1)

_logger.debug(f"After adding, stack is {self.open_stack}")
report_update(self.out, command)
Expand Down
12 changes: 7 additions & 5 deletions tested/judge/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def process_compile_results(

# There was no compilation
if results is None:
return [], Status.CORRECT, []
return CompilationResult(status=Status.CORRECT)

show_stdout = False
_logger.debug("Received stderr from compiler: " + results.stderr)
Expand Down Expand Up @@ -106,14 +106,16 @@ def process_compile_results(

# Report errors if needed.
if results.timeout:
return messages, Status.TIME_LIMIT_EXCEEDED, annotations
status = Status.TIME_LIMIT_EXCEEDED
if results.memory:
return messages, Status.MEMORY_LIMIT_EXCEEDED, annotations
status = Status.MEMORY_LIMIT_EXCEEDED
if results.exit != 0:
if not shown_messages:
messages.append(
get_i18n_string("judge.compilation.exitcode", exitcode=results.exit)
)
return messages, Status.COMPILATION_ERROR, annotations
status = Status.COMPILATION_ERROR
else:
return messages, Status.CORRECT, annotations
status = Status.CORRECT

return CompilationResult(messages=messages, status=status, annotations=annotations)
Loading

0 comments on commit 666668f

Please sign in to comment.