@@ -9377,9 +9377,9 @@ def test_model_blueprinting(tmp_path: Path) -> None:
93779377 model_defaults = ModelDefaultsConfig (dialect = "duckdb" ),
93789378 )
93799379
9380- blueprint_sql = tmp_path / "macros" / "identity_macro.py"
9381- blueprint_sql .parent .mkdir (parents = True , exist_ok = True )
9382- blueprint_sql .write_text (
9380+ identity_macro = tmp_path / "macros" / "identity_macro.py"
9381+ identity_macro .parent .mkdir (parents = True , exist_ok = True )
9382+ identity_macro .write_text (
93839383 """from sqlmesh import macro
93849384
93859385@macro()
@@ -11623,3 +11623,40 @@ def test_use_original_sql():
1162311623 assert model .query_ .sql == "SELECT 1 AS one, 2 AS two"
1162411624 assert model .pre_statements_ [0 ].sql == "CREATE TABLE pre (a INT)"
1162511625 assert model .post_statements_ [0 ].sql == "CREATE TABLE post (b INT)"
11626+
11627+
11628+ def test_case_sensitive_macro_locals (tmp_path : Path ) -> None :
11629+ init_example_project (tmp_path , engine_type = "duckdb" , template = ProjectTemplate .EMPTY )
11630+
11631+ db_path = str (tmp_path / "db.db" )
11632+ db_connection = DuckDBConnectionConfig (database = db_path )
11633+
11634+ config = Config (
11635+ gateways = {"gw" : GatewayConfig (connection = db_connection )},
11636+ model_defaults = ModelDefaultsConfig (dialect = "duckdb" ),
11637+ )
11638+
11639+ macro_file = tmp_path / "macros" / "some_macro_with_globals.py"
11640+ macro_file .parent .mkdir (parents = True , exist_ok = True )
11641+ macro_file .write_text (
11642+ """from sqlmesh import macro
11643+
11644+ x = 1
11645+ X = 2
11646+
11647+ @macro()
11648+ def my_macro(evaluator):
11649+ assert evaluator.locals.get("x") == 1
11650+ assert evaluator.locals.get("X") == 2
11651+
11652+ return x + X
11653+ """
11654+ )
11655+ test_model = tmp_path / "models" / "test_model.sql"
11656+ test_model .parent .mkdir (parents = True , exist_ok = True )
11657+ test_model .write_text ("MODEL (name test_model, kind FULL); SELECT @my_macro() AS c" )
11658+
11659+ context = Context (paths = tmp_path , config = config )
11660+ model = context .get_model ("test_model" , raise_if_missing = True )
11661+
11662+ assert model .render_query_or_raise ().sql () == 'SELECT 3 AS "c"'
0 commit comments