Enable more lint rules #10

Merged
alexander merged 31 commits from more-lint-rules into develop 2026-11-30 23:59:09 +01:00
20 changed files with 201 additions and 99 deletions
Showing only changes of commit ae2dc8db64 - Show all commits

Enable EM in flake8 and ruff

Alexander Hess 2026-11-30 22:59:41 +01:00
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -12,7 +12,8 @@ from velofy import db
# Disable the --sql option, a.k.a, the "offline mode".
if context.is_offline_mode():
raise NotImplementedError("The --sql option is not implemented in this project")
msg = "The --sql option is not implemented in this project"
raise NotImplementedError(msg)
# Set up the default Python logger from the alembic.ini file.

View file

@ -202,6 +202,7 @@ def lint_code(session: nox.Session) -> None:
"flake8-comprehensions",
"flake8-debugger",
"flake8-docstrings",
"flake8-errmsg",
"flake8-implicit-str-concat",
"flake8-pyproject",
"flake8-pytest-style",

View file

@ -102,6 +102,7 @@ dev = [
"flake8-comprehensions (>=3.17.0,<4.0.0)",
"flake8-debugger (>=4.1.2,<5.0.0)",
"flake8-docstrings (>=1.7.0,<2.0.0)",
"flake8-errmsg (>=0.7.0,<0.8.0)",
"flake8-implicit-str-concat (>=0.7.0,<0.8.0)",
"flake8-pyproject (>=1.2.4,<2.0.0)",
"flake8-pytest-style (>=2.2.0,<3.0.0)",
@ -227,6 +228,8 @@ select = [
"T100",
# flake8-docstrings => PEP257 compliance
"D1", "D2", "D3", "D4",
# flake8-errmsg => Shorter tracebacks
"EM",
# flake8-implicit-str-concat => Unified string concatenation
"ISC",
# flake8-pytest-style => enforce a consistent style with pytest
@ -511,6 +514,8 @@ select = [
"D",
# pycodestyle => PEP8 compliance
"E", "W",
# flake8-errmsg => Shorter tracebacks
"EM",
# pyflakes => basic errors
"F",
# flake8-boolean-trap => Keyword-only flags

View file

@ -115,7 +115,8 @@ def make_config(env: str = "production") -> Config:
elif env.strip().lower() == "testing":
config = TestingConfig()
else:
raise ValueError("Must be either 'production' or 'testing'")
msg = "Must be either 'production' or 'testing'"
raise ValueError(msg)
# Without a PostgreSQL database the package cannot work.
# As pytest sets the "TESTING" environment variable explicitly,

View file

@ -270,7 +270,8 @@ class Path(meta.Base):
underlying attributes (i.e., `._directions`) are to be changed.
"""
if not self._directions:
raise RuntimeError("_directions is not set")
msg = "_directions is not set"
raise RuntimeError(msg)
points = [utils.Location(*point) for point in json.loads(self._directions)]
for point in points:

View file

@ -549,9 +549,11 @@ class Order(meta.Base):
This measures the time it took the UDP to notify the `.courier` after dispatch.
"""
if not self.dispatch_at:
raise RuntimeError("dispatch_at is not set")
msg = "dispatch_at is not set"
raise RuntimeError(msg)
if not self.courier_accepted_at:
raise RuntimeError("courier_accepted_at is not set")
msg = "courier_accepted_at is not set"
raise RuntimeError(msg)
return self.courier_accepted_at - self.dispatch_at
@property
@ -561,36 +563,44 @@ class Order(meta.Base):
A subset of `.time_to_accept`.
"""
if not self.courier_notified_at:
raise RuntimeError("courier_notified_at is not set")
msg = "courier_notified_at is not set"
raise RuntimeError(msg)
if not self.courier_accepted_at:
raise RuntimeError("courier_accepted_at is not set")
msg = "courier_accepted_at is not set"
raise RuntimeError(msg)
return self.courier_accepted_at - self.courier_notified_at
@property
def time_to_pickup(self) -> dt.timedelta:
"""Time from the `.courier`'s acceptance to arrival at `.pickup_address`."""
if not self.courier_accepted_at:
raise RuntimeError("courier_accepted_at is not set")
msg = "courier_accepted_at is not set"
raise RuntimeError(msg)
if not self.reached_pickup_at:
raise RuntimeError("reached_pickup_at is not set")
msg = "reached_pickup_at is not set"
raise RuntimeError(msg)
return self.reached_pickup_at - self.courier_accepted_at
@property
def time_at_pickup(self) -> dt.timedelta:
"""Time the `.courier` stayed at the `.pickup_address`."""
if not self.reached_pickup_at:
raise RuntimeError("reached_pickup_at is not set")
msg = "reached_pickup_at is not set"
raise RuntimeError(msg)
if not self.pickup_at:
raise RuntimeError("pickup_at is not set")
msg = "pickup_at is not set"
raise RuntimeError(msg)
return self.pickup_at - self.reached_pickup_at
@property
def scheduled_pickup_at(self) -> dt.datetime:
"""Point in time at which the pickup was scheduled."""
if not self.restaurant_notified_at:
raise RuntimeError("restaurant_notified_at is not set")
msg = "restaurant_notified_at is not set"
raise RuntimeError(msg)
if not self.estimated_prep_duration:
raise RuntimeError("estimated_prep_duration is not set")
msg = "estimated_prep_duration is not set"
raise RuntimeError(msg)
delta = dt.timedelta(seconds=self.estimated_prep_duration)
return self.restaurant_notified_at + delta
@ -605,7 +615,8 @@ class Order(meta.Base):
Goes together with `.courier_late`.
"""
if not self.reached_pickup_at:
raise RuntimeError("reached_pickup_at is not set")
msg = "reached_pickup_at is not set"
raise RuntimeError(msg)
return max(
dt.timedelta(),
@ -623,7 +634,8 @@ class Order(meta.Base):
Goes together with `.courier_early`.
"""
if not self.reached_pickup_at:
raise RuntimeError("reached_pickup_at is not set")
msg = "reached_pickup_at is not set"
raise RuntimeError(msg)
return max(
dt.timedelta(),
@ -641,7 +653,8 @@ class Order(meta.Base):
Goes together with `.restaurant_late`.
"""
if not self.pickup_at:
raise RuntimeError("pickup_at is not set")
msg = "pickup_at is not set"
raise RuntimeError(msg)
return max(dt.timedelta(), self.scheduled_pickup_at - self.pickup_at)
@ -656,7 +669,8 @@ class Order(meta.Base):
Goes together with `.restaurant_early`.
"""
if not self.pickup_at:
raise RuntimeError("pickup_at is not set")
msg = "pickup_at is not set"
raise RuntimeError(msg)
return max(dt.timedelta(), self.pickup_at - self.scheduled_pickup_at)
@ -664,18 +678,22 @@ class Order(meta.Base):
def time_to_delivery(self) -> dt.timedelta:
"""Time the `.courier` took from `.pickup_address` to `.delivery_address`."""
if not self.pickup_at:
raise RuntimeError("pickup_at is not set")
msg = "pickup_at is not set"
raise RuntimeError(msg)
if not self.reached_delivery_at:
raise RuntimeError("reached_delivery_at is not set")
msg = "reached_delivery_at is not set"
raise RuntimeError(msg)
return self.reached_delivery_at - self.pickup_at
@property
def time_at_delivery(self) -> dt.timedelta:
"""Time the `.courier` stayed at the `.delivery_address`."""
if not self.reached_delivery_at:
raise RuntimeError("reached_delivery_at is not set")
msg = "reached_delivery_at is not set"
raise RuntimeError(msg)
if not self.delivery_at:
raise RuntimeError("delivery_at is not set")
msg = "delivery_at is not set"
raise RuntimeError(msg)
return self.delivery_at - self.reached_delivery_at
@property
@ -696,11 +714,14 @@ class Order(meta.Base):
Goes together with `.delivery_late`.
"""
if not self.scheduled:
raise AttributeError("Makes sense only for scheduled orders")
msg = "Makes sense only for scheduled orders"
raise AttributeError(msg)
if not self.scheduled_delivery_at:
raise RuntimeError("scheduled_delivery_at is not set")
msg = "scheduled_delivery_at is not set"
raise RuntimeError(msg)
if not self.delivery_at:
raise RuntimeError("delivery_at is not set")
msg = "delivery_at is not set"
raise RuntimeError(msg)
return max(dt.timedelta(), self.scheduled_delivery_at - self.delivery_at)
@property
@ -714,22 +735,28 @@ class Order(meta.Base):
Goes together with `.delivery_early`.
"""
if not self.scheduled:
raise AttributeError("Makes sense only for scheduled orders")
msg = "Makes sense only for scheduled orders"
raise AttributeError(msg)
if not self.scheduled_delivery_at:
raise RuntimeError("scheduled_delivery_at is not set")
msg = "scheduled_delivery_at is not set"
raise RuntimeError(msg)
if not self.delivery_at:
raise RuntimeError("delivery_at is not set")
msg = "delivery_at is not set"
raise RuntimeError(msg)
return max(dt.timedelta(), self.delivery_at - self.scheduled_delivery_at)
@property
def total_time(self) -> dt.timedelta:
"""Time from order placement to delivery for an `.ad_hoc` order."""
if self.scheduled:
raise AttributeError("Scheduled orders have no total_time")
msg = "Scheduled orders have no total_time"
raise AttributeError(msg)
if self.cancelled:
raise RuntimeError("Cancelled orders have no total_time")
msg = "Cancelled orders have no total_time"
raise RuntimeError(msg)
if not self.delivery_at:
raise RuntimeError("delivery_at is not set")
msg = "delivery_at is not set"
raise RuntimeError(msg)
return self.delivery_at - self.placed_at
# Other Methods

View file

@ -103,7 +103,8 @@ class Location:
return NotImplemented
if self.zone != other.zone:
raise ValueError("locations must be in the same zone, including the band")
msg = "locations must be in the same zone, including the band"
raise ValueError(msg)
return (self.easting, self.northing) == (other.easting, other.northing)
@ -114,7 +115,8 @@ class Location:
The origin, which defines the `(0, 0)` coordinate, is set with `.relate_to()`.
"""
if self._normalized_easting is None:
raise RuntimeError("an origin to relate to must be set first")
msg = "an origin to relate to must be set first"
raise RuntimeError(msg)
return self._normalized_easting
@ -125,7 +127,8 @@ class Location:
The origin, which defines the `(0, 0)` coordinate, is set with `.relate_to()`.
"""
if self._normalized_northing is None:
raise RuntimeError("an origin to relate to must be set first")
msg = "an origin to relate to must be set first"
raise RuntimeError(msg)
return self._normalized_northing
@ -140,13 +143,16 @@ class Location:
properties, the `other` origin may only be set once!
"""
if self._normalized_easting is not None:
raise RuntimeError("the `other` origin may only be set once")
msg = "the `other` origin may only be set once"
raise RuntimeError(msg)
if not isinstance(other, Location):
raise TypeError("`other` is not a `Location` object")
msg = "`other` is not a `Location` object"
raise TypeError(msg)
if self.zone != other.zone:
raise ValueError("`other` must be in the same zone, including the band")
msg = "`other` must be in the same zone, including the band"
raise ValueError(msg)
self._normalized_easting = self.easting - other.easting
self._normalized_northing = self.northing - other.northing

View file

@ -39,7 +39,8 @@ def predict(
robjects.r("set.seed(42)")
if training_ts.isna().any():
raise ValueError("`training_ts` must not contain `NaN` values")
msg = "`training_ts` must not contain `NaN` values"
raise ValueError(msg)
# Copy the data from Python to R.
robjects.globalenv["data"] = robjects.r["ts"](

View file

@ -94,18 +94,21 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915
# Validate all arguments and set default values.
if time_series.isna().any():
raise ValueError("`time_series` must not contain `NaN` values")
msg = "`time_series` must not contain `NaN` values"
raise ValueError(msg)
if ns % 2 == 0 or ns < 7:
raise ValueError("`ns` must be odd and `>= 7`")
msg = "`ns` must be odd and `>= 7`"
raise ValueError(msg)
default_nt = math.ceil((1.5 * frequency) / (1 - (1.5 / ns)))
if nt is not None:
if nt % 2 == 0 or nt < default_nt:
raise ValueError(
msg = (
"`nt` must be odd and `>= (1.5 * frequency) / [1 - (1.5 / ns)]`, "
f"which is {default_nt}",
f"which is {default_nt}"
)
raise ValueError(msg)
else:
nt = default_nt
if nt % 2 == 0: # pragma: no cover => hard to construct edge case
@ -113,42 +116,51 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915
if nl is not None:
if nl % 2 == 0 or nl < frequency:
raise ValueError("`nl` must be odd and `>= frequency`")
msg = "`nl` must be odd and `>= frequency`"
raise ValueError(msg)
elif frequency % 2 == 0:
nl = frequency + 1
else: # pragma: no cover => hard to construct edge case
nl = frequency
if ds not in {0, 1}:
raise ValueError("`ds` must be either `0` or `1`")
msg = "`ds` must be either `0` or `1`"
raise ValueError(msg)
if dt not in {0, 1}:
raise ValueError("`dt` must be either `0` or `1`")
msg = "`dt` must be either `0` or `1`"
raise ValueError(msg)
if dl not in {0, 1}:
raise ValueError("`dl` must be either `0` or `1`")
msg = "`dl` must be either `0` or `1`"
raise ValueError(msg)
if js is not None:
if js <= 0:
raise ValueError("`js` must be positive")
msg = "`js` must be positive"
raise ValueError(msg)
else:
js = math.ceil(ns / 10)
if jt is not None:
if jt <= 0:
raise ValueError("`jt` must be positive")
msg = "`jt` must be positive"
raise ValueError(msg)
else:
jt = math.ceil(nt / 10)
if jl is not None:
if jl <= 0:
raise ValueError("`jl` must be positive")
msg = "`jl` must be positive"
raise ValueError(msg)
else:
jl = math.ceil(nl / 10)
if ni <= 0:
raise ValueError("`ni` must be positive")
msg = "`ni` must be positive"
raise ValueError(msg)
if no < 0:
raise ValueError("`no` must be non-negative")
msg = "`no` must be non-negative"
raise ValueError(msg)
robust = no > 0
# Initialize R only if it is actually used.

View file

@ -40,7 +40,8 @@ def predict(
robjects.r("set.seed(42)")
if training_ts.isna().any():
raise ValueError("`training_ts` must not contain `NaN` values")
msg = "`training_ts` must not contain `NaN` values"
raise ValueError(msg)
# Copy the data from Python to R.
robjects.globalenv["data"] = robjects.r["ts"](

View file

@ -37,7 +37,8 @@ def predict(
could not be made for time steps in the `forecast_interval`
"""
if training_ts.isna().any():
raise ValueError("`training_ts` must not contain `NaN` values")
msg = "`training_ts` must not contain `NaN` values"
raise ValueError(msg)
extrapolated_ts = pd.Series(index=forecast_interval, dtype=float)
seasonal_lag = frequency * (training_ts.index[1] - training_ts.index[0])
@ -61,7 +62,8 @@ def predict(
# Sanity check.
if extrapolated_ts.isna().any(): # pragma: no cover
raise ValueError("missing predictions in the `forecast_interval`")
msg = "missing predictions in the `forecast_interval`"
raise ValueError(msg)
return pd.DataFrame(
data={

View file

@ -118,6 +118,7 @@ class ForecastingModelABC(abc.ABC):
return forecast
# ..., however, we put in a loud error, just in case.
raise RuntimeError( # pragma: no cover
"`Forecast` for `predict_at` was not returned by `*Model.predict()`",
msg = ( # pragma: no cover
"`Forecast` for `predict_at` was not returned by `*Model.predict()`"
)
raise RuntimeError(msg) # pragma: no cover

View file

@ -52,7 +52,8 @@ class HorizontalETSModel(base.ForecastingModelABC):
# Sanity check.
if frequency != 7: # pragma: no cover
raise RuntimeError("`frequency` should be `7`")
msg = "`frequency` should be `7`"
raise RuntimeError(msg)
# Make `predictions` with the seasonal ETS method ("ZZZ" model).
predictions = methods.ets.predict(
@ -66,9 +67,11 @@ class HorizontalETSModel(base.ForecastingModelABC):
# Sanity checks.
if predictions.isna().sum().any(): # pragma: no cover
raise RuntimeError("missing predictions in hets model")
msg = "missing predictions in hets model"
raise RuntimeError(msg)
if predict_at not in predictions.index: # pragma: no cover
raise RuntimeError("missing prediction for `predict_at`")
msg = "missing prediction for `predict_at`"
raise RuntimeError(msg)
return predictions
@ -109,11 +112,11 @@ class HorizontalSMAModel(base.ForecastingModelABC):
# Sanity checks.
if frequency != 7: # pragma: no cover
raise RuntimeError("`frequency` should be `7`")
msg = "`frequency` should be `7`"
raise RuntimeError(msg)
if len(actuals_ts) != 1: # pragma: no cover
raise RuntimeError(
"the hsma model can only predict one step into the future",
)
msg = "the hsma model can only predict one step into the future"
raise RuntimeError(msg)
# The "prediction" is calculated as the `np.mean()`.
# As the `training_ts` covers only full week horizons,
@ -132,8 +135,10 @@ class HorizontalSMAModel(base.ForecastingModelABC):
# Sanity checks.
if predictions[["actual", "prediction"]].isna().any().any(): # pragma: no cover
raise RuntimeError("missing predictions in hsma model")
msg = "missing predictions in hsma model"
raise RuntimeError(msg)
if predict_at not in predictions.index: # pragma: no cover
raise RuntimeError("missing prediction for `predict_at`")
msg = "missing prediction for `predict_at`"
raise RuntimeError(msg)
return predictions

View file

@ -53,11 +53,11 @@ class TrivialModel(base.ForecastingModelABC):
# Sanity checks.
if frequency != 7: # pragma: no cover
raise RuntimeError("`frequency` should be `7`")
msg = "`frequency` should be `7`"
raise RuntimeError(msg)
if len(actuals_ts) != 1: # pragma: no cover
raise RuntimeError(
"the trivial model can only predict one step into the future",
)
msg = "the trivial model can only predict one step into the future"
raise RuntimeError(msg)
# The "prediction" is simply `0.0`.
predictions = pd.DataFrame(
@ -74,8 +74,10 @@ class TrivialModel(base.ForecastingModelABC):
# Sanity checks.
if predictions["actual"].isna().any(): # pragma: no cover
raise RuntimeError("missing actuals in trivial model")
msg = "missing actuals in trivial model"
raise RuntimeError(msg)
if predict_at not in predictions.index: # pragma: no cover
raise RuntimeError("missing prediction for `predict_at`")
msg = "missing prediction for `predict_at`"
raise RuntimeError(msg)
return predictions

View file

@ -114,10 +114,13 @@ class RealtimeARIMAModel(base.ForecastingModelABC):
# Sanity checks.
if len(predictions) != 1: # pragma: no cover
raise RuntimeError("real-time models should predict exactly one time step")
msg = "real-time models should predict exactly one time step"
raise RuntimeError(msg)
if predictions.isna().sum().any(): # pragma: no cover
raise RuntimeError("missing predictions in rtarima model")
msg = "missing predictions in rtarima model"
raise RuntimeError(msg)
if predict_at not in predictions.index: # pragma: no cover
raise RuntimeError("missing prediction for `predict_at`")
msg = "missing prediction for `predict_at`"
raise RuntimeError(msg)
return predictions

View file

@ -114,10 +114,13 @@ class VerticalARIMAModel(base.ForecastingModelABC):
# Sanity checks.
if len(predictions) <= 1: # pragma: no cover
raise RuntimeError("vertical models should predict several time steps")
msg = "vertical models should predict several time steps"
raise RuntimeError(msg)
if predictions.isna().sum().any(): # pragma: no cover
raise RuntimeError("missing predictions in varima model")
msg = "missing predictions in varima model"
raise RuntimeError(msg)
if predict_at not in predictions.index: # pragma: no cover
raise RuntimeError("missing prediction for `predict_at`")
msg = "missing prediction for `predict_at`"
raise RuntimeError(msg)
return predictions

View file

@ -37,7 +37,8 @@ class OrderHistory:
60 * (pkg_config.SERVICE_END - pkg_config.SERVICE_START) / time_step
)
if n_daily_time_steps != int(n_daily_time_steps): # pragma: no cover
raise RuntimeError("Internal error: configuration has invalid TIME_STEPS")
msg = "Internal error: configuration has invalid TIME_STEPS"
raise RuntimeError(msg)
self._n_daily_time_steps = int(n_daily_time_steps)
# The `_data` are populated by `.aggregate_orders()`.
@ -193,13 +194,15 @@ class OrderHistory:
try:
intra_pixel = self.totals.loc[pixel_id]
except KeyError:
raise LookupError("The `pixel_id` is not in the `grid`") from None
msg = "The `pixel_id` is not in the `grid`"
raise LookupError(msg) from None
first_order = intra_pixel[intra_pixel["n_orders"] > 0].index.min()
# Sanity check: without an `Order`, the `Pixel` should not exist.
if first_order is pd.NaT: # pragma: no cover
raise RuntimeError("no orders in the pixel")
msg = "no orders in the pixel"
raise RuntimeError(msg)
# Return a proper `datetime.datetime` object.
return dt.datetime(
@ -226,13 +229,15 @@ class OrderHistory:
try:
intra_pixel = self.totals.loc[pixel_id]
except KeyError:
raise LookupError("The `pixel_id` is not in the `grid`") from None
msg = "The `pixel_id` is not in the `grid`"
raise LookupError(msg) from None
last_order = intra_pixel[intra_pixel["n_orders"] > 0].index.max()
# Sanity check: without an `Order`, the `Pixel` should not exist.
if last_order is pd.NaT: # pragma: no cover
raise RuntimeError("no orders in the pixel")
msg = "no orders in the pixel"
raise RuntimeError(msg)
# Return a proper `datetime.datetime` object.
return dt.datetime(
@ -273,10 +278,12 @@ class OrderHistory:
try:
intra_pixel = self.totals.loc[pixel_id]
except KeyError:
raise LookupError("The `pixel_id` is not in the `grid`") from None
msg = "The `pixel_id` is not in the `grid`"
raise LookupError(msg) from None
if predict_at >= pkg_config.CUTOFF_DAY: # pragma: no cover
raise RuntimeError("Internal error: cannot predict beyond the given data")
msg = "Internal error: cannot predict beyond the given data"
raise RuntimeError(msg)
# The first and last training day are just before the `predict_at` day
# and span exactly `train_horizon` weeks covering only the times of the
@ -307,11 +314,13 @@ class OrderHistory:
"n_orders",
]
if len(training_ts) != frequency * train_horizon:
raise RuntimeError("Not enough historic data for `predict_at`")
msg = "Not enough historic data for `predict_at`"
raise RuntimeError(msg)
actuals_ts = intra_pixel.loc[[predict_at], "n_orders"]
if not len(actuals_ts): # pragma: no cover
raise LookupError("`predict_at` is not in the order history")
msg = "`predict_at` is not in the order history"
raise LookupError(msg)
return training_ts, frequency, actuals_ts
@ -345,10 +354,12 @@ class OrderHistory:
try:
intra_pixel = self.totals.loc[pixel_id]
except KeyError:
raise LookupError("The `pixel_id` is not in the `grid`") from None
msg = "The `pixel_id` is not in the `grid`"
raise LookupError(msg) from None
if predict_day >= pkg_config.CUTOFF_DAY.date(): # pragma: no cover
raise RuntimeError("Internal error: cannot predict beyond the given data")
msg = "Internal error: cannot predict beyond the given data"
raise RuntimeError(msg)
# The first and last training day are just before the `predict_day`
# and span exactly `train_horizon` weeks covering all times of the day.
@ -378,7 +389,8 @@ class OrderHistory:
"n_orders",
]
if len(training_ts) != frequency * train_horizon:
raise RuntimeError("Not enough historic data for `predict_day`")
msg = "Not enough historic data for `predict_day`"
raise RuntimeError(msg)
first_prediction_at = dt.datetime(
predict_day.year,
@ -400,7 +412,8 @@ class OrderHistory:
"n_orders",
]
if not len(actuals_ts): # pragma: no cover
raise LookupError("`predict_day` is not in the order history")
msg = "`predict_day` is not in the order history"
raise LookupError(msg)
return training_ts, frequency, actuals_ts
@ -434,10 +447,12 @@ class OrderHistory:
try:
intra_pixel = self.totals.loc[pixel_id]
except KeyError:
raise LookupError("The `pixel_id` is not in the `grid`") from None
msg = "The `pixel_id` is not in the `grid`"
raise LookupError(msg) from None
if predict_at >= pkg_config.CUTOFF_DAY: # pragma: no cover
raise RuntimeError("Internal error: cannot predict beyond the given data")
msg = "Internal error: cannot predict beyond the given data"
raise RuntimeError(msg)
# The first and last training day are just before the `predict_at` day
# and span exactly `train_horizon` weeks covering all times of the day,
@ -492,11 +507,13 @@ class OrderHistory:
// self._time_step
)
if len(training_ts) != frequency * train_horizon + n_time_steps_on_predict_day:
raise RuntimeError("Not enough historic data for `predict_day`")
msg = "Not enough historic data for `predict_day`"
raise RuntimeError(msg)
actuals_ts = intra_pixel.loc[[predict_at], "n_orders"]
if not len(actuals_ts): # pragma: no cover
raise LookupError("`predict_at` is not in the order history")
msg = "`predict_at` is not in the order history"
raise LookupError(msg)
return training_ts, frequency, actuals_ts
@ -588,6 +605,5 @@ class OrderHistory:
# = "no demand"
return models.TrivialModel(order_history=self)
raise RuntimeError(
"no rule for the given average daily demand and training horizon",
)
msg = "no rule for the given average daily demand and training horizon"
raise RuntimeError(msg)

View file

@ -27,10 +27,12 @@ pytest_plugins = [
# The TESTING environment variable is set
# in pyproject.toml in pytest's config section.
if not os.getenv("TESTING"):
raise RuntimeError("Tests must be executed with TESTING set in the environment")
msg = "Tests must be executed with TESTING set in the environment"
raise RuntimeError(msg)
if not pkg_config.TESTING:
raise RuntimeError("The testing configuration was not loaded")
msg = "The testing configuration was not loaded"
raise RuntimeError(msg)
@pytest.fixture(scope="session", params=["all_at_once", "sequentially"])

View file

@ -141,7 +141,8 @@ def make_replay_order(make_order, simulation):
"""
if scheduled:
if order and order.ad_hoc is False:
raise RuntimeError("`order` must be scheduled")
msg = "`order` must be scheduled"
raise RuntimeError(msg)
if order is None:
order = make_order(scheduled=True)

11
uv.lock generated
View file

@ -1021,6 +1021,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/3f/7d/76a278fa43250441ed9300c344f889c7fb1817080c8fb8996b840bf421c2/flake8_docstrings-1.7.0-py2.py3-none-any.whl", hash = "sha256:51f2344026da083fc084166a9353f5082b01f72901df422f74b4d953ae88ac75", size = 4994, upload-time = "2023-01-25T14:27:12.32Z" },
]
[[package]]
name = "flake8-errmsg"
version = "0.7.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/85/90/be4b2ebfe475a6429dc15fb183abcf9d177dd2320853fca6b5c1b5448812/flake8_errmsg-0.7.0.tar.gz", hash = "sha256:0af7480d4a892c94e7b399ecd38ea4b1889e2c7c8b398080c4c6e756cbacbe95", size = 14557, upload-time = "2026-06-18T14:56:02.366Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/62/47/2d71411967eabc97dc520fc80dc9ea275b07c0357c290e0e8ca1829bc448/flake8_errmsg-0.7.0-py3-none-any.whl", hash = "sha256:406c35d07fc7edc4deb2091e0d9a7177a2102d304f58d56ef18f782834a959f0", size = 9871, upload-time = "2026-06-18T14:56:01.245Z" },
]
[[package]]
name = "flake8-implicit-str-concat"
version = "0.7.0"
@ -3859,6 +3868,7 @@ dev = [
{ name = "flake8-comprehensions" },
{ name = "flake8-debugger" },
{ name = "flake8-docstrings" },
{ name = "flake8-errmsg" },
{ name = "flake8-implicit-str-concat" },
{ name = "flake8-pyproject" },
{ name = "flake8-pytest-style" },
@ -3931,6 +3941,7 @@ dev = [
{ name = "flake8-comprehensions", specifier = ">=3.17.0,<4.0.0" },
{ name = "flake8-debugger", specifier = ">=4.1.2,<5.0.0" },
{ name = "flake8-docstrings", specifier = ">=1.7.0,<2.0.0" },
{ name = "flake8-errmsg", specifier = ">=0.7.0,<0.8.0" },
{ name = "flake8-implicit-str-concat", specifier = ">=0.7.0,<0.8.0" },
{ name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" },
{ name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" },