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

Add new basic tests TestDocsGenerateDatabricks and TestDocsGenReferencesDatabricks #134

Merged
merged 4 commits into from
Jul 21, 2022
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
4 changes: 2 additions & 2 deletions dbt/adapters/databricks/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def parse_describe_extended(
table_owner=str(metadata.get(KEY_TABLE_OWNER)),
table_stats=table_stats,
column=column["col_name"],
column_index=idx,
column_index=(idx + 1),
dtype=column["data_type"],
)
for idx, column in enumerate(rows)
Expand All @@ -177,7 +177,7 @@ def parse_columns_from_information(
table_schema=relation.schema,
table_name=relation.table,
table_type=relation.type,
column_index=match_num,
column_index=(match_num + 1),
table_owner=owner,
column=column_name,
dtype=column_type,
Expand Down
64 changes: 61 additions & 3 deletions tests/functional/adapter/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import pytest

from dbt.tests.adapter.basic.expected_catalog import (
base_expected_catalog,
expected_references_catalog,
)
from dbt.tests.util import AnyInteger, AnyString

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_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
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod
from dbt.tests.adapter.basic.test_docs_generate import BaseDocsGenerate, BaseDocsGenReferences


class TestSimpleMaterializationsDatabricks(BaseSimpleMaterializations):
Expand Down Expand Up @@ -50,3 +57,54 @@ class TestSnapshotTimestampDatabricks(BaseSnapshotTimestamp):

class TestBaseAdapterMethodDatabricks(BaseAdapterMethod):
pass


class TestDocsGenerateDatabricks(BaseDocsGenerate):
@pytest.fixture(scope="class")
def expected_catalog(self, project):
return base_expected_catalog(
project,
role=AnyString(),
id_type="long",
text_type="string",
time_type="timestamp",
view_type="view",
table_type="table",
model_stats=_StatsLikeDict(),
)


class TestDocsGenReferencesDatabricks(BaseDocsGenReferences):
@pytest.fixture(scope="class")
def expected_catalog(self, project):
return expected_references_catalog(
project,
role=AnyString(),
id_type="long",
text_type="string",
time_type="timestamp",
bigint_type="long",
view_type="view",
table_type="table",
model_stats=_StatsLikeDict(),
)


class _StatsLikeDict:
"""Any stats-like dict. Use this in assert calls"""

def __eq__(self, other):
return (
isinstance(other, dict)
and "has_stats" in other
and (
other["has_stats"]
== {
"id": "has_stats",
"label": "Has Stats?",
"value": AnyInteger(),
"description": "Indicates whether there are statistics for this table",
"include": False,
}
)
)
22 changes: 11 additions & 11 deletions tests/unit/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_parse_relation(self):
"table_type": rel_type,
"table_owner": "root",
"column": "col1",
"column_index": 0,
"column_index": 1,
"dtype": "decimal(22,0)",
"numeric_scale": None,
"numeric_precision": None,
Expand All @@ -260,7 +260,7 @@ def test_parse_relation(self):
"table_type": rel_type,
"table_owner": "root",
"column": "col2",
"column_index": 1,
"column_index": 2,
"dtype": "string",
"numeric_scale": None,
"numeric_precision": None,
Expand All @@ -277,7 +277,7 @@ def test_parse_relation(self):
"table_type": rel_type,
"table_owner": "root",
"column": "dt",
"column_index": 2,
"column_index": 3,
"dtype": "date",
"numeric_scale": None,
"numeric_precision": None,
Expand All @@ -294,7 +294,7 @@ def test_parse_relation(self):
"table_type": rel_type,
"table_owner": "root",
"column": "struct_col",
"column_index": 3,
"column_index": 4,
"dtype": "struct<struct_inner_col:string>",
"numeric_scale": None,
"numeric_precision": None,
Expand Down Expand Up @@ -368,7 +368,7 @@ def test_parse_relation_with_statistics(self):
"table_type": rel_type,
"table_owner": "root",
"column": "col1",
"column_index": 0,
"column_index": 1,
"dtype": "decimal(22,0)",
"numeric_scale": None,
"numeric_precision": None,
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_parse_columns_from_information_with_table_type_and_delta_provider(self)
"table_type": rel_type,
"table_owner": "root",
"column": "col1",
"column_index": 0,
"column_index": 1,
"dtype": "decimal(22,0)",
"numeric_scale": None,
"numeric_precision": None,
Expand All @@ -457,7 +457,7 @@ def test_parse_columns_from_information_with_table_type_and_delta_provider(self)
"table_type": rel_type,
"table_owner": "root",
"column": "struct_col",
"column_index": 3,
"column_index": 4,
"dtype": "struct",
"numeric_scale": None,
"numeric_precision": None,
Expand Down Expand Up @@ -521,7 +521,7 @@ def test_parse_columns_from_information_with_view_type(self):
"table_type": rel_type,
"table_owner": "root",
"column": "col2",
"column_index": 1,
"column_index": 2,
"dtype": "string",
"numeric_scale": None,
"numeric_precision": None,
Expand All @@ -538,7 +538,7 @@ def test_parse_columns_from_information_with_view_type(self):
"table_type": rel_type,
"table_owner": "root",
"column": "struct_col",
"column_index": 3,
"column_index": 4,
"dtype": "struct",
"numeric_scale": None,
"numeric_precision": None,
Expand Down Expand Up @@ -587,7 +587,7 @@ def test_parse_columns_from_information_with_table_type_and_parquet_provider(sel
"table_type": rel_type,
"table_owner": "root",
"column": "dt",
"column_index": 2,
"column_index": 3,
"dtype": "date",
"numeric_scale": None,
"numeric_precision": None,
Expand All @@ -612,7 +612,7 @@ def test_parse_columns_from_information_with_table_type_and_parquet_provider(sel
"table_type": rel_type,
"table_owner": "root",
"column": "struct_col",
"column_index": 3,
"column_index": 4,
"dtype": "struct",
"numeric_scale": None,
"numeric_precision": None,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist = linter, unit
[testenv:linter]
basepython = python3
commands = /bin/bash -c '$(which black) --config black.ini --check .'
/bin/bash -c '$(which flake8) --select=E,W,F --ignore=E203 --max-line-length=100 .'
/bin/bash -c '$(which flake8) --select=E,W,F --ignore=E203,W503 --max-line-length=100 .'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the compatibility issue with black formatter:

./tests/functional/adapter/test_basic.py:99:13: W503 line break before binary operator
./tests/functional/adapter/test_basic.py:100:13: W503 line break before binary operator
./tests/functional/adapter/test_basic.py:102:17: W503 line break before binary operator

/bin/bash -c '$(which mypy) --config-file mypy.ini --namespace-packages --explicit-package-bases dbt tests'
passenv = DBT_* PYTEST_ADDOPTS
deps =
Expand Down