Skip to content

Commit

Permalink
Mp/reformat the repo to precommit hooks (#562)
Browse files Browse the repository at this point in the history
* Clean up code and get mypy passing

* Remove references to pytest

---------

Co-authored-by: Mila Page <[email protected]>
  • Loading branch information
VersusFacit and VersusFacit authored Apr 12, 2023
1 parent f4f020c commit 08728d8
Show file tree
Hide file tree
Showing 41 changed files with 948 additions and 845 deletions.
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# For more on configuring pre-commit hooks (see https://pre-commit.com/)

# TODO: remove global exclusion of tests when testing overhaul is complete
exclude: '^tests/.*'

# Force all unspecified python hooks to run python 3.8
default_language_version:
python: python3
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import agate

from dbt.adapters.base.impl import AdapterConfig, ConstraintSupport
from dbt.adapters.base.impl import AdapterConfig, ConstraintSupport # type: ignore
from dbt.adapters.base.meta import available
from dbt.adapters.sql import SQLAdapter # type: ignore
from dbt.adapters.sql.impl import (
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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


# The profile dictionary, used to write out profiles.yml
@pytest.fixture(scope="class")
def dbt_profile_target():
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/adapter/column_types/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_MODEL_SQL ="""
_MODEL_SQL = """
select
1::smallint as smallint_col,
2::int as int_col,
Expand Down Expand Up @@ -43,4 +43,4 @@
number_col: ['numeric', 'number', 'not string', 'not float', 'not integer']
text_col: ['string', 'not number']
varchar_col: ['string', 'not number']
"""
"""
14 changes: 4 additions & 10 deletions tests/functional/adapter/column_types/test_column_types.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import pytest
from dbt.tests.adapter.column_types.test_column_types import BaseColumnTypes
from tests.functional.adapter.column_types.fixtures import (
_MODEL_SQL,
_SCHEMA_YML
)
from tests.functional.adapter.column_types.fixtures import _MODEL_SQL, _SCHEMA_YML

class TestSnowflakeColumnTypes(BaseColumnTypes):

class TestSnowflakeColumnTypes(BaseColumnTypes):
@pytest.fixture(scope="class")
def models(self):
return {
"model.sql": _MODEL_SQL,
"schema.yml": _SCHEMA_YML
}
return {"model.sql": _MODEL_SQL, "schema.yml": _SCHEMA_YML}

def test_run_and_test(self, project):
self.run_and_test()
self.run_and_test()
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import pytest
import os
from dbt.tests.util import (
check_relations_equal,
check_table_does_exist,
run_dbt
)
from tests.functional.adapter.custom_schema_tests.seeds import (
seed_agg_csv,
seed_csv
)
from dbt.tests.util import check_relations_equal, check_table_does_exist, run_dbt
from tests.functional.adapter.custom_schema_tests.seeds import seed_agg_csv, seed_csv

_VIEW_1_SQL = """
select * from {{ ref('seed') }}
Expand Down Expand Up @@ -65,6 +58,7 @@

ALT_DATABASE = os.getenv("SNOWFLAKE_TEST_ALT_DATABASE")


class TestOverrideDatabase:
@pytest.fixture(scope="class")
def macros(self):
Expand All @@ -74,10 +68,7 @@ def macros(self):

@pytest.fixture(scope="class")
def seeds(self):
return {
"seed.csv" : seed_csv,
"agg.csv": seed_agg_csv
}
return {"seed.csv": seed_csv, "agg.csv": seed_agg_csv}

@pytest.fixture(scope="class")
def models(self):
Expand Down Expand Up @@ -110,8 +101,14 @@ def test_snowflake_override_generate_db_name(self, project):
check_table_does_exist(project.adapter, f"{alt_db_with_schema}.{view_3}")

# not overridden
check_relations_equal(project.adapter, [f"{db_with_schema}.{seed_table}", f"{db_with_schema}.{view_1}"])
check_relations_equal(
project.adapter, [f"{db_with_schema}.{seed_table}", f"{db_with_schema}.{view_1}"]
)

# overridden
check_relations_equal(project.adapter, [f"{db_with_schema}.{seed_table}", f"{alt_db_with_schema}.{view_2}"])
check_relations_equal(project.adapter, [f"{db_with_schema}.{agg_table}", f"{alt_db_with_schema}.{view_3}"])
check_relations_equal(
project.adapter, [f"{db_with_schema}.{seed_table}", f"{alt_db_with_schema}.{view_2}"]
)
check_relations_equal(
project.adapter, [f"{db_with_schema}.{agg_table}", f"{alt_db_with_schema}.{view_3}"]
)
39 changes: 14 additions & 25 deletions tests/functional/adapter/custom_schema_tests/test_custom_schema.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import pytest
from dbt.tests.util import (
check_relations_equal,
run_dbt
)
from tests.functional.adapter.custom_schema_tests.seeds import (
seed_agg_csv,
seed_csv
)
from dbt.tests.util import check_relations_equal, run_dbt
from tests.functional.adapter.custom_schema_tests.seeds import seed_agg_csv, seed_csv

_VIEW_1_SQL = """
select * from {{ ref('seed') }}
Expand Down Expand Up @@ -54,26 +48,15 @@
class TestCustomProjectSchemaWithPrefix:
@pytest.fixture(scope="class")
def seeds(self):
return {
"seed.csv": seed_csv,
"agg.csv": seed_agg_csv
}
return {"seed.csv": seed_csv, "agg.csv": seed_agg_csv}

@pytest.fixture(scope="class")
def models(self):
return {
"view_1.sql": _VIEW_1_SQL,
"view_2.sql": _VIEW_2_SQL,
"view_3.sql": _VIEW_3_SQL
}
return {"view_1.sql": _VIEW_1_SQL, "view_2.sql": _VIEW_2_SQL, "view_3.sql": _VIEW_3_SQL}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"models": {
"schema": "dbt_test"
}
}
return {"models": {"schema": "dbt_test"}}

def test__snowflake__custom_schema_with_prefix(self, project):
seed_results = run_dbt(["seed"])
Expand All @@ -82,6 +65,12 @@ def test__snowflake__custom_schema_with_prefix(self, project):
assert len(results) == 3

db_with_schema = f"{project.database}.{project.test_schema}"
check_relations_equal(project.adapter, [f"{db_with_schema}.SEED", f"{db_with_schema}_DBT_TEST.VIEW_1"])
check_relations_equal(project.adapter, [f"{db_with_schema}.SEED", f"{db_with_schema}_CUSTOM.VIEW_2"])
check_relations_equal(project.adapter, [f"{db_with_schema}.AGG", f"{db_with_schema}_TEST.VIEW_3"])
check_relations_equal(
project.adapter, [f"{db_with_schema}.SEED", f"{db_with_schema}_DBT_TEST.VIEW_1"]
)
check_relations_equal(
project.adapter, [f"{db_with_schema}.SEED", f"{db_with_schema}_CUSTOM.VIEW_2"]
)
check_relations_equal(
project.adapter, [f"{db_with_schema}.AGG", f"{db_with_schema}_TEST.VIEW_3"]
)
51 changes: 26 additions & 25 deletions tests/functional/adapter/expected_stats.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
from dbt.tests.util import AnyString, AnyFloat


def snowflake_stats():
return {
'has_stats': {
'id': 'has_stats',
'label': 'Has Stats?',
'value': True,
'description': 'Indicates whether there are statistics for this table',
'include': False,
"has_stats": {
"id": "has_stats",
"label": "Has Stats?",
"value": True,
"description": "Indicates whether there are statistics for this table",
"include": False,
},
"bytes": {
"id": "bytes",
"label": "Approximate Size",
"value": AnyFloat(),
"description": "Approximate size of the table as reported by Snowflake",
"include": True,
},
'bytes': {
'id': 'bytes',
'label': 'Approximate Size',
'value': AnyFloat(),
'description': 'Approximate size of the table as reported by Snowflake',
'include': True,
"last_modified": {
"id": "last_modified",
"label": "Last Modified",
"value": AnyString(),
"description": "The timestamp for last update/change",
"include": True,
},
'last_modified': {
'id': 'last_modified',
'label': 'Last Modified',
'value': AnyString(),
'description': 'The timestamp for last update/change',
'include': True,
"row_count": {
"id": "row_count",
"label": "Row Count",
"value": 1.0,
"description": "An approximate count of rows in this table",
"include": True,
},
'row_count': {
'id': 'row_count',
'label': 'Row Count',
'value': 1.0,
'description': 'An approximate count of rows in this table',
'include': True,
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from dbt.tests.adapter.incremental.test_incremental_merge_exclude_columns import (
BaseMergeExcludeColumns,
)

from dbt.tests.adapter.incremental.test_incremental_merge_exclude_columns import BaseMergeExcludeColumns

class TestMergeExcludeColumns(BaseMergeExcludeColumns):
pass
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from dbt.tests.adapter.incremental.test_incremental_on_schema_change import BaseIncrementalOnSchemaChange
from dbt.tests.adapter.incremental.test_incremental_on_schema_change import (
BaseIncrementalOnSchemaChange,
)


class TestIncrementalOnSchemaChange(BaseIncrementalOnSchemaChange):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@ class TestIncrementalPredicatesDeleteInsertSnowflake(BaseIncrementalPredicates):
class TestPredicatesDeleteInsertSnowflake(BaseIncrementalPredicates):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"models": {
"+predicates": [
"id != 2"
],
"+incremental_strategy": "delete+insert"
}
}
return {"models": {"+predicates": ["id != 2"], "+incremental_strategy": "delete+insert"}}


class TestIncrementalPredicatesMergeSnowflake(BaseIncrementalPredicates):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"models": {
"+incremental_predicates": [
"dbt_internal_dest.id != 2"
],
"+incremental_strategy": "merge"
"models": {
"+incremental_predicates": ["dbt_internal_dest.id != 2"],
"+incremental_strategy": "merge",
}
}

Expand All @@ -36,10 +27,8 @@ class TestPredicatesMergeSnowflake(BaseIncrementalPredicates):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"models": {
"+predicates": [
"dbt_internal_dest.id != 2"
],
"+incremental_strategy": "merge"
"models": {
"+predicates": ["dbt_internal_dest.id != 2"],
"+incremental_strategy": "merge",
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import pytest

from dbt.tests.util import run_dbt
from dbt.tests.adapter.basic.test_incremental import BaseIncremental, BaseIncrementalNotSchemaChange
from dbt.tests.adapter.basic.test_incremental import (
BaseIncremental,
BaseIncrementalNotSchemaChange,
)


class TestBaseIncrementalNotSchemaChange(BaseIncrementalNotSchemaChange):
pass


class TestIncrementalRunResultSnowflake(BaseIncremental):
"""Bonus test to verify that incremental models return the number of rows affected"""

def test_incremental(self, project):
# seed command
results = run_dbt(["seed"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ class TestUniqueKeySnowflake(BaseIncrementalUniqueKey):
class TestUniqueKeyDeleteInsertSnowflake(BaseIncrementalUniqueKey):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"models": { "+incremental_strategy": "delete+insert" }
}
return {"models": {"+incremental_strategy": "delete+insert"}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from dbt.tests.adapter.query_comment.test_query_comment import (
BaseQueryComments,
BaseMacroQueryComments,
Expand All @@ -12,17 +11,22 @@
class TestQueryCommentsSnowflake(BaseQueryComments):
pass


class TestMacroQueryCommentsSnowflake(BaseMacroQueryComments):
pass


class TestMacroArgsQueryCommentsSnowflake(BaseMacroArgsQueryComments):
pass


class TestMacroInvalidQueryCommentsSnowflake(BaseMacroInvalidQueryComments):
pass


class TestNullQueryCommentsSnowflake(BaseNullQueryComments):
pass


class TestEmptyQueryCommentsSnowflake(BaseEmptyQueryComments):
pass
pass
Loading

0 comments on commit 08728d8

Please sign in to comment.