Skip to content

Commit

Permalink
Move container stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Oct 9, 2024
1 parent 5d6b90d commit 620756d
Show file tree
Hide file tree
Showing 36 changed files with 946 additions and 923 deletions.
31 changes: 17 additions & 14 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
import tmt.utils.git
import tmt.utils.jira
from tmt.checks import Check
from tmt.container import (
SerializableContainer,
SpecBasedContainer,
container,
container_field,
container_fields,
field,
)
from tmt.lint import LinterOutcome, LinterReturn
from tmt.result import Result, ResultInterpret
from tmt.utils import (
Expand All @@ -64,14 +72,9 @@
EnvVarValue,
FmfContext,
Path,
SerializableContainer,
ShellScript,
SpecBasedContainer,
WorkdirArgumentType,
container_field,
container_fields,
dict_to_yaml,
field,
normalize_shell_script,
verdict,
)
Expand Down Expand Up @@ -137,7 +140,7 @@ class _RawFmfId(TypedDict, total=False):


# An internal fmf id representation.
@dataclasses.dataclass
@container
class FmfId(
SpecBasedContainer[_RawFmfId, _RawFmfId],
SerializableContainer,
Expand Down Expand Up @@ -411,7 +414,7 @@ class _RawDependencyFmfId(_RawFmfId):
type: Optional[str]


@dataclasses.dataclass
@container
class DependencyFmfId(
FmfId,
# Repeat the SpecBasedContainer, with more fitting in/out spec type.
Expand Down Expand Up @@ -500,7 +503,7 @@ class _RawDependencyFile(TypedDict):
pattern: Optional[list[str]]


@dataclasses.dataclass
@container
class DependencyFile(
SpecBasedContainer[_RawDependencyFile, _RawDependencyFile],
SerializableContainer,
Expand Down Expand Up @@ -649,7 +652,7 @@ def _normalize_link(key_address: str, value: _RawLinks, logger: tmt.log.Logger)
return Links(data=value)


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Core(
tmt.utils.ValidateFmfMixin,
tmt.utils.LoadFmfKeysMixin,
Expand Down Expand Up @@ -1030,7 +1033,7 @@ def has_link(self, needle: 'LinkNeedle') -> bool:
Node = Core


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Test(
Core,
tmt.export.Exportable['Test'],
Expand Down Expand Up @@ -1651,7 +1654,7 @@ def expand_node_data(data: T, fmf_context: FmfContext) -> T:
return data


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Plan(
Core,
tmt.export.Exportable['Plan'],
Expand Down Expand Up @@ -2594,7 +2597,7 @@ def __str__(self) -> str:
return self.value


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Story(
Core,
tmt.export.Exportable['Story'],
Expand Down Expand Up @@ -3331,7 +3334,7 @@ def init(
logger=logger)


@dataclasses.dataclass
@container
class RunData(SerializableContainer):
root: Optional[str]
plans: Optional[list[str]]
Expand Down Expand Up @@ -4084,7 +4087,7 @@ def matches(self, link: 'Link') -> bool:
return False


@dataclasses.dataclass
@container
class Link(SpecBasedContainer[Any, _RawLinkRelation]):
"""
An internal "link" as defined by tmt specification.
Expand Down
13 changes: 7 additions & 6 deletions tmt/checks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import dataclasses
import enum
import functools
from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypedDict, TypeVar, cast

import tmt.log
import tmt.steps.provision
import tmt.utils
from tmt.plugins import PluginRegistry
from tmt.utils import (
NormalizeKeysMixin,
from tmt.container import (
SerializableContainer,
SpecBasedContainer,
container,
field,
key_to_option,
)
from tmt.plugins import PluginRegistry
from tmt.utils import NormalizeKeysMixin

if TYPE_CHECKING:
import tmt.base
Expand Down Expand Up @@ -83,7 +84,7 @@ def from_spec(cls, spec: str) -> 'CheckEvent':
raise tmt.utils.SpecificationError(f"Invalid test check event '{spec}'.")


@dataclasses.dataclass
@container
class Check(
SpecBasedContainer[_RawCheck, _RawCheck],
SerializableContainer,
Expand Down Expand Up @@ -118,7 +119,7 @@ def from_spec( # type: ignore[override]

def to_spec(self) -> _RawCheck:
return cast(_RawCheck, {
tmt.utils.key_to_option(key): value
key_to_option(key): value
for key, value in self.items()
})

Expand Down
6 changes: 3 additions & 3 deletions tmt/checks/dmesg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
import datetime
import re
from re import Pattern
Expand All @@ -9,9 +8,10 @@
import tmt.steps.provision
import tmt.utils
from tmt.checks import Check, CheckEvent, CheckPlugin, _RawCheck, provides_check
from tmt.container import container, field
from tmt.result import CheckResult, ResultOutcome
from tmt.steps.provision import GuestCapability
from tmt.utils import Path, field, format_timestamp, render_run_exception_streams
from tmt.utils import Path, format_timestamp, render_run_exception_streams

if TYPE_CHECKING:
import tmt.base
Expand All @@ -29,7 +29,7 @@
]


@dataclasses.dataclass
@container
class DmesgCheck(Check):
failure_pattern: list[Pattern[str]] = field(
default_factory=lambda: DEFAULT_FAILURE_PATTERNS[:],
Expand Down
5 changes: 3 additions & 2 deletions tmt/checks/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import tmt.steps.provision.testcloud
import tmt.utils
from tmt.checks import Check, CheckPlugin, provides_check
from tmt.container import container, field
from tmt.result import CheckResult, ResultOutcome
from tmt.utils import Path, field, format_timestamp, render_run_exception_streams
from tmt.utils import Path, format_timestamp, render_run_exception_streams

if TYPE_CHECKING:
from tmt.steps.execute import TestInvocation
Expand Down Expand Up @@ -101,7 +102,7 @@ class GuestContext:
keep_running: bool = True


@dataclasses.dataclass
@container
class WatchdogCheck(Check):
interval: int = field(
default=60,
Expand Down
Loading

0 comments on commit 620756d

Please sign in to comment.