Reword the comments in the test suite

Each comment is one sentence or two short ones
joined by "=>", without a final period.
This commit is contained in:
Alexander Hess 2026-12-03 10:52:09 +01:00
commit bca4250b4d
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
12 changed files with 39 additions and 59 deletions

View file

@ -13,8 +13,8 @@ DATE = (YEAR, MONTH, DAY)
# The hour when most test cases take place # The hour when most test cases take place
NOON = 12 NOON = 12
# `START` and `END` constitute a 57-day time span, 8 full weeks plus 1 day. # `START` and `END` span 57 days, i.e., 8 full weeks plus 1 day
# That implies a maximum `train_horizon` of `8` as that needs full 7-day weeks. # => The maximum `train_horizon` is `8` as it needs full 7-day weeks
START = dt.datetime(YEAR, MONTH, DAY, pkg_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 = START + dt.timedelta(days=56) # `56` as `START` is not included
END = dt.datetime(_end.year, _end.month, _end.day, pkg_config.SERVICE_END, 0) END = dt.datetime(_end.year, _end.month, _end.day, pkg_config.SERVICE_END, 0)
@ -23,9 +23,8 @@ END = dt.datetime(_end.year, _end.month, _end.day, pkg_config.SERVICE_END, 0)
LONG_TIME_STEP = 60 LONG_TIME_STEP = 60
SHORT_TIME_STEP = 30 SHORT_TIME_STEP = 30
TIME_STEPS = (SHORT_TIME_STEP, LONG_TIME_STEP) TIME_STEPS = (SHORT_TIME_STEP, LONG_TIME_STEP)
# The `frequency` of vertical time series is the number of days in a week, 7, # Vertical `frequency`s are 7 days times the time steps per day (12 operating hours)
# times the number of time steps per day. With 12 operating hours (11 am - 11 pm) # => 84 and 168 for the `LONG_TIME_STEP` and `SHORT_TIME_STEP`
# the `frequency`s are 84 and 168 for the `LONG/SHORT_TIME_STEP`s.
VERTICAL_FREQUENCY_LONG = 7 * 12 VERTICAL_FREQUENCY_LONG = 7 * 12
VERTICAL_FREQUENCY_SHORT = 7 * 24 VERTICAL_FREQUENCY_SHORT = 7 * 24

View file

@ -54,8 +54,8 @@ def db_connection(request):
This ensures that Alembic's migration files are consistent. This ensures that Alembic's migration files are consistent.
""" """
# We need a fresh database connection for each of the two `params`. # Each of the two `params` needs a fresh database connection
# Otherwise, the first test of the parameter run second will fail. # => Otherwise, the first test of the second parameter run fails
engine = sa.create_engine(pkg_config.DATABASE_URI) engine = sa.create_engine(pkg_config.DATABASE_URI)
connection = engine.connect() connection = engine.connect()
@ -98,9 +98,8 @@ def db_session(db_connection, monkeypatch):
# that is rolled back at the end of each test case # that is rolled back at the end of each test case
transaction = db_connection.begin() transaction = db_connection.begin()
# Create a session bound to the same connection as the `transaction`. # The session joins the `transaction`'s connection to be rolled back with it
# Using any other session would not result in the roll back. # => Commits inside a test case only release a savepoint
# Commits inside a test case then only release a savepoint.
session = orm.Session(bind=db_connection, join_transaction_mode="create_savepoint") session = orm.Session(bind=db_connection, join_transaction_mode="create_savepoint")
# Monkey patch the package's global `session` object, # Monkey patch the package's global `session` object,

View file

@ -24,15 +24,12 @@ def test_two_pixels_with_two_addresses(
`tests.db.test_grids.test_two_pixels_with_two_addresses`. `tests.db.test_grids.test_two_pixels_with_two_addresses`.
The difference is that the result is written to the database. The difference is that the result is written to the database.
""" """
# Create two `Address` objects in distinct `Pixel`s. # Two `Address`es in distinct `Pixel`s: one in the lower-left `Pixel`, ...
# One `Address` in the lower-left `Pixel`, ...
address1 = make_address(latitude=48.8357377, longitude=2.2517412) address1 = make_address(latitude=48.8357377, longitude=2.2517412)
# ... and another one in the upper-right one. # ... and another one in the upper-right one
address2 = make_address(latitude=48.8898312, longitude=2.4357622) address2 = make_address(latitude=48.8898312, longitude=2.4357622)
# Locate a `Restaurant` at the two `Address`es # `Restaurant`s with one `Order` each make the `Address`es pickup addresses
# and place one `Order` for each of them
# so that the `Address`es are used as `Order.pickup_address`es
restaurant1 = make_restaurant(address=address1) restaurant1 = make_restaurant(address=address1)
restaurant2 = make_restaurant(address=address2) restaurant2 = make_restaurant(address=address2)
order1 = make_order(restaurant=restaurant1) order1 = make_order(restaurant=restaurant1)

View file

@ -20,10 +20,8 @@ class AddressFactory(alchemy.SQLAlchemyModelFactory):
id = factory.Sequence(lambda num: num) id = factory.Sequence(lambda num: num)
created_at = factory.LazyFunction(utils.early_in_the_morning) created_at = factory.LazyFunction(utils.early_in_the_morning)
# When testing, all addresses are considered primary ones. # Non-primary addresses behave no differently in the tests
# As non-primary addresses have no different behavior # => Treat all addresses as primary ones
# and the property is only kept from the original dataset for
# completeness sake, that is ok to do.
primary_id = factory.LazyAttribute(lambda obj: obj.id) primary_id = factory.LazyAttribute(lambda obj: obj.id)
# Mimic a Google Maps Place ID with just random characters # Mimic a Google Maps Place ID with just random characters

View file

@ -72,8 +72,8 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
id = factory.Sequence(lambda num: num) id = factory.Sequence(lambda num: num)
# customer -> set by the `make_order` fixture for better control # customer -> set by the `make_order` fixture for better control
# Attributes regarding the specialization of an `Order`: ad-hoc or scheduled. # Attributes regarding the specialization of an `Order`: ad-hoc or scheduled
# Ad-hoc `Order`s are placed between 11.45 and 14.15. # Ad-hoc `Order`s are placed between 11.45 and 14.15
placed_at = factory.LazyFunction( placed_at = factory.LazyFunction(
lambda: ( lambda: (
dt.datetime(*test_config.DATE, 11, 45) dt.datetime(*test_config.DATE, 11, 45)
@ -88,8 +88,8 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
lambda obj: obj.placed_at + dt.timedelta(minutes=45), lambda obj: obj.placed_at + dt.timedelta(minutes=45),
) )
# Attributes regarding the cancellation of an `Order`. # Attributes regarding the cancellation of an `Order`
# May be overwritten with the `cancel_before_pickup` or `cancel_after_pickup` flags. # May be overwritten with the `cancel_before_pickup` or `cancel_after_pickup` flags
cancelled = False cancelled = False
cancelled_at = None cancelled_at = None
cancelled_at_corrected = None cancelled_at_corrected = None

View file

@ -298,13 +298,11 @@ class TestConstraints:
Scheduled orders must be at least 30 minutes into the future. Scheduled orders must be at least 30 minutes into the future.
""" """
# Create an ad-hoc order first and then make that a scheduled order. # Turning an ad-hoc order into a scheduled one keeps the timestamps consistent
# This way, it is less work to keep the timestamps consistent.
replay_pre_order = make_replay_order(scheduled=False) replay_pre_order = make_replay_order(scheduled=False)
# Make the `scheduled_delivery_at` the quarter of an hour # Schedule the delivery at the quarter of an hour after the next one
# following the next quarter of an hour (i.e., the timestamp # => It is 15 to 30 minutes into the future
# is between 15 and 30 minutes into the future)
replay_pre_order.ad_hoc = False replay_pre_order.ad_hoc = False
replay_pre_order.actual.ad_hoc = False replay_pre_order.actual.ad_hoc = False
minutes_to_next_quarter = 15 - (replay_pre_order.placed_at.minute % 15) minutes_to_next_quarter = 15 - (replay_pre_order.placed_at.minute % 15)

View file

@ -383,9 +383,8 @@ class TestSyncWithGoogleMaps:
"copyrights": "Map data ©2021", "copyrights": "Map data ©2021",
"legs": [ "legs": [
{ {
# We choose an artificially high distance of `9999` # An artificially high distance of `9999` ensures
# so that the synced bicycle distance is longer # that the synced bicycle distance exceeds the fake air distance
# than the randomized air distance (i.e., fake data) for sure
"distance": {"text": "3.0 km", "value": 9999}, "distance": {"text": "3.0 km", "value": 9999},
"duration": {"text": "10 mins", "value": 596}, "duration": {"text": "10 mins", "value": 596},
"end_address": "13 Place Paul et Jean Paul Avisseau, ...", "end_address": "13 Place Paul et Jean Paul Avisseau, ...",

View file

@ -115,8 +115,8 @@ class TestGridification:
""" """
addresses_mock.return_value = [] addresses_mock.return_value = []
# The chosen `side_length` would result in one `Pixel` if there were orders. # One `Pixel` would cover the whole `city` if there were orders
# `+1` as otherwise there would be a second pixel in one direction. # => `+1` as otherwise there would be a second one in one direction
side_length = max(city.total_x, city.total_y) + 1 side_length = max(city.total_x, city.total_y) + 1
result = db.Grid.gridify(city=city, side_length=side_length) result = db.Grid.gridify(city=city, side_length=side_length)
@ -203,7 +203,7 @@ class TestGridification:
addresses_mock.return_value = [ addresses_mock.return_value = [
# One `Address` in the lower-left `Pixel`, ... # One `Address` in the lower-left `Pixel`, ...
make_address(latitude=48.8357377, longitude=2.2517412), make_address(latitude=48.8357377, longitude=2.2517412),
# ... and another one in the upper-right one. # ... and another one in the upper-right one
make_address(latitude=48.8898312, longitude=2.4357622), make_address(latitude=48.8898312, longitude=2.4357622),
] ]

View file

@ -100,11 +100,8 @@ class TestConstraints:
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_restaurants"): with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_restaurants"):
db_session.commit() db_session.commit()
# Here should be a test to check deletion of a referenced pickup address, # No test for "fk_orders_to_addresses_on_pickup_address_id" as the
# so `test_delete_a_referenced_pickup_address(self, db_session, order)`. # "fk_orders_to_restaurants_..." constraint already ensures its integrity
# The corresponding "fk_orders_to_addresses_on_pickup_address_id" constraint
# is very hard to test in isolation as the above "fk_orders_to_restaurants_..."
# constraint ensures its integrity already.
def test_delete_a_referenced_delivery_address(self, db_session, order): def test_delete_a_referenced_delivery_address(self, db_session, order):
"""Remove a record that is referenced with a FK.""" """Remove a record that is referenced with a FK."""
@ -289,13 +286,11 @@ class TestConstraints:
Scheduled orders must be at least 30 minutes into the future. Scheduled orders must be at least 30 minutes into the future.
""" """
# Create an ad-hoc order first and then make that a scheduled order. # Turning an ad-hoc order into a scheduled one keeps the timestamps consistent
# This way, it is less work to keep the timestamps consistent.
pre_order = make_order(scheduled=False) pre_order = make_order(scheduled=False)
# Make the `scheduled_delivery_at` the quarter of an hour # Schedule the delivery at the quarter of an hour after the next one
# following the next quarter of an hour (i.e., the timestamp # => It is 15 to 30 minutes into the future
# is between 15 and 30 minutes into the future)
pre_order.ad_hoc = False pre_order.ad_hoc = False
minutes_to_next_quarter = 15 - (pre_order.placed_at.minute % 15) minutes_to_next_quarter = 15 - (pre_order.placed_at.minute % 15)
pre_order.scheduled_delivery_at = ( pre_order.scheduled_delivery_at = (
@ -1187,8 +1182,8 @@ def test_make_random_orders(
else: else:
cancel_before_pickup, cancel_after_pickup = False, False cancel_before_pickup, cancel_after_pickup = False, False
# Write all the generated objects to the database. # Writing all generated objects to the database checks their integrity
# This should already trigger an `IntegrityError` if the data are flawed. # => An `IntegrityError` here means the fake data are flawed
order = make_order( order = make_order(
scheduled=scheduled, scheduled=scheduled,
restaurant=restaurant, restaurant=restaurant,

View file

@ -27,8 +27,7 @@ def horizontal_datetime_index():
index = pd.Index(gen) index = pd.Index(gen)
index.name = "start_at" index.name = "start_at"
# Sanity check. # `n_days` includes both the `START` and `END` day => `+1`
# `+1` as both the `START` and `END` day are included.
n_days = (test_config.END - test_config.START).days + 1 n_days = (test_config.END - test_config.START).days + 1
assert len(index) == n_days assert len(index) == n_days
@ -63,8 +62,7 @@ def vertical_datetime_index():
index = pd.Index(gen) index = pd.Index(gen)
index.name = "start_at" index.name = "start_at"
# Sanity check: n_days * n_number_of_opening_hours. # `n_days` includes both the `START` and `END` day => `+1`
# `+1` as both the `START` and `END` day are included.
n_days = (test_config.END - test_config.START).days + 1 n_days = (test_config.END - test_config.START).days + 1
assert len(index) == n_days * 12 assert len(index) == n_days * 12
@ -122,8 +120,7 @@ def order_totals(good_pixel_id):
df = pd.DataFrame(data={"n_orders": 1}, index=index) df = pd.DataFrame(data={"n_orders": 1}, index=index)
# Sanity check: n_pixels * n_time_steps_per_day * n_days. # `n_days` includes both the `START` and `END` day => `+1`
# `+1` as both the `START` and `END` day are included.
n_days = (test_config.END - test_config.START).days + 1 n_days = (test_config.END - test_config.START).days + 1
assert len(df) == 2 * 12 * n_days assert len(df) == 2 * 12 * n_days

View file

@ -125,8 +125,7 @@ class TestAggregateOrders:
result = oh.aggregate_orders() result = oh.aggregate_orders()
# Even though there are only 10 orders, there are 12 rows in the `DataFrame`. # `0`s fill the hours without demand at the end => 12 rows from 10 orders
# That is so as `0`s are filled in for hours without any demand at the end.
assert len(result) == 12 assert len(result) == 12
assert result["n_orders"].min() == 0 assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 1 assert result["n_orders"].max() == 1
@ -241,8 +240,7 @@ class TestAggregateOrders:
result = oh.aggregate_orders() result = oh.aggregate_orders()
# The resulting `DataFrame` has 24 rows for the 24 30-minute time steps. # 24 rows for the 24 30-minute time steps, alternating between `0` and `1`
# The rows' values are `0` and `1` alternating.
assert len(result) == 24 assert len(result) == 24
assert result["n_orders"].min() == 0 assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 1 assert result["n_orders"].max() == 1
@ -314,7 +312,7 @@ class TestAggregateOrders:
"""A persisted `Grid` with two `Pixel` objects.""" """A persisted `Grid` with two `Pixel` objects."""
# One `Address` in the lower-left `Pixel`, ... # One `Address` in the lower-left `Pixel`, ...
address1 = make_address(latitude=48.8357377, longitude=2.2517412) address1 = make_address(latitude=48.8357377, longitude=2.2517412)
# ... and another one in the upper-right one. # ... and another one in the upper-right one
address2 = make_address(latitude=48.8898312, longitude=2.4357622) address2 = make_address(latitude=48.8898312, longitude=2.4357622)
addresses_mock.return_value = [address1, address2] addresses_mock.return_value = [address1, address2]

View file

@ -104,7 +104,7 @@ class TestChooseTacticalModel:
data = order_history._data data = order_history._data
data.loc[:, "n_orders"] = 1 data.loc[:, "n_orders"] = 1
# ... and we set three additional time steps per day to `0`. # ... and we set three additional time steps per day to `0`
data.loc[ data.loc[
# all `Pixel`s, all `Order`s in time steps starting at 11 am # all `Pixel`s, all `Order`s in time steps starting at 11 am
(slice(None), slice(data.index.levels[1][0], None, 12)), (slice(None), slice(data.index.levels[1][0], None, 12)),