debian-forge/test/integration_tests/test_case.py
Martin Sehnoutka ea68bb0c26 Test refactoring
The testing script is getting too big and not very well organized. In
this commit a new module `integration_tests` is introduced that contains
parts of the original testing script split into multiple files. The
content should be the same, the only difference is that now you can run
the tests by invoking `python3 -m test`.
2019-08-13 15:14:58 +02:00

38 lines
1,019 B
Python

from dataclasses import dataclass
from enum import Enum
from typing import List, Callable, Any
from . import evaluate_test, rel_path
from .build import run_osbuild
from .run import boot_image, extract_image
class IntegrationTestType(Enum):
EXTRACT=0
BOOT_WITH_QEMU=1
@dataclass
class IntegrationTestCase:
name: str
pipeline: str
output_image: str
test_cases: List[Callable[[Any], None]]
type: IntegrationTestType
def run(self):
run_osbuild(rel_path(f"pipelines/{self.pipeline}"))
if self.type == IntegrationTestType.BOOT_WITH_QEMU:
self.boot_and_run()
else:
self.extract_and_run()
def boot_and_run(self):
with boot_image(self.output_image):
for test in self.test_cases:
evaluate_test(test)
def extract_and_run(self):
with extract_image(self.output_image) as fstree:
for test in self.test_cases:
evaluate_test(lambda: test(fstree), name=test.__name__)