Source code for codegrade.models.quality_test_log

"""The module that defines the ``QualityTestLog`` 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_quality_test_log import UntaggedQualityTestLog


[docs] @dataclass(kw_only=True) class QualityTestLog(UntaggedQualityTestLog): """The log of a code quality step.""" #: The type of the step that produced this log. type: t.Literal["code_quality"] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: UntaggedQualityTestLog.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "type", rqa.StringEnum("code_quality"), 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), } if self.points.is_just: res["points"] = to_dict(self.points.value) return res @classmethod def from_dict( cls: t.Type[QualityTestLog], d: t.Dict[str, t.Any] ) -> QualityTestLog: 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, points=parsed.points, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): import datetime from cg_maybe import Maybe, Nothing from cg_maybe.utils import maybe_from_nullable from .auto_test_step_log_base import AutoTestStepLogBase from .quality_test_log_base import QualityTestLogBase