|
19 | 19 | Type, |
20 | 20 | ) |
21 | 21 | from airbyte_cdk.test import entrypoint_wrapper |
22 | | -from airbyte_cdk.test.declarative.models import ( |
| 22 | +from airbyte_cdk.test.standard_tests._job_runner import IConnector, run_test_job |
| 23 | +from airbyte_cdk.test.standard_tests.models import ( |
23 | 24 | ConnectorTestScenario, |
24 | 25 | ) |
25 | | -from airbyte_cdk.test.declarative.utils.job_runner import IConnector, run_test_job |
26 | 26 | from airbyte_cdk.test.standard_tests.test_resources import ( |
27 | 27 | ACCEPTANCE_TEST_CONFIG, |
28 | 28 | find_connector_root, |
|
32 | 32 | class ConnectorTestSuiteBase(abc.ABC): |
33 | 33 | """Base class for connector test suites.""" |
34 | 34 |
|
35 | | - connector: type[IConnector] | Callable[[], IConnector] | None |
| 35 | + connector: type[IConnector] | Callable[[], IConnector] | None # type: ignore [reportRedeclaration] |
36 | 36 | """The connector class or a factory function that returns an scenario of IConnector.""" |
37 | 37 |
|
| 38 | + @classproperty # type: ignore [no-redef] |
| 39 | + def connector(cls) -> type[IConnector] | Callable[[], IConnector] | None: |
| 40 | + """Get the connector class for the test suite. |
| 41 | +
|
| 42 | + This assumes a python connector and should be overridden by subclasses to provide the |
| 43 | + specific connector class to be tested. |
| 44 | + """ |
| 45 | + connector_root = cls.get_connector_root_dir() |
| 46 | + connector_name = connector_root.name |
| 47 | + |
| 48 | + expected_module_name = connector_name.replace("-", "_").lower() |
| 49 | + expected_class_name = connector_name.replace("-", "_").title().replace("_", "") |
| 50 | + |
| 51 | + # dynamically import and get the connector class: <expected_module_name>.<expected_class_name> |
| 52 | + |
| 53 | + # Dynamically import the module |
| 54 | + try: |
| 55 | + module = importlib.import_module(expected_module_name) |
| 56 | + except ModuleNotFoundError as e: |
| 57 | + raise ImportError(f"Could not import module '{expected_module_name}'.") from e |
| 58 | + |
| 59 | + # Dynamically get the class from the module |
| 60 | + try: |
| 61 | + return cast(type[IConnector], getattr(module, expected_class_name)) |
| 62 | + except AttributeError as e: |
| 63 | + # We did not find it based on our expectations, so let's check if we can find it |
| 64 | + # with a case-insensitive match. |
| 65 | + matching_class_name = next( |
| 66 | + (name for name in dir(module) if name.lower() == expected_class_name.lower()), |
| 67 | + None, |
| 68 | + ) |
| 69 | + if not matching_class_name: |
| 70 | + raise ImportError( |
| 71 | + f"Module '{expected_module_name}' does not have a class named '{expected_class_name}'." |
| 72 | + ) from e |
| 73 | + return cast(type[IConnector], getattr(module, matching_class_name)) |
| 74 | + |
38 | 75 | @classmethod |
39 | 76 | def get_test_class_dir(cls) -> Path: |
40 | 77 | """Get the file path that contains the class.""" |
@@ -85,43 +122,6 @@ def get_connector_root_dir(cls) -> Path: |
85 | 122 | """Get the root directory of the connector.""" |
86 | 123 | return find_connector_root([cls.get_test_class_dir(), Path.cwd()]) |
87 | 124 |
|
88 | | - @classproperty |
89 | | - def connector(cls) -> type[IConnector]: |
90 | | - """Get the connector class for the test suite. |
91 | | -
|
92 | | - This assumes a python connector and should be overridden by subclasses to provide the |
93 | | - specific connector class to be tested. |
94 | | - """ |
95 | | - connector_root = cls.get_connector_root_dir() |
96 | | - connector_name = connector_root.name |
97 | | - |
98 | | - expected_module_name = connector_name.replace("-", "_").lower() |
99 | | - expected_class_name = connector_name.replace("-", "_").title().replace("_", "") |
100 | | - |
101 | | - # dynamically import and get the connector class: <expected_module_name>.<expected_class_name> |
102 | | - |
103 | | - # Dynamically import the module |
104 | | - try: |
105 | | - module = importlib.import_module(expected_module_name) |
106 | | - except ModuleNotFoundError as e: |
107 | | - raise ImportError(f"Could not import module '{expected_module_name}'.") from e |
108 | | - |
109 | | - # Dynamically get the class from the module |
110 | | - try: |
111 | | - return getattr(module, expected_class_name) |
112 | | - except AttributeError as e: |
113 | | - # We did not find it based on our expectations, so let's check if we can find it |
114 | | - # with a case-insensitive match. |
115 | | - matching_class_name = next( |
116 | | - (name for name in dir(module) if name.lower() == expected_class_name.lower()), |
117 | | - None, |
118 | | - ) |
119 | | - if not matching_class_name: |
120 | | - raise ImportError( |
121 | | - f"Module '{expected_module_name}' does not have a class named '{expected_class_name}'." |
122 | | - ) from e |
123 | | - return getattr(module, matching_class_name) |
124 | | - |
125 | 125 | @classproperty |
126 | 126 | def acceptance_test_config_path(cls) -> Path: |
127 | 127 | """Get the path to the acceptance test config file.""" |
|
0 commit comments