Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test): Allow mock server tests for manifest only sources #371

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,16 @@ def _get_class_from_fully_qualified_class_name(
try:
module_ref = importlib.import_module(module_name_full)
except ModuleNotFoundError as e:
raise ValueError(f"Could not load module `{module_name_full}`.") from e
if split[0] == "source_declarative_manifest":
# During testing, the modules containing the custom components are not moved to source_declarative_manifest. In order to run the test, add the source folder to your PYTHONPATH or add it runtime using sys.path.append
try:
import os
module_name_with_source_declarative_manifest = ".".join(split[1:-1])
module_ref = importlib.import_module(module_name_with_source_declarative_manifest)
except ModuleNotFoundError:
raise ValueError(f"Could not load module `{module_name_full}`.") from e
else:
raise ValueError(f"Could not load module `{module_name_full}`.") from e

try:
return getattr(module_ref, class_name)
Expand Down
17 changes: 11 additions & 6 deletions airbyte_cdk/sources/declarative/yaml_declarative_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ def __init__(
)

def _read_and_parse_yaml_file(self, path_to_yaml_file: str) -> ConnectionDefinition:
package = self.__class__.__module__.split(".")[0]
try:
# For testing purposes, we want to allow to just pass a file. However, this
with open(path_to_yaml_file, "r") as f:
return yaml.safe_load(f) # type: ignore # we assume the yaml represents a ConnectionDefinition
except FileNotFoundError:
# Running inside the container, the working directory during an operation is not structured the same as the static files
package = self.__class__.__module__.split(".")[0]

yaml_config = pkgutil.get_data(package, path_to_yaml_file)
if yaml_config:
decoded_yaml = yaml_config.decode()
return self._parse(decoded_yaml)
else:
yaml_config = pkgutil.get_data(package, path_to_yaml_file)
if yaml_config:
decoded_yaml = yaml_config.decode()
return self._parse(decoded_yaml)
return {}

def _emit_manifest_debug_message(self, extra_args: dict[str, Any]) -> None:
Expand Down
Loading