-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
9 additions
and
41 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,51 +1,16 @@ | ||
""" | ||
Tests Dataset export override | ||
""" | ||
import sys | ||
from unittest import mock | ||
|
||
import airflow | ||
import pytest | ||
|
||
from cosmos.providers.dbt.dataset import Dataset | ||
|
||
@pytest.fixture(autouse=False) | ||
def reset_dataset_import() -> None: | ||
""" | ||
Remove all dataset imports from sys.modules. | ||
""" | ||
for key in list(sys.modules.keys()): | ||
if "dataset" in key.lower(): | ||
del sys.modules[key] | ||
|
||
def test_import() -> None: | ||
"Tests that we can import the Dataset object in all versions of Airflow." | ||
|
||
def test_failed_dataset_import(reset_dataset_import: None) -> None: | ||
""" | ||
Test that you can still import the Dataset class even if Airflow <= 2.5 is installed. | ||
""" | ||
with mock.patch.dict(sys.modules, {"airflow.datasets": None}): | ||
from cosmos.providers.dbt.dataset import Dataset | ||
|
||
assert Dataset.cosmos_override is True | ||
if airflow.__version__ >= "2.4.0": | ||
assert Dataset.__module__ == "airflow.datasets" | ||
else: | ||
assert Dataset.__module__ == "cosmos.providers.dbt.dataset" | ||
|
||
dataset = Dataset("my_dataset") | ||
assert dataset.id == "my_dataset" | ||
|
||
dataset_two = Dataset("my_dataset") | ||
assert dataset_two.id == "my_dataset" | ||
|
||
assert dataset == dataset_two | ||
|
||
|
||
@pytest.mark.skipif( | ||
airflow.__version__ < "2.5.0", | ||
reason="This test only applies to Airflow 2.5.0 and above", | ||
) | ||
def test_successful_dataset_import() -> None: | ||
""" | ||
Test that you can still import the Dataset class even if Airflow <= 2.5 is installed. | ||
""" | ||
from cosmos.providers.dbt.dataset import Dataset | ||
|
||
# this should be the airflow.datasets.Dataset class | ||
assert Dataset.__module__ == "airflow.datasets" |