BaseRunner: Pass RunbookBuilder

This commit is contained in:
Kameron Carr 2023-08-17 15:49:46 -07:00 коммит произвёл Kameron Carr
Родитель 51d8d4e4f9
Коммит 36f9249bc5
3 изменённых файлов: 17 добавлений и 8 удалений

Просмотреть файл

@ -9,6 +9,7 @@ from dataclasses_json import dataclass_json
from marshmallow import validate
from lisa import schema
from lisa.parameter_parser.runbook import RunbookBuilder
from lisa.runner import BaseRunner
from lisa.schema import BaseTestCaseFilter
from lisa.util import field_metadata
@ -41,10 +42,14 @@ class MockRunner(BaseRunner):
_is_done = False
def __init__(
self, runbook: schema.Runbook, index: int, case_variables: Dict[str, Any]
self,
runbook_builder: RunbookBuilder,
runbook: schema.Runbook,
index: int,
case_variables: Dict[str, Any],
) -> None:
self._is_done = False
super().__init__(runbook, index, case_variables)
super().__init__(runbook_builder, runbook, index, case_variables)
@classmethod
def type_name(cls) -> str:

Просмотреть файл

@ -94,11 +94,13 @@ class BaseRunner(BaseClassMixin, InitializableMixin):
def __init__(
self,
runbook_builder: RunbookBuilder,
runbook: schema.Runbook,
index: int,
case_variables: Dict[str, Any],
) -> None:
super().__init__()
self._runbook_builder = runbook_builder
self._runbook = runbook
self.id = f"{self.type_name()}_{index}"
@ -273,9 +275,7 @@ class RootRunner(Action):
sub_runbook_builder, phase=constants.TRANSFORMER_PHASE_EXPANDED
)
runners = self._generate_runners(
sub_runbook_builder.resolve(), variables
)
runners = self._generate_runners(sub_runbook_builder, variables)
for runner in runners:
yield runner
@ -290,7 +290,7 @@ class RootRunner(Action):
)
for runner in self._generate_runners(
root_runbook, self._runbook_builder.variables
self._runbook_builder, self._runbook_builder.variables
):
yield runner
@ -300,9 +300,10 @@ class RootRunner(Action):
)
def _generate_runners(
self, runbook: schema.Runbook, variables: Dict[str, VariableEntry]
self, runbook_builder: RunbookBuilder, variables: Dict[str, VariableEntry]
) -> Iterator[BaseRunner]:
# group filters by runner type
runbook = runbook_builder.resolve(variables=variables)
case_variables = get_case_variables(variables)
runner_filters: Dict[str, List[schema.BaseTestCaseFilter]] = {}
for raw_filter in runbook.testcase_raw:
@ -329,6 +330,7 @@ class RootRunner(Action):
runbook.testcase = parse_testcase_filters(raw_filters)
runner = factory.create_by_type_name(
type_name=runner_name,
runbook_builder=runbook_builder,
runbook=runbook,
index=self._runner_count,
case_variables=case_variables,

Просмотреть файл

@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from pathlib import Path
from typing import List, Optional, Union, cast
from unittest import TestCase
@ -9,6 +10,7 @@ from lisa import LisaException, constants, schema
from lisa.environment import EnvironmentStatus, load_environments
from lisa.messages import TestResultMessage, TestStatus
from lisa.notifier import register_notifier
from lisa.parameter_parser.runbook import RunbookBuilder
from lisa.runner import RunnerResult
from lisa.runners.lisa_runner import LisaRunner
from lisa.testsuite import TestResult, simple_requirement
@ -43,7 +45,7 @@ def generate_runner(
runbook.wait_resource_timeout = 0
if env_runbook:
runbook.environment = env_runbook
runner = LisaRunner(runbook, 0, {})
runner = LisaRunner(RunbookBuilder(Path("mock_runbook.yml")), runbook, 0, {})
return runner