Skip to content

Commit 4fc4932

Browse files
committed
typing fixes
1 parent ea848b0 commit 4fc4932

File tree

7 files changed

+45
-54
lines changed

7 files changed

+45
-54
lines changed

airbyte_cdk/cli/airbyte_cdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949

5050
@click.group(
51-
help=cast(str, __doc__).replace("\n", "\n\n"), # Workaround to format help text correctly
51+
help=__doc__.replace("\n", "\n\n"), # Workaround to format help text correctly
5252
invoke_without_command=True,
5353
)
5454
@click.option(

airbyte_cdk/cli/airbyte_cdk/_connector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import os
4242
from pathlib import Path
43+
from types import ModuleType
4344

4445
import rich_click as click
4546

@@ -49,6 +50,7 @@
4950

5051
click.rich_click.TEXT_MARKUP = "markdown"
5152

53+
pytest: ModuleType | None
5254
try:
5355
import pytest
5456
except ImportError:
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
from airbyte_cdk.test.declarative.models.scenario import (
2-
ConnectorTestScenario,
3-
)
4-
5-
__all__ = [
6-
"ConnectorTestScenario",
7-
]

airbyte_cdk/test/declarative/utils/job_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Status,
1717
)
1818
from airbyte_cdk.test import entrypoint_wrapper
19-
from airbyte_cdk.test.declarative.models import (
19+
from airbyte_cdk.test.standard_tests.models import (
2020
ConnectorTestScenario,
2121
)
2222

airbyte_cdk/test/standard_tests/connector_base.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
Type,
2020
)
2121
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 (
2324
ConnectorTestScenario,
2425
)
25-
from airbyte_cdk.test.declarative.utils.job_runner import IConnector, run_test_job
2626
from airbyte_cdk.test.standard_tests.test_resources import (
2727
ACCEPTANCE_TEST_CONFIG,
2828
find_connector_root,
@@ -32,9 +32,46 @@
3232
class ConnectorTestSuiteBase(abc.ABC):
3333
"""Base class for connector test suites."""
3434

35-
connector: type[IConnector] | Callable[[], IConnector] | None
35+
connector: type[IConnector] | Callable[[], IConnector] | None # type: ignore [reportRedeclaration]
3636
"""The connector class or a factory function that returns an scenario of IConnector."""
3737

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+
3875
@classmethod
3976
def get_test_class_dir(cls) -> Path:
4077
"""Get the file path that contains the class."""
@@ -85,43 +122,6 @@ def get_connector_root_dir(cls) -> Path:
85122
"""Get the root directory of the connector."""
86123
return find_connector_root([cls.get_test_class_dir(), Path.cwd()])
87124

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-
125125
@classproperty
126126
def acceptance_test_config_path(cls) -> Path:
127127
"""Get the path to the acceptance test config file."""

airbyte_cdk/test/standard_tests/declarative_sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from airbyte_cdk.sources.declarative.concurrent_declarative_source import (
1010
ConcurrentDeclarativeSource,
1111
)
12-
from airbyte_cdk.test.declarative.models import ConnectorTestScenario
1312
from airbyte_cdk.test.declarative.utils.job_runner import IConnector
13+
from airbyte_cdk.test.standard_tests.models import ConnectorTestScenario
1414
from airbyte_cdk.test.standard_tests.source_base import SourceTestSuiteBase
1515
from airbyte_cdk.test.standard_tests.test_resources import MANIFEST_YAML
1616

airbyte_cdk/test/standard_tests/source_base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
Type,
1414
)
1515
from airbyte_cdk.test import entrypoint_wrapper
16-
from airbyte_cdk.test.declarative.models import (
17-
ConnectorTestScenario,
18-
)
19-
from airbyte_cdk.test.declarative.utils.job_runner import run_test_job
2016
from airbyte_cdk.test.standard_tests._job_runner import run_test_job
2117
from airbyte_cdk.test.standard_tests.connector_base import (
2218
ConnectorTestSuiteBase,

0 commit comments

Comments
 (0)