11import pathlib
22
3+ from pytest_mock .plugin import MockerFixture
34from sqlmesh .core .config import Config
45from sqlmesh .core .context import Context
56from sqlmesh .core .dialect import parse
67from sqlmesh .core .audit import ModelAudit
78from sqlmesh .core .model import SqlModel , load_sql_based_model
89from tests .utils .test_filesystem import create_temp_file
10+ from unittest .mock import call
911
1012
11- def test_format_files (tmp_path : pathlib .Path ):
13+ def test_format_files (tmp_path : pathlib .Path , mocker : MockerFixture ):
1214 models_dir = pathlib .Path ("models" )
1315 audits_dir = pathlib .Path ("audits" )
1416
@@ -35,6 +37,7 @@ def test_format_files(tmp_path: pathlib.Path):
3537
3638 config = Config ()
3739 context = Context (paths = tmp_path , config = config )
40+ context .console = mocker .Mock ()
3841 context .load ()
3942
4043 assert isinstance (context .get_model ("this.model" ), SqlModel )
@@ -54,6 +57,13 @@ def test_format_files(tmp_path: pathlib.Path):
5457 )
5558
5659 assert not context .format (check = True )
60+ assert context .console .log_status_update .mock_calls == [ # type: ignore
61+ call (f"Would reformat { tmp_path } /models/model_3.sql" ),
62+ call (f"Would reformat { tmp_path } /models/model_2.sql" ),
63+ call (f"Would reformat { tmp_path } /models/model_1.sql" ),
64+ call (f"Would reformat { tmp_path } /audits/audit_1.sql" ),
65+ call ("\n 4 file(s) would be reformatted." ),
66+ ]
5767
5868 # Transpile project to BigQuery
5969 context .format (transpile = "bigquery" )
0 commit comments