Skip to content

Commit e2a9fb9

Browse files
committed
fix more tests
1 parent 015ced9 commit e2a9fb9

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

airbyte_cdk/test/declarative/test_suites/connector_base.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ def get_test_class_dir(cls) -> Path:
100100
connector: type[Connector] | Path | JavaClass | DockerImage | None = None
101101
"""The connector class or path to the connector to test."""
102102

103-
working_dir: Path | None = None
104-
"""The root directory of the connector source code."""
105-
106103
@classmethod
107104
def create_connector(
108105
cls,
@@ -144,23 +141,6 @@ def test_check(
144141
f"Expected exactly one CONNECTION_STATUS message. Got: {result._messages}"
145142
)
146143

147-
@classproperty
148-
def manifest_yml_path(cls) -> Path:
149-
"""Get the path to the acceptance test config file.
150-
151-
Check cwd and parent directories of cwd for the config file, and return the first one found.
152-
153-
Give up if the config file is not found in any parent directory.
154-
"""
155-
result = cls.get_connector_root_dir() / MANIFEST_YAML
156-
if result.exists():
157-
return result
158-
159-
raise FileNotFoundError(
160-
f"Manifest file not found at: {str(result)}. "
161-
f"Please check if the file exists in the connector root directory."
162-
)
163-
164144
@classmethod
165145
def get_connector_root_dir(cls) -> Path:
166146
"""Get the root directory of the connector."""
@@ -221,10 +201,11 @@ def get_scenarios(
221201
for test in all_tests_config["acceptance_tests"][category]["tests"]
222202
if "iam_role" not in test["config_path"]
223203
]
224-
working_dir = cls.get_test_class_dir()
204+
connector_root = cls.get_connector_root_dir().absolute()
225205
for test in tests_scenarios:
226206
if test.config_path:
227-
test.config_path = working_dir / test.config_path
207+
test.config_path = connector_root / test.config_path
228208
if test.configured_catalog_path:
229-
test.configured_catalog_path = working_dir / test.configured_catalog_path
209+
test.configured_catalog_path = connector_root / test.configured_catalog_path
210+
230211
return tests_scenarios

airbyte_cdk/test/declarative/test_suites/declarative_sources.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
from typing import Any, cast
55

66
import yaml
7+
from boltons.typeutils import classproperty
78

89
from airbyte_cdk.sources.declarative.concurrent_declarative_source import (
910
ConcurrentDeclarativeSource,
1011
)
1112
from airbyte_cdk.test.declarative.models import ConnectorTestScenario
13+
from airbyte_cdk.test.declarative.test_suites.connector_base import MANIFEST_YAML
1214
from airbyte_cdk.test.declarative.test_suites.source_base import (
1315
SourceTestSuiteBase,
1416
)
@@ -21,8 +23,26 @@ def md5_checksum(file_path: Path) -> str:
2123

2224

2325
class DeclarativeSourceTestSuite(SourceTestSuiteBase):
24-
manifest_path = Path("manifest.yaml")
25-
components_py_path: Path | None = None
26+
@classproperty
27+
def manifest_yaml_path(cls) -> Path:
28+
"""Get the path to the manifest.yaml file."""
29+
result = cls.get_connector_root_dir() / MANIFEST_YAML
30+
if result.exists():
31+
return result
32+
33+
raise FileNotFoundError(
34+
f"Manifest YAML file not found at {result}. "
35+
"Please ensure that the test suite is run in the correct directory.",
36+
)
37+
38+
@classproperty
39+
def components_py_path(cls) -> Path | None:
40+
"""Get the path to the components.py file."""
41+
result = cls.get_connector_root_dir() / "components.py"
42+
if result.exists():
43+
return result
44+
45+
return None
2646

2747
@classmethod
2848
def create_connector(
@@ -35,7 +55,7 @@ def create_connector(
3555
# state = scenario.get_state()
3656
# source_config = scenario.get_source_config()
3757

38-
manifest_dict = yaml.safe_load(cls.manifest_path.read_text())
58+
manifest_dict = yaml.safe_load(cls.manifest_yaml_path.read_text())
3959
if cls.components_py_path and cls.components_py_path.exists():
4060
os.environ["AIRBYTE_ENABLE_UNSAFE_CODE"] = "true"
4161
config["__injected_components_py"] = cls.components_py_path.read_text()

airbyte_cdk/test/declarative/utils/job_runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def run_test_job(
4545
if isinstance(connector, type) or callable(connector):
4646
# If the connector is a class or a factory lambda, instantiate it.
4747
connector_obj = connector()
48-
elif isinstance(connector, IConnector):
48+
elif isinstance(
49+
connector, IConnector,
50+
) or True: # TODO: Get a valid protocol check here
4951
connector_obj = connector
5052
else:
5153
raise ValueError(

unit_tests/source_declarative_manifest/test_source_declarative_w_custom_components.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
custom_code_execution_permitted,
3333
register_components_module_from_string,
3434
)
35+
from airbyte_cdk.test.declarative.test_suites.connector_base import MANIFEST_YAML
3536

3637
SAMPLE_COMPONENTS_PY_TEXT = """
3738
def sample_function() -> str:
@@ -90,14 +91,14 @@ def get_py_components_config_dict(
9091
failing_components: bool = False,
9192
) -> dict[str, Any]:
9293
connector_dir = Path(get_resource_path("source_pokeapi_w_components_py"))
93-
manifest_yml_path: Path = connector_dir / "manifest.yaml"
94+
manifest_yaml_path: Path = connector_dir / MANIFEST_YAML
9495
custom_py_code_path: Path = connector_dir / (
9596
"components.py" if not failing_components else "components_failing.py"
9697
)
9798
config_yaml_path: Path = connector_dir / "valid_config.yaml"
98-
secrets_yaml_path: Path = connector_dir / "secrets.yaml"
99+
# secrets_yaml_path: Path = connector_dir / "secrets.yaml"
99100

100-
manifest_dict = yaml.safe_load(manifest_yml_path.read_text())
101+
manifest_dict = yaml.safe_load(manifest_yaml_path.read_text())
101102
assert manifest_dict, "Failed to load the manifest file."
102103
assert isinstance(manifest_dict, Mapping), (
103104
f"Manifest file is type {type(manifest_dict).__name__}, not a mapping: {manifest_dict}"

0 commit comments

Comments
 (0)