Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## dbt-databricks 1.1.0 (Release TBD)

### Under the hood
- Port testing framework changes from [dbt-labs/dbt-spark#299](https://github.com/dbt-labs/dbt-spark/pull/299) and [dbt-labs/dbt-spark#314](https://github.com/dbt-labs/dbt-spark/pull/314) ([#70](https://github.com/databricks/dbt-databricks/pull/70))

## dbt-databricks 1.0.2 (March 31, 2022)

### Features
Expand Down
21 changes: 10 additions & 11 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# install latest changes in dbt-core
# TODO: how to automate switching from develop to version branches?
git+https://github.com/dbt-labs/dbt.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter

# install latest changes in dbt-spark
# TODO: how to automate switching from develop to version branches?
git+https://github.com/dbt-labs/dbt-spark.git#egg=dbt-spark

freezegun==0.3.9
pytest==6.0.2
pytest>=6.0.2
mock>=1.3.0
flake8>=3.5.0
pytz==2017.2
bumpversion==0.5.3
tox==3.2.0
flake8
pytz
tox>=3.2.0
ipdb
pytest-xdist>=2.1.0,<3
flaky>=3.5.3,<4
pytest-xdist
pytest-dotenv
pytest-csv
flaky

mypy==0.920
black==22.3.0

# Test requirements
pytest-dbt-adapter==0.6.0
10 changes: 10 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[pytest]
filterwarnings =
ignore:.*'soft_unicode' has been renamed to 'soft_str'*:DeprecationWarning
ignore:unclosed file .*:ResourceWarning
env_files =
test.env
testpaths =
tests/unit
tests/integration
tests/functional
85 changes: 85 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import pytest
import os

pytest_plugins = ["dbt.tests.fixtures.project"]


def pytest_addoption(parser):
parser.addoption("--profile", action="store", default="databricks_cluster", type=str)


# Using @pytest.mark.skip_profile('databricks_cluster') uses the 'skip_by_adapter_type'
# autouse fixture below
def pytest_configure(config):
config.addinivalue_line(
"markers",
"skip_profile(profile): skip test for the given profile",
)


@pytest.fixture(scope="session")
def dbt_profile_target(request):
profile_type = request.config.getoption("--profile")
if profile_type == "databricks_cluster":
target = databricks_cluster_target()
elif profile_type == "databricks_sql_endpoint":
target = databricks_sql_endpoint_target()
elif profile_type == "databricks_uc_cluster":
target = databricks_uc_cluster_target()
elif profile_type == "databricks_uc_sql_endpoint":
target = databricks_uc_sql_endpoint_target()
else:
raise ValueError(f"Invalid profile type '{profile_type}'")
return target


def databricks_cluster_target():
return {
"type": "databricks",
"host": os.getenv("DBT_DATABRICKS_HOST_NAME"),
"http_path": os.getenv(
"DBT_DATABRICKS_CLUSTER_HTTP_PATH", os.getenv("DBT_DATABRICKS_HTTP_PATH")
),
"token": os.getenv("DBT_DATABRICKS_TOKEN"),
}


def databricks_sql_endpoint_target():
return {
"type": "databricks",
"host": os.getenv("DBT_DATABRICKS_HOST_NAME"),
"http_path": os.getenv(
"DBT_DATABRICKS_ENDPOINT_HTTP_PATH", os.getenv("DBT_DATABRICKS_HTTP_PATH")
),
"token": os.getenv("DBT_DATABRICKS_TOKEN"),
}


def databricks_uc_cluster_target():
return {
"type": "databricks",
"host": os.getenv("DBT_DATABRICKS_HOST_NAME"),
"http_path": os.getenv(
"DBT_DATABRICKS_UC_CLUSTER_HTTP_PATH", os.getenv("DBT_DATABRICKS_HTTP_PATH")
),
"token": os.getenv("DBT_DATABRICKS_TOKEN"),
}


def databricks_uc_sql_endpoint_target():
return {
"type": "databricks",
"host": os.getenv("DBT_DATABRICKS_HOST_NAME"),
"http_path": os.getenv(
"DBT_DATABRICKS_UC_ENDPOINT_HTTP_PATH", os.getenv("DBT_DATABRICKS_HTTP_PATH")
),
"token": os.getenv("DBT_DATABRICKS_TOKEN"),
}


@pytest.fixture(autouse=True)
def skip_by_profile_type(request):
profile_type = request.config.getoption("--profile")
if request.node.get_closest_marker("skip_profile"):
if request.node.get_closest_marker("skip_profile").args[0] == profile_type:
pytest.skip("skipped on '{profile_type}' profile")
47 changes: 47 additions & 0 deletions tests/functional/adapter/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import (
BaseSingularTestsEphemeral,
)
from dbt.tests.adapter.basic.test_empty import BaseEmpty
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral
from dbt.tests.adapter.basic.test_incremental import BaseIncremental
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp


class TestSimpleMaterializationsDatabricks(BaseSimpleMaterializations):
pass


class TestSingularTestsDatabricks(BaseSingularTests):
pass


class TestSingularTestsEphemeralDatabricks(BaseSingularTestsEphemeral):
pass


class TestEmptyDatabricks(BaseEmpty):
pass


class TestEphemeralDatabricks(BaseEphemeral):
pass


class TestIncrementalDatabricks(BaseIncremental):
pass


class TestGenericTestsDatabricks(BaseGenericTests):
pass


class TestSnapshotCheckColsDatabricks(BaseSnapshotCheckCols):
pass


class TestSnapshotTimestampDatabricks(BaseSnapshotTimestamp):
pass
2 changes: 2 additions & 0 deletions tests/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(self):


class TestArgs:
__test__ = False

def __init__(self, kwargs):
self.which = "run"
self.single_threaded = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from tests.integration.base import DBTIntegrationTest, use_profile


TestResults = namedtuple(
"TestResults",
ResultHolder = namedtuple(
"ResultHolder",
[
"seed_count",
"model_count",
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_scenario_correctness(self, expected_fields, test_case_fields):
self.assertTablesEqual(expected_fields.relation, test_case_fields.relation)

def stub_expected_fields(self, relation, seed_rows, opt_model_count=None):
return TestResults(
return ResultHolder(
seed_count=1,
model_count=1,
seed_rows=seed_rows,
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_no_unique_keys(self):
update_sql_file = "add_new_rows"

expected_fields = self.stub_expected_fields(relation=seed, seed_rows=seed_rows)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=None,
relation=incremental_model,
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_empty_str_unique_key(self):
update_sql_file = "add_new_rows"

expected_fields = self.stub_expected_fields(relation=seed, seed_rows=seed_rows)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=None,
relation=incremental_model,
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_one_unique_key(self):
expected_fields = self.stub_expected_fields(
relation=expected_model, seed_rows=seed_rows, opt_model_count=1
)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=self.update_incremental_model(expected_model),
relation=incremental_model,
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_empty_unique_key_list(self):
update_sql_file = "add_new_rows"

expected_fields = self.stub_expected_fields(relation=seed, seed_rows=seed_rows)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=None,
relation=incremental_model,
Expand Down Expand Up @@ -274,7 +274,7 @@ def test_unary_unique_key_list(self):
expected_fields = self.stub_expected_fields(
relation=expected_model, seed_rows=seed_rows, opt_model_count=1
)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=self.update_incremental_model(expected_model),
relation=incremental_model,
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_duplicated_unary_unique_key_list(self):
expected_fields = self.stub_expected_fields(
relation=expected_model, seed_rows=seed_rows, opt_model_count=1
)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=self.update_incremental_model(expected_model),
relation=incremental_model,
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_trinary_unique_key_list(self):
expected_fields = self.stub_expected_fields(
relation=expected_model, seed_rows=seed_rows, opt_model_count=1
)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=self.update_incremental_model(expected_model),
relation=incremental_model,
Expand Down Expand Up @@ -377,7 +377,7 @@ def test_trinary_unique_key_list_no_update(self):
update_sql_file = "add_new_rows"

expected_fields = self.stub_expected_fields(relation=seed, seed_rows=seed_rows)
test_case_fields = TestResults(
test_case_fields = ResultHolder(
*self.setup_test(seed, incremental_model, update_sql_file),
opt_model_count=None,
relation=incremental_model,
Expand Down
30 changes: 0 additions & 30 deletions tests/specs/databricks-cluster.dbtspec

This file was deleted.

31 changes: 0 additions & 31 deletions tests/specs/databricks-sql-endpoint.dbtspec

This file was deleted.

35 changes: 0 additions & 35 deletions tests/specs/databricks-uc-cluster.dbtspec

This file was deleted.

Loading