-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to consolidate async dbt adapter code (#1509)
This PR addresses the feedback in PR #1474 suggesting to consolidate dbt adapter methods in the _asynchronous module and additionally avoiding keeping dictionary type maps for adapter callables. closes: #1508
- Loading branch information
1 parent
03358bf
commit bdb77e4
Showing
11 changed files
with
152 additions
and
138 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import importlib | ||
from typing import Any, Callable | ||
|
||
|
||
def load_method_from_module(module_path: str, method_name: str) -> Callable[..., Any]: | ||
try: | ||
module = importlib.import_module(module_path) | ||
method = getattr(module, method_name) | ||
return method # type: ignore | ||
except ModuleNotFoundError: | ||
raise ModuleNotFoundError(f"Module {module_path} not found") | ||
except AttributeError: | ||
raise AttributeError(f"Method {method_name} not found in module {module_path}") |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sys | ||
import types | ||
|
||
import pytest | ||
|
||
from cosmos._utils.importer import load_method_from_module | ||
|
||
dummy_module_text = """ | ||
def dummy_method(): | ||
return "Hello from dummy_method" | ||
""" | ||
|
||
|
||
@pytest.fixture | ||
def create_dummy_module(): | ||
"""Creates a temporary in-memory module with a dummy method.""" | ||
module_name = "test_dummy_module" | ||
method_name = "dummy_method" | ||
|
||
module = types.ModuleType(module_name) | ||
exec(dummy_module_text, module.__dict__) | ||
|
||
sys.modules[module_name] = module | ||
|
||
yield module_name, method_name | ||
|
||
del sys.modules[module_name] | ||
|
||
|
||
def test_load_valid_method(create_dummy_module): | ||
"""Test that a valid method is loaded successfully.""" | ||
module_name, method_name = create_dummy_module | ||
method = load_method_from_module(module_name, method_name) | ||
assert callable(method) | ||
assert method() == "Hello from dummy_method" | ||
|
||
|
||
def test_load_invalid_module(): | ||
"""Test that ModuleNotFoundError is raised for an invalid module.""" | ||
with pytest.raises(ModuleNotFoundError, match="Module invalid_module not found"): | ||
load_method_from_module("invalid_module", "dummy_method") | ||
|
||
|
||
def test_load_invalid_method(create_dummy_module): | ||
"""Test that AttributeError is raised for a missing method in a valid module.""" | ||
module_name, _ = create_dummy_module | ||
with pytest.raises(AttributeError, match=f"Method invalid_method not found in module {module_name}"): | ||
load_method_from_module(module_name, "invalid_method") |