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

Create separate base classes for shared tests #93

Merged
merged 5 commits into from
Feb 21, 2024
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240216-135420.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Make all adapter zone tests importable by removing "Test" prefix
time: 2024-02-16T13:54:20.411864-05:00
custom:
Author: mikealfare
Issue: "93"
6 changes: 5 additions & 1 deletion dbt/tests/adapter/caching/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_cache(self, project):
self.run_and_inspect_cache(project, run_args)


class TestNoPopulateCache(BaseCachingTest):
class BaseNoPopulateCache(BaseCachingTest):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -116,3 +116,7 @@ class TestCachingUppercaseModel(BaseCachingUppercaseModel):

class TestCachingSelectedSchemaOnly(BaseCachingSelectedSchemaOnly):
pass


class TestNoPopulateCache(BaseNoPopulateCache):
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
pass
6 changes: 4 additions & 2 deletions dbt/tests/adapter/column_types/test_column_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ def run_and_test(self):
results = run_dbt(["test"])
assert len(results) == 1


class TestPostgresColumnTypes(BaseColumnTypes):
@pytest.fixture(scope="class")
def models(self):
return {"model.sql": fixtures.model_sql, "schema.yml": fixtures.schema_yml}

def test_run_and_test(self, project):
self.run_and_test()


class TestPostgresColumnTypes(BaseColumnTypes):
pass
6 changes: 4 additions & 2 deletions dbt/tests/adapter/concurrency/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ def models(self):
"skip.sql": models__skip_sql,
}


class TestConcurenncy(BaseConcurrency):
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
def test_concurrency(self, project):
run_dbt(["seed", "--select", "seed"])
results = run_dbt(["run"], expect_pass=False)
Expand All @@ -329,3 +327,7 @@ def test_concurrency(self, project):
check_table_does_not_exist(project.adapter, "skip")

assert "PASS=5 WARN=0 ERROR=1 SKIP=1 TOTAL=7" in output


class TestConcurenncy(BaseConcurrency):
pass
6 changes: 5 additions & 1 deletion dbt/tests/adapter/constraints/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class TestConstraintQuotedColumn(BaseConstraintQuotedColumn):
pass


class TestIncrementalForeignKeyConstraint:
class BaseIncrementalForeignKeyConstraint:
@pytest.fixture(scope="class")
def macros(self):
return {
Expand All @@ -534,3 +534,7 @@ def test_incremental_foreign_key_constraint(self, project):
run_dbt(["run", "--select", "raw_numbers"])
run_dbt(["run", "--select", "stg_numbers"])
run_dbt(["run", "--select", "stg_numbers"])


class TestIncrementalForeignKeyConstraint(BaseIncrementalForeignKeyConstraint):
pass
6 changes: 5 additions & 1 deletion dbt/tests/adapter/dbt_clone/test_dbt_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def clean_up(self, project):
pass


class TestCloneSameTargetAndState(BaseClone):
class BaseCloneSameTargetAndState(BaseClone):
def test_clone_same_target_and_state(self, project, unique_schema, other_schema):
project.create_test_schema(other_schema)
self.run_and_save_state(project.project_root)
Expand All @@ -220,3 +220,7 @@ def test_clone_same_target_and_state(self, project, unique_schema, other_schema)

results, output = run_dbt_and_capture(clone_args, expect_pass=False)
assert "Warning: The state and target directories are the same: 'target'" in output


class TestCloneSameTargetAndState(BaseCloneSameTargetAndState):
pass
10 changes: 7 additions & 3 deletions dbt/tests/adapter/dbt_debug/test_dbt_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def project_config_update(self):
return {"config-version": 2, "profile": '{{ "te" ~ "st" }}'}


class TestDebugPostgres(BaseDebug):
class BaseDebugPostgres(BaseDebug):
def test_ok(self, project):
run_dbt(["debug"])
assert "ERROR" not in self.capsys.readouterr().out
Expand Down Expand Up @@ -85,11 +85,11 @@ def test_empty_target(self, project):
self.assertGotValue(re.compile(r"\s+output 'none_target'"), "misconfigured")


class TestDebugProfileVariablePostgres(BaseDebugProfileVariable):
class TestDebugPostgres(BaseDebugPostgres):
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
pass


class TestDebugInvalidProjectPostgres(BaseDebug):
class BaseDebugInvalidProjectPostgres(BaseDebug):
def test_empty_project(self, project):
with open("dbt_project.yml", "w") as f: # noqa: F841
pass
Expand Down Expand Up @@ -128,3 +128,7 @@ def test_profile_not_found(self, project):
)
assert "Profile loading failed for the following reason" in out
assert "Could not find profile named 'NONE'" in out


class TestDebugInvalidProjectPostgres(BaseDebugInvalidProjectPostgres):
pass
18 changes: 14 additions & 4 deletions dbt/tests/adapter/ephemeral/test_ephemeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ def models(self):
},
}


class TestEphemeralMulti(BaseEphemeralMulti):
def test_ephemeral_multi(self, project):
run_dbt(["seed"])
results = run_dbt(["run"])
Expand Down Expand Up @@ -281,7 +279,11 @@ def test_ephemeral_multi(self, project):
assert sql_file == expected_sql


class TestEphemeralNested(BaseEphemeral):
class TestEphemeralMulti(BaseEphemeralMulti):
pass


class BaseEphemeralNested(BaseEphemeral):
@pytest.fixture(scope="class")
def models(self):
return {
Expand Down Expand Up @@ -314,7 +316,11 @@ def test_ephemeral_nested(self, project):
assert sql_file == expected_sql


class TestEphemeralErrorHandling(BaseEphemeral):
class TestEphemeralNested(BaseEphemeralNested):
pass


class BaseEphemeralErrorHandling(BaseEphemeral):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -330,3 +336,7 @@ def test_ephemeral_error_handling(self, project):
assert len(results) == 1
assert results[0].status == "skipped"
assert "Compilation Error" in results[0].message


class TestEphemeralErrorHandling(BaseEphemeralErrorHandling):
pass
17 changes: 0 additions & 17 deletions dbt/tests/adapter/hooks/data/seed_model.sql

This file was deleted.

17 changes: 0 additions & 17 deletions dbt/tests/adapter/hooks/data/seed_run.sql

This file was deleted.

40 changes: 40 additions & 0 deletions dbt/tests/adapter/hooks/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,43 @@
4,5,6
7,8,9
"""


tables__on_model_hook = """
drop table if exists {schema}.on_model_hook;

create table {schema}.on_model_hook (
test_state TEXT, -- start|end
target_dbname TEXT,
target_host TEXT,
target_name TEXT,
target_schema TEXT,
target_type TEXT,
target_user TEXT,
target_pass TEXT,
target_threads INTEGER,
run_started_at TEXT,
invocation_id TEXT,
thread_id TEXT
);
"""


tables__on_run_hook = """
drop table if exists {schema}.on_run_hook;

create table {schema}.on_run_hook (
test_state TEXT, -- start|end
target_dbname TEXT,
target_host TEXT,
target_name TEXT,
target_schema TEXT,
target_type TEXT,
target_user TEXT,
target_pass TEXT,
target_threads INTEGER,
run_started_at TEXT,
invocation_id TEXT,
thread_id TEXT
);
"""
Loading
Loading