-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathscenario.py
More file actions
74 lines (54 loc) · 2.32 KB
/
scenario.py
File metadata and controls
74 lines (54 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
"""Run acceptance tests in PyTest.
These tests leverage the same `acceptance-test-config.yml` configuration files as the
acceptance tests in CAT, but they run in PyTest instead of CAT. This allows us to run
the acceptance tests in the same local environment as we are developing in, speeding
up iteration cycles.
"""
from __future__ import annotations
from pathlib import Path
from typing import Any, Literal, cast
import yaml
from pydantic import BaseModel
class ConnectorTestScenario(BaseModel):
"""Acceptance test scenario, as a Pydantic model.
This class represents an acceptance test scenario, which is a single test case
that can be run against a connector. It is used to deserialize and validate the
acceptance test configuration file.
"""
class AcceptanceTestExpectRecords(BaseModel):
path: Path
exact_order: bool = False
class AcceptanceTestFileTypes(BaseModel):
skip_test: bool
bypass_reason: str
config_path: Path | None = None
config_dict: dict[str, Any] | None = None
id: str | None = None
configured_catalog_path: Path | None = None
timeout_seconds: int | None = None
expect_records: AcceptanceTestExpectRecords | None = None
file_types: AcceptanceTestFileTypes | None = None
status: Literal["succeed", "failed"] | None = None
def get_config_dict(self) -> dict[str, Any]:
"""Return the config dictionary.
If a config dictionary has already been loaded, return it. Otherwise, load
the config file and return the dictionary.
"""
if self.config_dict:
return self.config_dict
if self.config_path:
return cast(dict[str, Any], yaml.safe_load(self.config_path.read_text()))
raise ValueError("No config dictionary or path provided.")
@property
def expect_exception(self) -> bool:
return self.status and self.status == "failed" or False
@property
def instance_name(self) -> str:
return self.config_path.stem if self.config_path else "Unnamed Scenario"
def __str__(self) -> str:
if self.id:
return f"'{self.id}' Test Scenario"
if self.config_path:
return f"'{self.config_path.name}' Test Scenario"
return f"'{hash(self)}' Test Scenario"