Source code for codegrade.models.io_test_log

"""The module that defines the ``IOTestLog`` 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_io_test_log import UntaggedIOTestLog


[docs] @dataclass(kw_only=True) class IOTestLog(UntaggedIOTestLog): """The log of an IO test step.""" #: The type of the step that produced this log. type: t.Literal["io_test"] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: UntaggedIOTestLog.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "type", rqa.StringEnum("io_test"), 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), "steps": to_dict(self.steps), } return res @classmethod def from_dict(cls: t.Type[IOTestLog], d: t.Dict[str, t.Any]) -> IOTestLog: parsed = cls.data_parser.try_parse(d) res = cls( type=parsed.type, steps=parsed.steps, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): from .auto_test_step_log_base import AutoTestStepLogBase from .io_test_step_log import IOTestStepLog