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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
4eff3237f2bf9d3d206c9234353fb07e70ac6013
# Updated README.md and blackified the code.
29bab50f0e7d9e09b9110500f6e41e1255d3f3f6
# Replaced black with ruff format.
3d77e975c41bb6be2a13afd0df8cbb596d84fe9f
2 changes: 1 addition & 1 deletion .github/scripts/verify_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main(argv: list[str]) -> int:
pkg_version = read_package_version()
if tag_version != pkg_version:
print(
f"Git tag {tag_version!r} does not match " f"package version {pkg_version!r}",
f"Git tag {tag_version!r} does not match package version {pkg_version!r}",
file=sys.stderr,
)
return 1
Expand Down
14 changes: 3 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,12 @@ repos:
alias: ruff-check-manual
stages:
- manual
- repo: 'https://github.com/psf/black'
rev: 26.5.1
hooks:
- id: black
args:
- '--line-length=99'
- '--target-version=py311'
- id: black
alias: black-check
- id: ruff-format
- id: ruff-format
alias: ruff-format-check
stages:
- manual
args:
- '--line-length=99'
- '--target-version=py311'
- '--check'
- '--diff'
- repo: 'https://github.com/pre-commit/mirrors-mypy'
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ ruff: ## Runs ruff against staged changes to enforce style guide.
@\
pre-commit run --hook-stage manual ruff-check-manual | grep -v "INFO"

.PHONY: black
black: ## Runs black against staged changes to enforce style guide.
.PHONY: format
format: ## Runs ruff format against staged changes to enforce style guide.
@\
pre-commit run --hook-stage manual black-check -v | grep -v "INFO"
pre-commit run --hook-stage manual ruff-format-check -v | grep -v "INFO"

.PHONY: lint
lint: ## Runs ruff and mypy code checks against staged changes.
Expand All @@ -46,7 +46,7 @@ functional: ## Runs functional tests.
test: ## Runs unit tests and code checks against staged changes.
@\
uv run pytest -n auto -ra -v tests/unit; \
pre-commit run black-check --hook-stage manual | grep -v "INFO"; \
pre-commit run ruff-format-check --hook-stage manual | grep -v "INFO"; \
pre-commit run ruff-check-manual --hook-stage manual | grep -v "INFO"; \
pre-commit run mypy-check --hook-stage manual | grep -v "INFO"

Expand Down
6 changes: 2 additions & 4 deletions dbt/adapters/sqlserver/sqlserver_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,11 @@ def _render_event_time_filtered(self, event_time_filter: EventTimeFilter) -> str
)
elif event_time_filter.start:
filter = (
f"{event_time_filter.field_name} >="
f" cast('{event_time_filter.start}' as datetime2)"
f"{event_time_filter.field_name} >= cast('{event_time_filter.start}' as datetime2)"
)
elif event_time_filter.end:
filter = (
f"{event_time_filter.field_name} <"
f" cast('{event_time_filter.end}' as datetime2)"
f"{event_time_filter.field_name} < cast('{event_time_filter.end}' as datetime2)"
)

return filter
1 change: 0 additions & 1 deletion tests/functional/adapter/dbt/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class TestSimpleMaterializations(BaseSimpleMaterializations):

def test_existing_view_materialization(self, project, models):
"""Test that materializing an existing view works correctly."""
# Create a temporary model file directly in the project
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/adapter/dbt/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class TestCachingLowercaseModel(BaseCachingLowercaseModel):
pass


@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
Fails because of case sensitivity.
MODEL is coereced to model which fails the test as it sees conflicting naming
""")
"""
)
class TestCachingUppercaseModel(BaseCachingUppercaseModel):
pass

Expand Down
6 changes: 3 additions & 3 deletions tests/functional/adapter/dbt/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class TestTypeStringSQLServer(BaseTypeString):
def assert_columns_equal(self, project, expected_cols, actual_cols):
# ignore the size of the varchar since we do
# an optimization to not use varchar(max) all the time
assert (
expected_cols[:-1] == actual_cols[:-1]
), f"Type difference detected: {expected_cols} vs. {actual_cols}"
assert expected_cols[:-1] == actual_cols[:-1], (
f"Type difference detected: {expected_cols} vs. {actual_cols}"
)


class TestTypeTimestampSQLServer(BaseTypeTimestamp):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/adapter/dbt/test_dbt_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_limit(self, project, args, expected):
limit = results.args.get("limit")
if limit > 0:
assert (
f"offset 0 rows fetch first { limit } rows only"
f"offset 0 rows fetch first {limit} rows only"
in results.results[0].node.compiled_code
)

Expand Down
18 changes: 10 additions & 8 deletions tests/functional/adapter/dbt/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ def check_hooks(self, state, project, host, count=1):
# assert ctx["target_user"] == "root"
# assert ctx["target_pass"] == ""

assert (
ctx["run_started_at"] is not None and len(ctx["run_started_at"]) > 0
), "run_started_at was not set"
assert (
ctx["invocation_id"] is not None and len(ctx["invocation_id"]) > 0
), "invocation_id was not set"
assert ctx["run_started_at"] is not None and len(ctx["run_started_at"]) > 0, (
"run_started_at was not set"
)
assert ctx["invocation_id"] is not None and len(ctx["invocation_id"]) > 0, (
"invocation_id was not set"
)
assert ctx["thread_id"].startswith("Thread-")


Expand Down Expand Up @@ -196,7 +196,8 @@ def project_config_update(self):
"models": {
"test": {
"hooked": {
"post-hook": ["""
"post-hook": [
"""
insert into {{this.schema}}.on_model_hook select
test_state,
'{{ target.dbname }}' as target_dbname,
Expand All @@ -210,7 +211,8 @@ def project_config_update(self):
'{{ run_started_at }}' as run_started_at,
'{{ invocation_id }}' as invocation_id,
'{{ thread_id }}' as thread_id
from {{ ref('post') }}""".strip()],
from {{ ref('post') }}""".strip()
],
}
},
}
Expand Down
36 changes: 24 additions & 12 deletions tests/functional/adapter/dbt/test_simple_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,25 @@ def test_simple_seed_with_disabled(self, clear_test_schema, project):
check_table_does_not_exist(project.adapter, "seed_disabled")
check_table_does_exist(project.adapter, "seed_tricky")

@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
Running all the tests in the same schema causes the tests to fail
as they all share the same schema across the tests
""")
"""
)
def test_simple_seed_selection(self, clear_test_schema, project):
results = run_dbt(["seed", "--select", "seed_enabled"])
assert len(results) == 1
check_table_does_exist(project.adapter, "seed_enabled")
check_table_does_not_exist(project.adapter, "seed_disabled")
check_table_does_not_exist(project.adapter, "seed_tricky")

@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
Running all the tests in the same schema causes the tests to fail
as they all share the same schema across the tests
""")
"""
)
def test_simple_seed_exclude(self, clear_test_schema, project):
results = run_dbt(["seed", "--exclude", "seed_enabled"])
assert len(results) == 1
Expand All @@ -204,10 +208,12 @@ def clear_test_schema(self, project):
project.run_sql(f"drop view if exists {project.test_schema}.seed_tricky")
project.run_sql(f"drop schema if exists {project.test_schema}")

@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
Running all the tests in the same schema causes the tests to fail
as they all share the same schema across the tests
""")
"""
)
def test_simple_seed_with_disabled(self, clear_test_schema, project):
results = run_dbt(["seed"])
assert len(results) == 2
Expand All @@ -222,10 +228,12 @@ def test_simple_seed_selection(self, clear_test_schema, project):
check_table_does_not_exist(project.adapter, "seed_disabled")
check_table_does_not_exist(project.adapter, "seed_tricky")

@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
Running all the tests in the same schema causes the tests to fail
as they all share the same schema across the tests
""")
"""
)
def test_simple_seed_exclude(self, clear_test_schema, project):
results = run_dbt(["seed", "--exclude", "seed_enabled"])
assert len(results) == 1
Expand All @@ -252,21 +260,25 @@ def clear_test_schema(self, project):
project.run_sql(f"drop view if exists {project.test_schema}.seed_tricky")
project.run_sql(f"drop schema if exists {project.test_schema}")

@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
Running all the tests in the same schema causes the tests to fail
as they all share the same schema across the tests
""")
"""
)
def test_simple_seed_with_disabled(self, clear_test_schema, project):
results = run_dbt(["seed"])
assert len(results) == 2
check_table_does_exist(project.adapter, "seed_enabled")
check_table_does_not_exist(project.adapter, "seed_disabled")
check_table_does_exist(project.adapter, "seed_tricky")

@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
Running all the tests in the same schema causes the tests to fail
as they all share the same schema across the tests
""")
"""
)
def test_simple_seed_selection(self, clear_test_schema, project):
results = run_dbt(["seed", "--select", "seed_enabled"])
assert len(results) == 1
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/adapter/dbt/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,12 @@ class TestStringLiteral(BaseStringLiteral):
pass


@pytest.mark.skip(reason="""
@pytest.mark.skip(
reason="""
comment here about why this is skipped.
https://github.com/dbt-labs/dbt-adapters/blob/f1987d4313cc94bac9906963dff1337ee0bffbc6/dbt/include/global_project/macros/adapters/timestamps.sql#L39
""")
"""
)
class TestCurrentTimestamps(BaseCurrentTimestamps):
pass

Expand Down
12 changes: 9 additions & 3 deletions tests/functional/adapter/mssql/test_index_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
)
"""

index_count = base_validation + """
index_count = (
base_validation
+ """
select
index_type + case when [unique] = 'Unique' then ' unique' else '' end as index_type,
count(*) index_count
Expand All @@ -65,8 +67,11 @@
schema_name='{schema_name}'
group by index_type + case when [unique] = 'Unique' then ' unique' else '' end
"""
)

indexes_def = base_validation + """
indexes_def = (
base_validation
+ """
SELECT
index_name,
[columns],
Expand All @@ -84,6 +89,7 @@
table_view='{schema_name}.{table_name}'

"""
)

# Altered from: https://github.com/dbt-labs/dbt-postgres

Expand Down Expand Up @@ -898,7 +904,7 @@ def models(self):
def test_clustered_collision_fails_with_clear_error(self, project, unique_schema):
run_dbt(["run", "--models", "collision"])
project.run_sql(
f"CREATE CLUSTERED INDEX ix_dba_clustered " f"ON {unique_schema}.collision (column_a)"
f"CREATE CLUSTERED INDEX ix_dba_clustered ON {unique_schema}.collision (column_a)"
)

_, output = run_dbt_and_capture(
Expand Down
18 changes: 10 additions & 8 deletions tests/functional/adapter/mssql/test_query_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ class TestApplyLabelBackwardCompat:

@pytest.fixture(scope="class")
def macros(self):
return {"verify_apply_label.sql": """
return {
"verify_apply_label.sql": """
{% macro verify_apply_label() %}
{%- set result = apply_label() -%}
{{ log("apply_label returned: " ~ result, info=True) }}
Expand All @@ -443,7 +444,8 @@ def macros(self):
{{ exceptions.raise_compiler_error("apply_label() must not emit query_options hints") }}
{%- endif -%}
{% endmacro %}
"""}
"""
}

def test_apply_label_callable_and_label_only(self, project):
# run-operation will fail (non-zero exit) if apply_label is undefined
Expand Down Expand Up @@ -904,9 +906,9 @@ def test_options_render_on_both_dml_statements(self, project):
logs,
re.IGNORECASE,
)
assert (
main_match is not None
), "query_options missing from the 'main' SELECT INTO statement of the DML refresh"
assert main_match is not None, (
"query_options missing from the 'main' SELECT INTO statement of the DML refresh"
)

# 'dml_refresh_swap' — INSERT ... SELECT ... FROM <scratch>, must carry
# the hint too. The INSERT...SELECT spans newlines but has no interior
Expand All @@ -916,9 +918,9 @@ def test_options_render_on_both_dml_statements(self, project):
logs,
re.IGNORECASE,
)
assert (
swap_match is not None
), "query_options missing from the 'dml_refresh_swap' INSERT statement of the DML refresh"
assert swap_match is not None, (
"query_options missing from the 'dml_refresh_swap' INSERT statement of the DML refresh"
)


def write_model(project, filename, contents):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ def project_config_update(self):

@pytest.fixture(scope="class")
def macros(self):
return {"generate_schema_name.sql": """
return {
"generate_schema_name.sql": """
{% macro generate_schema_name(custom_schema_name, node) -%}
{%- if custom_schema_name -%}
{{ custom_schema_name | trim }}
{%- else -%}
{{ target.schema }}
{%- endif -%}
{%- endmacro %}
"""}
"""
}

@pytest.fixture(autouse=True, scope="class")
def cleanup_schema(self, project):
Expand Down