Count rows with select() in the tests
`Session.query()` is the legacy API in SQLAlchemy 2.x.
This commit is contained in:
parent
455af6dfdb
commit
c1f04c65aa
1 changed files with 94 additions and 45 deletions
|
|
@ -4,6 +4,7 @@ import typing as t
|
|||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
import sqlalchemy as sa
|
||||
|
||||
from tests import config as test_config
|
||||
from velofy import db
|
||||
|
|
@ -173,7 +174,9 @@ class TestGenericForecastingModelProperties:
|
|||
"""`*Model.make_forecast()` caches the `Forecast` object."""
|
||||
model = model_cls(order_history=order_history)
|
||||
|
||||
assert db_session.query(db.Forecast).count() == 0
|
||||
assert (
|
||||
db_session.scalar(sa.select(sa.func.count()).select_from(db.Forecast)) == 0
|
||||
)
|
||||
|
||||
result1 = model.make_forecast(
|
||||
pixel=pixel,
|
||||
|
|
@ -181,7 +184,9 @@ class TestGenericForecastingModelProperties:
|
|||
train_horizon=test_config.LONG_TRAIN_HORIZON,
|
||||
)
|
||||
|
||||
n_cached_forecasts = db_session.query(db.Forecast).count()
|
||||
n_cached_forecasts = db_session.scalar(
|
||||
sa.select(sa.func.count()).select_from(db.Forecast),
|
||||
)
|
||||
assert n_cached_forecasts >= 1
|
||||
|
||||
result2 = model.make_forecast(
|
||||
|
|
@ -190,6 +195,8 @@ class TestGenericForecastingModelProperties:
|
|||
train_horizon=test_config.LONG_TRAIN_HORIZON,
|
||||
)
|
||||
|
||||
assert n_cached_forecasts == db_session.query(db.Forecast).count()
|
||||
assert n_cached_forecasts == db_session.scalar(
|
||||
sa.select(sa.func.count()).select_from(db.Forecast),
|
||||
)
|
||||
|
||||
assert result1 == result2
|
||||
|
|
|
|||
Loading…
Reference in a new issue