Skip to content

Commit

Permalink
Reorganize basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
genzgd committed Oct 31, 2023
1 parent 8a16ce2 commit 7641261
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 164 deletions.
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/integration/adapter/basic/test_adapter_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod


class TestBaseAdapterMethod(BaseAdapterMethod):
pass


class TestBaseCaching(BaseAdapterMethod):
pass
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations


class TestBaseSimpleMaterializations(BaseSimpleMaterializations):
pass
97 changes: 97 additions & 0 deletions tests/integration/adapter/basic/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os

import pytest
from dbt.tests.util import (
run_dbt,
)

# CSV content with boolean column type.
seeds_boolean_csv = """
key,value
abc,true
def,false
hij,true
klm,false
""".lstrip()

# CSV content with empty fields.
seeds_empty_csv = """
key,val1,val2,str1
abc,1,1,some_str
abc,1,0,"another string"
def,1,0,
hij,1,1,Caps
hij,1,,"second string"
klm,1,0,"test"
klm,1,,"test4"
""".lstrip()

seeds_schema_yml = """
version: 2
seeds:
- name: empty
config:
column_types:
val2: Nullable(UInt32)
str1: Nullable(String)
"""

replicated_seeds_schema_yml = """
version: 2
seeds:
- name: empty
config:
engine: ReplicatedMergeTree('/clickhouse/tables/{uuid}/one_shard', '{server_index}' )
column_types:
val2: Nullable(UInt32)
str1: Nullable(String)
"""

base_seeds_schema_yml = """
version: 2
seeds:
- name: base
config:
engine: ReplicatedMergeTree('/clickhouse/tables/{uuid}/one_shard', '{server_index}' )
"""


class TestCSVSeed:
@pytest.fixture(scope="class")
def seeds(self):
return {
"schema.yml": seeds_schema_yml,
"boolean.csv": seeds_boolean_csv,
"empty.csv": seeds_empty_csv,
}

def test_seed(self, project):
# seed command
results = run_dbt(["seed"])
assert len(results) == 2
columns = project.run_sql("DESCRIBE TABLE empty", fetch='all')
assert columns[2][1] == 'Nullable(UInt32)'
assert columns[3][1] == 'Nullable(String)'


class TestReplicatedCSVSeed:
@pytest.fixture(scope="class")
def seeds(self):
return {
"schema.yml": replicated_seeds_schema_yml,
"empty.csv": seeds_empty_csv,
}

@pytest.mark.skipif(
os.environ.get('DBT_CH_TEST_CLUSTER', '').strip() == '', reason='Not on a cluster'
)
def test_seed(self, project):
# seed command
results = run_dbt(["seed"])
assert len(results) == 1
columns = project.run_sql("DESCRIBE TABLE empty", fetch='all')
assert columns[2][1] == 'Nullable(UInt32)'
assert columns[3][1] == 'Nullable(String)'
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_empty import BaseEmpty


class TestEmpty(BaseEmpty):
pass
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_ephemeral.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral


class TestEphemeral(BaseEphemeral):
pass
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_generic_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests


class TestGenericTests(BaseGenericTests):
pass
24 changes: 24 additions & 0 deletions tests/integration/adapter/basic/test_incremental.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from dbt.tests.adapter.basic.test_incremental import BaseIncremental, BaseIncrementalNotSchemaChange


class TestIncremental(BaseIncremental):
pass


incremental_not_schema_change_sql = """
{{ config(materialized="incremental", unique_key="user_id_current_time",on_schema_change="sync_all_columns") }}
select
toString(1) || '-' || toString(now64()) as user_id_current_time,
{% if is_incremental() %}
'thisis18characters' as platform
{% else %}
'okthisis20characters' as platform
{% endif %}
"""


class TestIncrementalNotSchemaChange(BaseIncrementalNotSchemaChange):
@pytest.fixture(scope="class")
def models(self):
return {"incremental_not_schema_change.sql": incremental_not_schema_change_sql}
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_singular_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests


class TestSingularTests(BaseSingularTests):
pass
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import BaseSingularTestsEphemeral


class TestSingularTests(BaseSingularTests):
pass


class TestSingularTestsEphemeral(BaseSingularTestsEphemeral):
pass
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_snapshot_check_cols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols


class TestSnapshotCheckCols(BaseSnapshotCheckCols):
pass
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_snapshot_timestamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp


class TestSnapshotTimestamp(BaseSnapshotTimestamp):
pass
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_table_materialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_table_materialization import BaseTableMaterialization


class TestTableMat(BaseTableMaterialization):
pass
5 changes: 5 additions & 0 deletions tests/integration/adapter/basic/test_validate_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.basic.test_validate_connection import BaseValidateConnection


class TestValidateConnection(BaseValidateConnection):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,11 @@

import pytest
from dbt.tests.adapter.basic.files import model_base, schema_base_yml, seeds_base_csv
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_empty import BaseEmpty
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
from dbt.tests.adapter.basic.test_incremental import BaseIncremental
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp
from dbt.tests.util import (
check_relation_types,
check_relations_equal,
check_result_nodes_by_name,
relation_from_name,
run_dbt,
)
from dbt.tests.util import run_dbt, check_relation_types, relation_from_name, check_result_nodes_by_name, \
check_relations_equal

# CSV content with boolean column type.
seeds_boolean_csv = """
key,value
abc,true
def,false
hij,true
klm,false
""".lstrip()

# CSV content with empty fields.
seeds_empty_csv = """
key,val1,val2,str1
abc,1,1,some_str
abc,1,0,"another string"
def,1,0,
hij,1,1,Caps
hij,1,,"second string"
klm,1,0,"test"
klm,1,,"test4"
""".lstrip()

seeds_schema_yml = """
version: 2
seeds:
- name: empty
config:
column_types:
val2: Nullable(UInt32)
str1: Nullable(String)
"""

replicated_seeds_schema_yml = """
version: 2
seeds:
- name: empty
config:
engine: ReplicatedMergeTree('/clickhouse/tables/{uuid}/one_shard', '{server_index}' )
column_types:
val2: Nullable(UInt32)
str1: Nullable(String)
"""

base_seeds_schema_yml = """
version: 2
seeds:
- name: base
config:
engine: ReplicatedMergeTree('/clickhouse/tables/{uuid}/one_shard', '{server_index}' )
"""


class TestBaseSimpleMaterializations(BaseSimpleMaterializations):
pass


class TestEmpty(BaseEmpty):
pass


class TestIncremental(BaseIncremental):
pass


class TestEphemeral(BaseEphemeral):
pass


class TestSnapshotTimestamp(BaseSnapshotTimestamp):
pass


class TestSnapshotCheckCols(BaseSnapshotCheckCols):
pass


class TestSingularTests(BaseSingularTests):
pass


class TestGenericTests(BaseGenericTests):
pass


class TestBaseAdapterMethod(BaseAdapterMethod):
pass
from tests.integration.adapter.basic.test_basic import base_seeds_schema_yml


class TestMergeTreeTableMaterialization(BaseSimpleMaterializations):
Expand Down Expand Up @@ -141,44 +41,6 @@ def test_base(self, project):
assert result[0] == 10


class TestCSVSeed:
@pytest.fixture(scope="class")
def seeds(self):
return {
"schema.yml": seeds_schema_yml,
"boolean.csv": seeds_boolean_csv,
"empty.csv": seeds_empty_csv,
}

def test_seed(self, project):
# seed command
results = run_dbt(["seed"])
assert len(results) == 2
columns = project.run_sql("DESCRIBE TABLE empty", fetch='all')
assert columns[2][1] == 'Nullable(UInt32)'
assert columns[3][1] == 'Nullable(String)'


class TestReplicatedCSVSeed:
@pytest.fixture(scope="class")
def seeds(self):
return {
"schema.yml": replicated_seeds_schema_yml,
"empty.csv": seeds_empty_csv,
}

@pytest.mark.skipif(
os.environ.get('DBT_CH_TEST_CLUSTER', '').strip() == '', reason='Not on a cluster'
)
def test_seed(self, project):
# seed command
results = run_dbt(["seed"])
assert len(results) == 1
columns = project.run_sql("DESCRIBE TABLE empty", fetch='all')
assert columns[2][1] == 'Nullable(UInt32)'
assert columns[3][1] == 'Nullable(String)'


class TestDistributedMaterializations(BaseSimpleMaterializations):
'''Test distributed materializations and check if data is properly distributed/replicated'''

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from dbt.tests.adapter.basic.files import model_incremental, schema_base_yml
from dbt.tests.adapter.basic.test_incremental import BaseIncremental, BaseIncrementalNotSchemaChange
from dbt.tests.adapter.basic.test_incremental import BaseIncremental
from dbt.tests.util import run_dbt

uniq_schema = """
Expand Down Expand Up @@ -148,19 +148,3 @@ def models(self):
}


incremental_not_schema_change_sql = """
{{ config(materialized="incremental", unique_key="user_id_current_time",on_schema_change="sync_all_columns") }}
select
toString(1) || '-' || toString(now64()) as user_id_current_time,
{% if is_incremental() %}
'thisis18characters' as platform
{% else %}
'okthisis20characters' as platform
{% endif %}
"""


class TestIncrementalNotSchemaChange(BaseIncrementalNotSchemaChange):
@pytest.fixture(scope="class")
def models(self):
return {"incremental_not_schema_change.sql": incremental_not_schema_change_sql}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dbt.tests.adapter.basic.test_incremental import BaseIncremental, BaseIncrementalNotSchemaChange
from dbt.tests.util import run_dbt

from tests.integration.adapter.incremental.test_incremental import uniq_schema
from tests.integration.adapter.incremental.test_base_incremental import uniq_schema

uniq_source_model = """
{{config(
Expand Down

0 comments on commit 7641261

Please sign in to comment.