Skip to content

Commit

Permalink
WIP: Tests for get_powers_of_two macro
Browse files Browse the repository at this point in the history
Running into an issue where get_powersof_two is complaining that it's
getting a string for the `uppoer_bound` variable, and I don't know why.

Error:
```
E           dbt.exceptions.CaughtMacroErrorWithNodeError: Compilation Error in model test_get_powers_of_two (models/test_get_powers_of_two.sql)
E             '<=' not supported between instances of 'str' and 'int'
E
E             > in macro get_powers_of_two (macros/utils/generate_series.sql)
E             > called by model test_get_powers_of_two (models/test_get_powers_of_two.sql)
```
  • Loading branch information
QMalcolm committed Sep 11, 2023
1 parent 661d006 commit 356e547
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/adapter/dbt/tests/adapter/utils/fixture_get_powers_of_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# dateadd

seeds__data_get_powers_of_two_csv = """upper_bound,result
1,1
4,2
27,5
256,8
3125,12
46656,16
823543,20
16777216,24
387420489,29
"""


models__test_get_powers_of_two_sql = """
with data as (
select
cast({{ 'upper_bound' }} as {{ type_int() }}) as upper_bound,
cast({{ 'result' }} as {{ type_int() }}) as result
from {{ ref('data_get_powers_of_two') }}
)
select
{{get_powers_of_two('upper_bound')}} as actual,
result as expected
from data
"""

models__test_get_powers_of_two_yml = """
version: 2
models:
- name: test_powers_of_two
tests:
- assert_equal:
actual: actual
expected: expected
"""
26 changes: 26 additions & 0 deletions tests/adapter/dbt/tests/adapter/utils/test_get_powers_of_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
from dbt.tests.adapter.utils.base_utils import BaseUtils
from dbt.tests.adapter.utils.fixture_get_powers_of_two import (
seeds__data_get_powers_of_two_csv,
models__test_get_powers_of_two_sql,
models__test_get_powers_of_two_yml,
)


class BaseGetPowersOfTwo(BaseUtils):
@pytest.fixture(scope="class")
def seeds(self):
return {"data_get_powers_of_two.csv": seeds__data_get_powers_of_two_csv}

@pytest.fixture(scope="class")
def models(self):
return {
"test_get_powers_of_two.yml": models__test_get_powers_of_two_yml,
"test_get_powers_of_two.sql": self.interpolate_macro_namespace(
models__test_get_powers_of_two_sql, "get_powers_of_two"
),
}


class TestGetPowersOfTwo(BaseGetPowersOfTwo):
pass

0 comments on commit 356e547

Please sign in to comment.