@@ -1205,7 +1205,7 @@ def test_unpause_snapshots_remove_intervals(
12051205 ]
12061206
12071207
1208- def test_get_version (state_sync : EngineAdapterStateSync ) -> None :
1208+ def test_version_schema (state_sync : EngineAdapterStateSync ) -> None :
12091209 from sqlmesh import __version__ as SQLMESH_VERSION
12101210
12111211 # fresh install should not raise
@@ -1250,29 +1250,65 @@ def test_get_version(state_sync: EngineAdapterStateSync) -> None:
12501250 state_sync .get_versions ()
12511251 state_sync .get_versions (validate = False )
12521252
1253+
1254+ def test_version_sqlmesh (state_sync : EngineAdapterStateSync ) -> None :
1255+ from sqlmesh import __version__ as SQLMESH_VERSION
1256+ from sqlmesh import __version_tuple__ as SQLMESH_VERSION_TUPLE
1257+
1258+ # patch version sqlmesh doesn't matter
1259+ major , minor , patch , * _ = SQLMESH_VERSION_TUPLE
1260+ sqlmesh_version_patch_bump = f"{ major } .{ minor } .{ int (patch ) + 1 } "
1261+ state_sync ._update_versions (sqlmesh_version = sqlmesh_version_patch_bump )
1262+ state_sync .get_versions (validate = False )
1263+
1264+ # sqlmesh version is behind
1265+ sqlmesh_version_minor_bump = f"{ major } .{ int (minor ) + 1 } .{ patch } "
1266+ error = (
1267+ rf"SQLMesh \(local\) is using version '{ SQLMESH_VERSION } ' which is behind '{ sqlmesh_version_minor_bump } ' \(remote\). "
1268+ rf"""Please upgrade SQLMesh \('pip install --upgrade "sqlmesh=={ sqlmesh_version_minor_bump } "' command\)."""
1269+ )
1270+ state_sync ._update_versions (sqlmesh_version = sqlmesh_version_minor_bump )
1271+ with pytest .raises (SQLMeshError , match = error ):
1272+ state_sync .get_versions ()
1273+ state_sync .get_versions (validate = False )
1274+
1275+ # sqlmesh version is ahead
1276+ sqlmesh_version_minor_decrease = f"{ major } .{ int (minor ) - 1 } .{ patch } "
1277+ error = rf"SQLMesh \(local\) is using version '{ SQLMESH_VERSION } ' which is ahead of '{ sqlmesh_version_minor_decrease } '"
1278+ state_sync ._update_versions (sqlmesh_version = sqlmesh_version_minor_decrease )
1279+ with pytest .raises (SQLMeshError , match = error ):
1280+ state_sync .get_versions ()
1281+ state_sync .get_versions (validate = False )
1282+
1283+
1284+ def test_version_sqlglot (state_sync : EngineAdapterStateSync ) -> None :
12531285 # patch version sqlglot doesn't matter
12541286 major , minor , patch , * _ = SQLGLOT_VERSION .split ("." )
12551287 sqlglot_version = f"{ major } .{ minor } .{ int (patch ) + 1 } "
12561288 state_sync ._update_versions (sqlglot_version = sqlglot_version )
12571289 state_sync .get_versions (validate = False )
12581290
1259- # sqlglot version is behind, always raise
1291+ # sqlglot version is behind
12601292 sqlglot_version = f"{ major } .{ int (minor ) + 1 } .{ patch } "
12611293 error = (
12621294 rf"SQLGlot \(local\) is using version '{ SQLGLOT_VERSION } ' which is behind '{ sqlglot_version } ' \(remote\). "
12631295 rf"""Please upgrade SQLGlot \('pip install --upgrade "sqlglot=={ sqlglot_version } "' command\)."""
12641296 )
12651297 state_sync ._update_versions (sqlglot_version = sqlglot_version )
1298+ with pytest .raises (SQLMeshError , match = error ):
1299+ state_sync .get_versions ()
12661300 state_sync .get_versions (validate = False )
12671301
1268- # sqlglot version is ahead, only raise with validate is true
1302+ # sqlglot version is ahead
12691303 sqlglot_version = f"{ major } .{ int (minor ) - 1 } .{ patch } "
12701304 error = rf"SQLGlot \(local\) is using version '{ SQLGLOT_VERSION } ' which is ahead of '{ sqlglot_version } '"
12711305 state_sync ._update_versions (sqlglot_version = sqlglot_version )
12721306 with pytest .raises (SQLMeshError , match = error ):
12731307 state_sync .get_versions ()
12741308 state_sync .get_versions (validate = False )
12751309
1310+
1311+ def test_empty_versions () -> None :
12761312 for empty_versions in (
12771313 Versions (),
12781314 Versions (schema_version = None , sqlglot_version = None , sqlmesh_version = None ),
0 commit comments