|
21 | 21 | column_types_to_sqlmesh, |
22 | 22 | ) |
23 | 23 | from sqlmesh.dbt.context import DbtContext |
| 24 | +from sqlmesh.dbt.macros import dbt_utils_star |
24 | 25 | from sqlmesh.dbt.model import Materialization, ModelConfig |
25 | 26 | from sqlmesh.dbt.project import Project |
26 | 27 | from sqlmesh.dbt.seed import SeedConfig |
@@ -241,27 +242,30 @@ def test_this(assert_exp_eq, sushi_test_project: Project): |
241 | 242 | ) |
242 | 243 |
|
243 | 244 |
|
244 | | -def test_statement(sushi_test_project: Project): |
| 245 | +def test_statement(sushi_test_project: Project, runtime_renderer: t.Callable): |
245 | 246 | context = sushi_test_project.context |
246 | | - assert context.render( |
247 | | - "{% set test_var = 'SELECT 1' %}{% call statement('something', fetch_result=True) %} {{ test_var }} {% endcall %}{{ load_result('something').table }}" |
| 247 | + renderer = runtime_renderer(context) |
| 248 | + assert renderer( |
| 249 | + "{% set test_var = 'SELECT 1' %}{% call statement('something', fetch_result=True) %} {{ test_var }} {% endcall %}{{ load_result('something').table }}", |
248 | 250 | ) == str(agate.Table([[1]], column_names=["1"], column_types=[agate.Number()])) |
249 | 251 |
|
250 | 252 |
|
251 | | -def test_run_query(sushi_test_project: Project): |
| 253 | +def test_run_query(sushi_test_project: Project, runtime_renderer: t.Callable): |
252 | 254 | context = sushi_test_project.context |
253 | | - assert context.render("{{ run_query('SELECT 1 UNION ALL SELECT 2') }}") == str( |
| 255 | + renderer = runtime_renderer(context) |
| 256 | + assert renderer("{{ run_query('SELECT 1 UNION ALL SELECT 2') }}") == str( |
254 | 257 | agate.Table([[1], [2]], column_names=["1"], column_types=[agate.Number()]) |
255 | 258 | ) |
256 | 259 |
|
257 | 260 |
|
258 | | -def test_logging(capsys, sushi_test_project: Project): |
| 261 | +def test_logging(capsys, sushi_test_project: Project, runtime_renderer: t.Callable): |
259 | 262 | context = sushi_test_project.context |
| 263 | + renderer = runtime_renderer(context) |
260 | 264 |
|
261 | | - assert context.render('{{ log("foo") }}') == "" |
| 265 | + assert renderer('{{ log("foo") }}') == "" |
262 | 266 | assert "foo" in capsys.readouterr().out |
263 | 267 |
|
264 | | - assert context.render('{{ print("bar") }}') == "" |
| 268 | + assert renderer('{{ print("bar") }}') == "" |
265 | 269 | assert "bar" in capsys.readouterr().out |
266 | 270 |
|
267 | 271 |
|
@@ -394,3 +398,23 @@ def test_dbt_version(sushi_test_project: Project): |
394 | 398 | context = sushi_test_project.context |
395 | 399 |
|
396 | 400 | assert context.render("{{ dbt_version }}").startswith("1.") |
| 401 | + |
| 402 | + |
| 403 | +def test_dbt_utils_star_macro(sushi_test_project: Project): |
| 404 | + context = sushi_test_project.context |
| 405 | + context.jinja_macros.add_macros({"star": dbt_utils_star().info}, "dbt_utils") |
| 406 | + context._jinja_environment = None |
| 407 | + |
| 408 | + assert context.render("{{ dbt_utils.star(from='foo') }}") == "foo.*" |
| 409 | + assert ( |
| 410 | + context.render("{{ dbt_utils.star(from='foo', except=['bar']) }}") |
| 411 | + == """foo.* EXCEPT ("bar")""" |
| 412 | + ) |
| 413 | + assert ( |
| 414 | + context.render("{{ dbt_utils.star(from='foo', except=['bar', 'baz']) }}") |
| 415 | + == """foo.* EXCEPT ("bar", "baz")""" |
| 416 | + ) |
| 417 | + with pytest.raises(CompilationError): |
| 418 | + context.render("{{ dbt_utils.star(from='foo', prefix='pre') }}") |
| 419 | + with pytest.raises(CompilationError): |
| 420 | + context.render("{{ dbt_utils.star(from='foo', suffix='suf') }}") |
0 commit comments