44from __future__ import annotations
55
66import abc
7+ import inspect
8+ import sys
79from pathlib import Path
810from typing import Any , Literal
911
2325from airbyte_cdk .test .declarative .utils .job_runner import IConnector , run_test_job
2426
2527ACCEPTANCE_TEST_CONFIG = "acceptance-test-config.yml"
26-
28+ MANIFEST_YAML = "manifest.yaml"
2729
2830class JavaClass (str ):
2931 """A string that represents a Java class."""
@@ -87,12 +89,12 @@ class TestMyConnector(ConnectorTestSuiteBase):
8789class ConnectorTestSuiteBase (abc .ABC ):
8890 """Base class for connector test suites."""
8991
90- acceptance_test_file_path = Path ( "./acceptance-test-config.json" )
91- """The path to the acceptance test config file.
92-
93- By default, this is set to the `acceptance-test-config.json` file in
94- the root of the connector source directory.
95- """
92+ @ classmethod
93+ def get_test_class_dir ( cls ) -> Path :
94+ """Get the file path that contains the class."""
95+ module = sys . modules [ cls . __module__ ]
96+ # Get the directory containing the test file
97+ return Path ( inspect . getfile ( module )). parent
9698
9799 connector : type [Connector ] | Path | JavaClass | DockerImage | None = None
98100 """The connector class or path to the connector to test."""
@@ -142,22 +144,56 @@ def test_check(
142144 )
143145
144146 @classproperty
145- def acceptance_test_config_path ( self ) -> Path :
147+ def manifest_yml_path ( cls ) -> Path :
146148 """Get the path to the acceptance test config file.
147149
148- Check vwd and parent directories of cwd for the config file, and return the first one found.
150+ Check cwd and parent directories of cwd for the config file, and return the first one found.
149151
150152 Give up if the config file is not found in any parent directory.
151153 """
152- current_dir = Path .cwd ()
153- for parent_dir in current_dir .parents :
154- config_path = parent_dir / ACCEPTANCE_TEST_CONFIG
155- if config_path .exists ():
156- return config_path
154+ result = cls .connector_root_dir / MANIFEST_YAML
155+ if result .exists ():
156+ return result
157+
157158 raise FileNotFoundError (
158- f"Acceptance test config file not found in any parent directory from : { Path .cwd ()} "
159+ f"Manifest file not found at: { str (result )} . "
160+ f"Please check if the file exists in the connector root directory."
159161 )
160162
163+ @classproperty
164+ def connector_root_dir (cls ) -> Path :
165+ """Get the root directory of the connector."""
166+ for parent in cls .get_test_class_dir ().parents :
167+ if (parent / MANIFEST_YAML ).exists ():
168+ return parent
169+ if (parent / ACCEPTANCE_TEST_CONFIG ).exists ():
170+ return parent
171+ if parent .name == "airbyte_cdk" :
172+ break
173+ # If we reach here, we didn't find the manifest file in any parent directory
174+ # Check if the manifest file exists in the current directory
175+ for parent in Path .cwd ().parents :
176+ if (parent / MANIFEST_YAML ).exists ():
177+ return parent
178+ if (parent / ACCEPTANCE_TEST_CONFIG ).exists ():
179+ return parent
180+ if parent .name == "airbyte_cdk" :
181+ break
182+
183+ raise FileNotFoundError (
184+ "Could not find connector root directory relative to "
185+ f"'{ str (cls .get_test_class_dir ())} ' or '{ str (Path .cwd ())} '."
186+ )
187+
188+ @classproperty
189+ def acceptance_test_config_path (cls ) -> Path :
190+ """Get the path to the acceptance test config file."""
191+ result = cls .connector_root_dir / ACCEPTANCE_TEST_CONFIG
192+ if result .exists ():
193+ return result
194+
195+ raise FileNotFoundError (f"Acceptance test config file not found at: { str (result )} " )
196+
161197 @classmethod
162198 def get_scenarios (
163199 cls ,
@@ -184,7 +220,7 @@ def get_scenarios(
184220 for test in all_tests_config ["acceptance_tests" ][category ]["tests" ]
185221 if "iam_role" not in test ["config_path" ]
186222 ]
187- working_dir = cls .working_dir or Path ()
223+ working_dir = cls .get_test_class_dir ()
188224 for test in tests_scenarios :
189225 if test .config_path :
190226 test .config_path = working_dir / test .config_path
0 commit comments