Import velofy.config as pkg_config everywhere

This commit is contained in:
Alexander Hess 2026-11-30 20:19:35 +01:00
commit cf2534f41e
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
5 changed files with 113 additions and 103 deletions

View file

@ -2,7 +2,7 @@
import datetime as dt
from velofy import config
from velofy import config as pkg_config
# The day on which most test cases take place.
@ -15,9 +15,9 @@ NOON = 12
# `START` and `END` constitute a 57-day time span, 8 full weeks plus 1 day.
# That implies a maximum `train_horizon` of `8` as that needs full 7-day weeks.
START = dt.datetime(YEAR, MONTH, DAY, config.SERVICE_START, 0)
START = dt.datetime(YEAR, MONTH, DAY, pkg_config.SERVICE_START, 0)
_end = START + dt.timedelta(days=56) # `56` as `START` is not included
END = dt.datetime(_end.year, _end.month, _end.day, config.SERVICE_END, 0)
END = dt.datetime(_end.year, _end.month, _end.day, pkg_config.SERVICE_END, 0)
# Default time steps (in minutes), for example, for `OrderHistory` objects.
LONG_TIME_STEP = 60

View file

@ -12,7 +12,7 @@ from alembic import command as alembic_cmd
from alembic import config as alembic_config
from sqlalchemy import orm
from velofy import config
from velofy import config as pkg_config
from velofy import db
@ -29,7 +29,7 @@ pytest_plugins = [
if not os.getenv("TESTING"):
raise RuntimeError("Tests must be executed with TESTING set in the environment")
if not config.TESTING:
if not pkg_config.TESTING:
raise RuntimeError("The testing configuration was not loaded")
@ -51,12 +51,12 @@ def db_connection(request):
"""
# We need a fresh database connection for each of the two `params`.
# Otherwise, the first test of the parameter run second will fail.
engine = sa.create_engine(config.DATABASE_URI)
engine = sa.create_engine(pkg_config.DATABASE_URI)
connection = engine.connect()
if request.param == "all_at_once":
with connection.begin():
connection.execute(sa.text(f"CREATE SCHEMA {config.CLEAN_SCHEMA};"))
connection.execute(sa.text(f"CREATE SCHEMA {pkg_config.CLEAN_SCHEMA};"))
db.Base.metadata.create_all(connection)
else:
cfg = alembic_config.Config("alembic.ini")
@ -71,13 +71,15 @@ def db_connection(request):
connection.close()
with engine.begin() as cleanup:
cleanup.execute(sa.text(f"DROP SCHEMA {config.CLEAN_SCHEMA} CASCADE;"))
cleanup.execute(sa.text(f"DROP SCHEMA {pkg_config.CLEAN_SCHEMA} CASCADE;"))
if request.param == "sequentially":
tmp_alembic_version = f"{config.ALEMBIC_TABLE}_{config.CLEAN_SCHEMA}"
tmp_alembic_version = (
f"{pkg_config.ALEMBIC_TABLE}_{pkg_config.CLEAN_SCHEMA}"
)
cleanup.execute(
sa.text(
f"DROP TABLE {config.ALEMBIC_TABLE_SCHEMA}.{tmp_alembic_version};", # noqa:E501
f"DROP TABLE {pkg_config.ALEMBIC_TABLE_SCHEMA}.{tmp_alembic_version};", # noqa:E501
),
)

View file

@ -6,7 +6,7 @@ import pandas as pd
import pytest
from tests import config as test_config
from velofy import config
from velofy import config as pkg_config
from velofy.forecasts import timify
@ -57,7 +57,7 @@ def vertical_datetime_index():
gen = (
start_at
for start_at in start_ats
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
)
index = pd.Index(gen)
@ -113,7 +113,7 @@ def order_totals(good_pixel_id):
(pixel_id, start_at)
for pixel_id in pixel_ids
for start_at in start_ats
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
)
# Re-index `data` filling in `0`s where there is no demand.

View file

@ -6,7 +6,7 @@ import pandas as pd
import pytest
from tests import config as test_config
from velofy import config
from velofy import config as pkg_config
from velofy.forecasts.methods import arima
from velofy.forecasts.methods import ets
from velofy.forecasts.methods import extrapolate_season
@ -24,14 +24,14 @@ def forecast_interval():
future_day.year,
future_day.month,
future_day.day,
config.SERVICE_START,
pkg_config.SERVICE_START,
0,
)
end_of_day = dt.datetime(
future_day.year,
future_day.month,
future_day.day,
config.SERVICE_END,
pkg_config.SERVICE_END,
0,
)
@ -43,7 +43,7 @@ def forecast_interval():
gen = (
start_at
for start_at in start_ats
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
)
index = pd.Index(gen)

View file

@ -10,7 +10,7 @@ import pandas as pd
import pytest
from tests import config as test_config
from velofy import config
from velofy import config as pkg_config
@pytest.fixture
@ -221,7 +221,7 @@ class TestMakeVerticalTimeSeries:
n_daily_time_steps = (
60
* (config.SERVICE_END - config.SERVICE_START)
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
// test_config.LONG_TIME_STEP
)
@ -247,7 +247,7 @@ class TestMakeVerticalTimeSeries:
n_daily_time_steps = (
60
* (config.SERVICE_END - config.SERVICE_START)
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
// test_config.LONG_TIME_STEP
)
@ -345,7 +345,7 @@ class TestMakeRealTimeTimeSeries:
good_predict_at.year,
good_predict_at.month,
good_predict_at.day,
config.SERVICE_START,
pkg_config.SERVICE_START,
0,
)
result = order_history.make_realtime_ts(
@ -358,7 +358,7 @@ class TestMakeRealTimeTimeSeries:
n_daily_time_steps = (
60
* (config.SERVICE_END - config.SERVICE_START)
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
// test_config.LONG_TIME_STEP
)
@ -395,11 +395,13 @@ class TestMakeRealTimeTimeSeries:
n_daily_time_steps = (
60
* (config.SERVICE_END - config.SERVICE_START)
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
// test_config.LONG_TIME_STEP
)
n_time_steps_before = (
60 * (test_config.NOON - config.SERVICE_START) // test_config.LONG_TIME_STEP
60
* (test_config.NOON - pkg_config.SERVICE_START)
// test_config.LONG_TIME_STEP
)
assert (
@ -427,7 +429,7 @@ class TestMakeRealTimeTimeSeries:
n_daily_time_steps = (
60
* (config.SERVICE_END - config.SERVICE_START)
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
// test_config.LONG_TIME_STEP
)