Source code for codegrade.models.run_program_log

"""The module that defines the ``RunProgramLog`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa

from ..utils import to_dict
from .untagged_run_program_log import UntaggedRunProgramLog


[docs] @dataclass(kw_only=True) class RunProgramLog(UntaggedRunProgramLog): """The log of a run program step.""" #: The type of the step that produced this log. type: t.Literal["run_program"] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: UntaggedRunProgramLog.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "type", rqa.StringEnum("run_program"), doc="The type of the step that produced this log.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "type": to_dict(self.type), "stdout": to_dict(self.stdout), "stderr": to_dict(self.stderr), "exit_code": to_dict(self.exit_code), "time_spend": to_dict(self.time_spend), } return res @classmethod def from_dict( cls: t.Type[RunProgramLog], d: t.Dict[str, t.Any] ) -> RunProgramLog: parsed = cls.data_parser.try_parse(d) res = cls( type=parsed.type, stdout=parsed.stdout, stderr=parsed.stderr, exit_code=parsed.exit_code, time_spend=parsed.time_spend, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): import datetime from .auto_test_step_log_base import AutoTestStepLogBase