Remove periods from one-sentence comments
This commit is contained in:
parent
454c2898a0
commit
049a5f6f62
14 changed files with 308 additions and 308 deletions
|
|
@ -26,12 +26,12 @@ class AddressFactory(alchemy.SQLAlchemyModelFactory):
|
|||
# completeness sake, that is ok to do.
|
||||
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
|
||||
place_id = factory.LazyFunction(
|
||||
lambda: "".join(random.choice(string.ascii_lowercase) for _ in range(20)),
|
||||
)
|
||||
|
||||
# Place the addresses somewhere in downtown Paris.
|
||||
# Place the addresses somewhere in downtown Paris
|
||||
latitude = factory.Faker("pyfloat", min_value=48.845, max_value=48.865)
|
||||
longitude = factory.Faker("pyfloat", min_value=2.31, max_value=2.37)
|
||||
# city -> set by the `make_address` fixture as there is only one `city`
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
|
|||
"""
|
||||
|
||||
# Timestamps after `cancelled_at` are discarded
|
||||
# by the `post_generation` hook at the end of the `OrderFactory`.
|
||||
# by the `post_generation` hook at the end of the `OrderFactory`
|
||||
cancel_ = factory.Trait( # -> leading underscore does not work
|
||||
cancelled=True,
|
||||
cancelled_at_corrected=False,
|
||||
|
|
@ -83,7 +83,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
|
|||
ad_hoc = True
|
||||
scheduled_delivery_at = None
|
||||
scheduled_delivery_at_corrected = None
|
||||
# Without statistical info, we assume an ad-hoc `Order` delivered after 45 minutes.
|
||||
# Without statistical info, we assume an ad-hoc `Order` delivered after 45 minutes
|
||||
first_estimated_delivery_at = factory.LazyAttribute(
|
||||
lambda obj: obj.placed_at + dt.timedelta(minutes=45),
|
||||
)
|
||||
|
|
@ -118,7 +118,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
|
|||
restaurant_confirmed_at_corrected = factory.LazyAttribute(
|
||||
lambda obj: False if obj.restaurant_confirmed_at else None,
|
||||
)
|
||||
# Use the database defaults of the historic data.
|
||||
# Use the database defaults of the historic data
|
||||
estimated_prep_duration = 900
|
||||
estimated_prep_duration_corrected = False
|
||||
estimated_prep_buffer = 480
|
||||
|
|
@ -150,7 +150,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
|
|||
courier_accepted_at_corrected = factory.LazyAttribute(
|
||||
lambda obj: False if obj.courier_accepted_at else None,
|
||||
)
|
||||
# Sample a realistic utilization.
|
||||
# Sample a realistic utilization
|
||||
utilization = factory.LazyFunction(lambda: random.choice([50, 60, 70, 80, 90, 100]))
|
||||
|
||||
# Pickup-related attributes
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ class ScheduledOrderFactory(ad_hoc.AdHocOrderFactory):
|
|||
and calculated backwards from `.scheduled_delivery_at`.
|
||||
"""
|
||||
|
||||
# Attributes regarding the specialization of an `Order`: ad-hoc or scheduled.
|
||||
# Attributes regarding the specialization of an `Order`: ad-hoc or scheduled
|
||||
placed_at = factory.LazyFunction(utils.early_in_the_morning)
|
||||
ad_hoc = False
|
||||
# Discrete `datetime` objects in the "core" lunch time are enough.
|
||||
# Discrete `datetime` objects in the "core" lunch time are enough
|
||||
scheduled_delivery_at = factory.LazyFunction(
|
||||
lambda: random.choice(
|
||||
[
|
||||
|
|
@ -38,7 +38,7 @@ class ScheduledOrderFactory(ad_hoc.AdHocOrderFactory):
|
|||
),
|
||||
)
|
||||
scheduled_delivery_at_corrected = False
|
||||
# Assume the `Order` is on time.
|
||||
# Assume the `Order` is on time
|
||||
first_estimated_delivery_at = factory.LazyAttribute(
|
||||
lambda obj: obj.scheduled_delivery_at,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from tests.db.fake_data import factories
|
|||
@pytest.fixture
|
||||
def make_address(city):
|
||||
"""Replaces `AddressFactory.build()`: Create an `Address` in the `city`."""
|
||||
# Reset the identifiers before every test.
|
||||
# Reset the identifiers before every test
|
||||
factories.AddressFactory.reset_sequence(1)
|
||||
|
||||
def func(**kwargs):
|
||||
|
|
@ -25,7 +25,7 @@ def make_address(city):
|
|||
@pytest.fixture
|
||||
def make_courier():
|
||||
"""Replaces `CourierFactory.build()`: Create a `Courier`."""
|
||||
# Reset the identifiers before every test.
|
||||
# Reset the identifiers before every test
|
||||
factories.CourierFactory.reset_sequence(1)
|
||||
|
||||
def func(**kwargs):
|
||||
|
|
@ -38,7 +38,7 @@ def make_courier():
|
|||
@pytest.fixture
|
||||
def make_customer():
|
||||
"""Replaces `CustomerFactory.build()`: Create a `Customer`."""
|
||||
# Reset the identifiers before every test.
|
||||
# Reset the identifiers before every test
|
||||
factories.CustomerFactory.reset_sequence(1)
|
||||
|
||||
def func(**kwargs):
|
||||
|
|
@ -51,7 +51,7 @@ def make_customer():
|
|||
@pytest.fixture
|
||||
def make_restaurant(make_address):
|
||||
"""Replaces `RestaurantFactory.build()`: Create a `Restaurant`."""
|
||||
# Reset the identifiers before every test.
|
||||
# Reset the identifiers before every test
|
||||
factories.RestaurantFactory.reset_sequence(1)
|
||||
|
||||
def func(address=None, **kwargs):
|
||||
|
|
@ -74,7 +74,7 @@ def make_restaurant(make_address):
|
|||
@pytest.fixture
|
||||
def make_order(make_address, make_courier, make_customer, make_restaurant):
|
||||
"""Replaces `OrderFactory.build()`: Create a `Order`."""
|
||||
# Reset the identifiers before every test.
|
||||
# Reset the identifiers before every test
|
||||
factories.AdHocOrderFactory.reset_sequence(1)
|
||||
|
||||
def func(*, scheduled=False, restaurant=None, courier=None, **kwargs):
|
||||
|
|
@ -119,7 +119,7 @@ def make_order(make_address, make_courier, make_customer, make_restaurant):
|
|||
@pytest.fixture
|
||||
def make_replay_order(make_order, simulation):
|
||||
"""Replaces `ReplayedOrderFactory.build()`: Create a `ReplayedOrder`."""
|
||||
# Reset the identifiers before every test.
|
||||
# Reset the identifiers before every test
|
||||
factories.ReplayedOrderFactory.reset_sequence(1)
|
||||
|
||||
def func(*, scheduled=False, order=None, **kwargs):
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class TestConstraints:
|
|||
db_session.add(replayed_order)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.ReplaySimulation).where(
|
||||
db.ReplaySimulation.id == replayed_order.simulation.id,
|
||||
)
|
||||
|
|
@ -65,7 +65,7 @@ class TestConstraints:
|
|||
db_session.add(replayed_order)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Order).where(db.Order.id == replayed_order.actual.id)
|
||||
|
||||
with pytest.raises(sa_exc.IntegrityError, match="fk_replayed_orders_to_orders"):
|
||||
|
|
@ -79,13 +79,13 @@ class TestConstraints:
|
|||
):
|
||||
"""Remove a record that is referenced with a FK."""
|
||||
# Need a second courier, one that is
|
||||
# not associated with the `.actual` order.
|
||||
# not associated with the `.actual` order
|
||||
replayed_order.courier = make_courier()
|
||||
|
||||
db_session.add(replayed_order)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Courier).where(db.Courier.id == replayed_order.courier.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
@ -304,12 +304,12 @@ class TestConstraints:
|
|||
|
||||
# Make the `scheduled_delivery_at` the quarter of an hour
|
||||
# following the next quarter of an hour (i.e., the timestamp
|
||||
# is between 15 and 30 minutes into the future).
|
||||
# is between 15 and 30 minutes into the future)
|
||||
replay_pre_order.ad_hoc = False
|
||||
replay_pre_order.actual.ad_hoc = False
|
||||
minutes_to_next_quarter = 15 - (replay_pre_order.placed_at.minute % 15)
|
||||
scheduled_delivery_at = (
|
||||
# `.placed_at` may have non-0 seconds.
|
||||
# `.placed_at` may have non-0 seconds
|
||||
replay_pre_order.placed_at.replace(second=0)
|
||||
+ dt.timedelta(minutes=(minutes_to_next_quarter + 15))
|
||||
)
|
||||
|
|
@ -398,11 +398,11 @@ class TestConstraints:
|
|||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
# Setting `.cancelled_at` to the end of a day
|
||||
# ensures the timestamps are logically ok.
|
||||
# ensures the timestamps are logically ok
|
||||
replayed_order.cancelled_at = dt.datetime(*test_config.DATE, 23)
|
||||
|
||||
# Set all timestamps after `.reached_pickup_at` to NULL
|
||||
# except the one under test.
|
||||
# except the one under test
|
||||
for unset_column in (
|
||||
"pickup_at",
|
||||
"left_pickup_at",
|
||||
|
|
@ -572,7 +572,7 @@ class TestConstraints:
|
|||
"""
|
||||
replayed_pre_order = make_replay_order(scheduled=True)
|
||||
# As we subtract 1 second in the generic case,
|
||||
# choose one second after a quarter of an hour.
|
||||
# choose one second after a quarter of an hour
|
||||
replayed_pre_order.placed_at = dt.datetime(*test_config.DATE, 11, 45, 1)
|
||||
self.test_timestamps_unordered(
|
||||
db_session,
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class TestConstraints:
|
|||
def test_delete_a_referenced_address(self, db_session, address, make_address):
|
||||
"""Remove a record that is referenced with a FK."""
|
||||
db_session.add(address)
|
||||
# Fake another_address that has the same `.primary_id` as `address`.
|
||||
# Fake another_address that has the same `.primary_id` as `address`
|
||||
db_session.add(make_address(primary_id=address.id))
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ class TestConstraints:
|
|||
db_session.add(address)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.City).where(db.City.id == address.city.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ def path(address, another_address, make_address):
|
|||
).meters
|
||||
|
||||
# We put 5 latitude-longitude pairs as the "path" from
|
||||
# `.first_address` to `.second_address`.
|
||||
# `.first_address` to `.second_address`
|
||||
directions = [
|
||||
[float(add.latitude), float(add.longitude)]
|
||||
for add in (make_address() for _ in range(5))
|
||||
|
|
@ -68,7 +68,7 @@ class TestConstraints:
|
|||
db_session.add(path)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Address).where(db.Address.id == path.first_address.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
@ -82,7 +82,7 @@ class TestConstraints:
|
|||
db_session.add(path)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Address).where(db.Address.id == path.second_address.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
@ -98,7 +98,7 @@ class TestConstraints:
|
|||
db_session.commit()
|
||||
|
||||
# Must insert without ORM as otherwise SQLAlchemy figures out
|
||||
# that something is wrong before any query is sent to the database.
|
||||
# that something is wrong before any query is sent to the database
|
||||
stmt = sa.insert(db.Path).values(
|
||||
first_address_id=address.id,
|
||||
second_address_id=another_address.id,
|
||||
|
|
@ -118,7 +118,7 @@ class TestConstraints:
|
|||
db_session.commit()
|
||||
|
||||
# Must insert without ORM as otherwise SQLAlchemy figures out
|
||||
# that something is wrong before any query is sent to the database.
|
||||
# that something is wrong before any query is sent to the database
|
||||
stmt = sa.insert(db.Path).values(
|
||||
first_address_id=path.first_address.id,
|
||||
second_address_id=path.second_address.id,
|
||||
|
|
@ -311,7 +311,7 @@ class TestFromAddresses:
|
|||
|
||||
assert result == 6
|
||||
|
||||
# Tests for the `Path.from_order()` convenience method.
|
||||
# Tests for the `Path.from_order()` convenience method
|
||||
|
||||
def test_make_path_instance_from_order(
|
||||
self,
|
||||
|
|
@ -385,7 +385,7 @@ class TestSyncWithGoogleMaps:
|
|||
{
|
||||
# We choose an artificially high distance of `9999`
|
||||
# so that the synced bicycle distance is longer than
|
||||
# the randomized air distance (i.e., fake data) for sure.
|
||||
# the randomized air distance (i.e., fake data) for sure
|
||||
"distance": {"text": "3.0 km", "value": 9999},
|
||||
"duration": {"text": "10 mins", "value": 596},
|
||||
"end_address": "13 Place Paul et Jean Paul Avisseau, ...",
|
||||
|
|
@ -685,7 +685,7 @@ class TestProperties:
|
|||
result = path.waypoints
|
||||
|
||||
# There are 5 inner points, excluding start and end,
|
||||
# i.e., the `.first_address` and `second_address`.
|
||||
# i.e., the `.first_address` and `second_address`
|
||||
assert len(result) == 5
|
||||
|
||||
def test_waypoints_is_cached(self, path):
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class TestConstraints:
|
|||
db_session.add(assoc)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Address).where(db.Address.id == assoc.address.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
@ -81,7 +81,7 @@ class TestConstraints:
|
|||
db_session.commit()
|
||||
|
||||
# Must insert without ORM as otherwise SQLAlchemy figures out
|
||||
# that something is wrong before any query is sent to the database.
|
||||
# that something is wrong before any query is sent to the database
|
||||
stmt = sa.insert(db.AddressPixelAssociation).values(
|
||||
address_id=address.id,
|
||||
city_id=999,
|
||||
|
|
@ -102,7 +102,7 @@ class TestConstraints:
|
|||
db_session.commit()
|
||||
|
||||
# Must insert without ORM as otherwise SQLAlchemy figures out
|
||||
# that something is wrong before any query is sent to the database.
|
||||
# that something is wrong before any query is sent to the database
|
||||
stmt = sa.insert(db.AddressPixelAssociation).values(
|
||||
address_id=address.id,
|
||||
city_id=address.city.id,
|
||||
|
|
@ -121,7 +121,7 @@ class TestConstraints:
|
|||
db_session.add(assoc)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Pixel).where(db.Pixel.id == assoc.pixel.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
@ -135,7 +135,7 @@ class TestConstraints:
|
|||
db_session.add(assoc)
|
||||
db_session.commit()
|
||||
|
||||
# Create a neighboring `Pixel` and put the same `address` as in `pixel` in it.
|
||||
# Create a neighboring `Pixel` and put the same `address` as in `pixel` in it
|
||||
neighbor = db.Pixel(grid=pixel.grid, n_x=pixel.n_x, n_y=pixel.n_y + 1)
|
||||
another_assoc = db.AddressPixelAssociation(address=address, pixel=neighbor)
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Pixel).where(db.Pixel.id == forecast.pixel.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
@ -376,7 +376,7 @@ class TestConstraints:
|
|||
assert forecast.low80 is not None
|
||||
assert forecast.high80 is not None
|
||||
|
||||
# Do not trigger the "ci95_must_be_wider_than_ci80" constraint.
|
||||
# Do not trigger the "ci95_must_be_wider_than_ci80" constraint
|
||||
forecast.low95 = None
|
||||
forecast.high95 = None
|
||||
|
||||
|
|
@ -398,7 +398,7 @@ class TestConstraints:
|
|||
assert forecast.low95 is not None
|
||||
assert forecast.high95 is not None
|
||||
|
||||
# Do not trigger the "ci95_must_be_wider_than_ci80" constraint.
|
||||
# Do not trigger the "ci95_must_be_wider_than_ci80" constraint
|
||||
forecast.low80 = None
|
||||
forecast.high80 = None
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class TestConstraints:
|
|||
db_session.add(grid)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.City).where(db.City.id == grid.city.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
@ -54,7 +54,7 @@ class TestConstraints:
|
|||
db_session.add(grid)
|
||||
db_session.commit()
|
||||
|
||||
# Create a `Grid` with the same `.side_length` in the same `.city`.
|
||||
# Create a `Grid` with the same `.side_length` in the same `.city`
|
||||
another_grid = db.Grid(city=grid.city, side_length=grid.side_length)
|
||||
db_session.add(another_grid)
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ class TestConstraints:
|
|||
db_session.add(grid)
|
||||
db_session.commit()
|
||||
|
||||
# Create a `Grid` with the same `.side_length` in another `.city`.
|
||||
# Create a `Grid` with the same `.side_length` in another `.city`
|
||||
another_city = db.City(**(city_data | {"id": 2, "name": "Lyon"}))
|
||||
another_grid = db.Grid(city=another_city, side_length=grid.side_length)
|
||||
db_session.add(another_grid)
|
||||
|
|
@ -132,7 +132,7 @@ class TestGridification:
|
|||
"""
|
||||
addresses_mock.return_value = [order.pickup_address]
|
||||
|
||||
# `+1` as otherwise there would be a second pixel in one direction.
|
||||
# `+1` as otherwise there would be a second pixel in one direction
|
||||
side_length = max(city.total_x, city.total_y) + 1
|
||||
|
||||
result = db.Grid.gridify(city=city, side_length=side_length)
|
||||
|
|
@ -152,7 +152,7 @@ class TestGridification:
|
|||
orders = [make_order(), make_order()]
|
||||
addresses_mock.return_value = [order.pickup_address for order in orders]
|
||||
|
||||
# `+1` as otherwise there would be a second pixel in one direction.
|
||||
# `+1` as otherwise there would be a second pixel in one direction
|
||||
side_length = max(city.total_x, city.total_y) + 1
|
||||
|
||||
result = db.Grid.gridify(city=city, side_length=side_length)
|
||||
|
|
@ -162,11 +162,11 @@ class TestGridification:
|
|||
|
||||
def test_no_pixel_with_one_address_too_far_south(self, city, order, addresses_mock):
|
||||
"""An `address` outside the `city`'s viewport is discarded."""
|
||||
# Move the `address` just below `city.southwest`.
|
||||
# Move the `address` just below `city.southwest`
|
||||
order.pickup_address.latitude = city.southwest.latitude - 0.1
|
||||
addresses_mock.return_value = [order.pickup_address]
|
||||
|
||||
# `+1` as otherwise there would be a second pixel in one direction.
|
||||
# `+1` as otherwise there would be a second pixel in one direction
|
||||
side_length = max(city.total_x, city.total_y) + 1
|
||||
|
||||
result = db.Grid.gridify(city=city, side_length=side_length)
|
||||
|
|
@ -181,11 +181,11 @@ class TestGridification:
|
|||
This test is a logical sibling to
|
||||
`test_no_pixel_with_one_address_too_far_south` and therefore redundant.
|
||||
"""
|
||||
# Move the `address` just left to `city.southwest`.
|
||||
# Move the `address` just left to `city.southwest`
|
||||
order.pickup_address.longitude = city.southwest.longitude - 0.1
|
||||
addresses_mock.return_value = [order.pickup_address]
|
||||
|
||||
# `+1` as otherwise there would be a second pixel in one direction.
|
||||
# `+1` as otherwise there would be a second pixel in one direction
|
||||
side_length = max(city.total_x, city.total_y) + 1
|
||||
|
||||
result = db.Grid.gridify(city=city, side_length=side_length)
|
||||
|
|
@ -199,7 +199,7 @@ class TestGridification:
|
|||
|
||||
This test is more of a sanity check.
|
||||
"""
|
||||
# Create two `Address` objects in distinct `Pixel`s.
|
||||
# Create two `Address` objects in distinct `Pixel`s
|
||||
addresses_mock.return_value = [
|
||||
# One `Address` in the lower-left `Pixel`, ...
|
||||
make_address(latitude=48.8357377, longitude=2.2517412),
|
||||
|
|
@ -209,12 +209,12 @@ class TestGridification:
|
|||
|
||||
side_length = max(city.total_x // 2, city.total_y // 2) + 1
|
||||
|
||||
# By assumption of the test data.
|
||||
# By assumption of the test data
|
||||
n_pixels_x = (city.total_x // side_length) + 1
|
||||
n_pixels_y = (city.total_y // side_length) + 1
|
||||
assert n_pixels_x * n_pixels_y == 4
|
||||
|
||||
# Create a `Grid` with at most four `Pixel`s.
|
||||
# Create a `Grid` with at most four `Pixel`s
|
||||
result = db.Grid.gridify(city=city, side_length=side_length)
|
||||
|
||||
assert isinstance(result, db.Grid)
|
||||
|
|
@ -252,7 +252,7 @@ class TestGridification:
|
|||
assert isinstance(result, db.Grid)
|
||||
assert 1 <= len(result.pixels) <= n_pixels_x * n_pixels_y
|
||||
|
||||
# Sanity checks for `Pixel.southwest` and `Pixel.northeast`.
|
||||
# Sanity checks for `Pixel.southwest` and `Pixel.northeast`
|
||||
for pixel in result.pixels:
|
||||
assert abs(pixel.southwest.x - pixel.n_x * side_length) < 2
|
||||
assert abs(pixel.southwest.y - pixel.n_y * side_length) < 2
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Customer).where(db.Customer.id == order.customer.id)
|
||||
|
||||
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_customers"):
|
||||
|
|
@ -68,7 +68,7 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Courier).where(db.Courier.id == order.courier.id)
|
||||
|
||||
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_couriers"):
|
||||
|
|
@ -79,7 +79,7 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Restaurant).where(db.Restaurant.id == order.restaurant.id)
|
||||
|
||||
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_restaurants"):
|
||||
|
|
@ -93,7 +93,7 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# Give the `restaurant` another `address`.
|
||||
# Give the `restaurant` another `address`
|
||||
order.restaurant.address = make_address()
|
||||
db_session.add(order.restaurant.address)
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Address).where(db.Address.id == order.delivery_address.id)
|
||||
|
||||
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_addresses"):
|
||||
|
|
@ -295,11 +295,11 @@ class TestConstraints:
|
|||
|
||||
# Make the `scheduled_delivery_at` the quarter of an hour
|
||||
# following the next quarter of an hour (i.e., the timestamp
|
||||
# is between 15 and 30 minutes into the future).
|
||||
# is between 15 and 30 minutes into the future)
|
||||
pre_order.ad_hoc = False
|
||||
minutes_to_next_quarter = 15 - (pre_order.placed_at.minute % 15)
|
||||
pre_order.scheduled_delivery_at = (
|
||||
# `.placed_at` may have non-0 seconds.
|
||||
# `.placed_at` may have non-0 seconds
|
||||
pre_order.placed_at.replace(second=0)
|
||||
+ dt.timedelta(minutes=(minutes_to_next_quarter + 15))
|
||||
)
|
||||
|
|
@ -434,22 +434,22 @@ class TestConstraints:
|
|||
There are two special cases for this test case below,
|
||||
where other attributes on `order` must be unset.
|
||||
"""
|
||||
# Set the actual timestamp to NULL.
|
||||
# Set the actual timestamp to NULL
|
||||
setattr(order, column, None)
|
||||
|
||||
# Setting both the timestamp and its correction column to NULL is allowed.
|
||||
# Setting both the timestamp and its correction column to NULL is allowed
|
||||
setattr(order, f"{column}_corrected", None)
|
||||
|
||||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# Also, an unset timestamp column may always be marked as corrected.
|
||||
# Also, an unset timestamp column may always be marked as corrected
|
||||
setattr(order, f"{column}_corrected", True)
|
||||
|
||||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# Without a timestamp set, a column may not be marked as uncorrected.
|
||||
# Without a timestamp set, a column may not be marked as uncorrected
|
||||
setattr(order, f"{column}_corrected", False)
|
||||
|
||||
db_session.add(order)
|
||||
|
|
@ -518,10 +518,10 @@ class TestConstraints:
|
|||
There are two special cases for this test case below,
|
||||
where other attributes on `order` must be unset.
|
||||
"""
|
||||
# Ensure the timestamp is set.
|
||||
# Ensure the timestamp is set
|
||||
assert getattr(order, column) is not None
|
||||
|
||||
# A set timestamp may be marked as either corrected or uncorrected.
|
||||
# A set timestamp may be marked as either corrected or uncorrected
|
||||
|
||||
setattr(order, f"{column}_corrected", True)
|
||||
|
||||
|
|
@ -533,7 +533,7 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
db_session.commit()
|
||||
|
||||
# A set timestamp may not be left unmarked.
|
||||
# A set timestamp may not be left unmarked
|
||||
setattr(order, f"{column}_corrected", None)
|
||||
|
||||
db_session.add(order)
|
||||
|
|
@ -659,7 +659,7 @@ class TestConstraints:
|
|||
This is one of two special cases. See the generic case above.
|
||||
"""
|
||||
# As we subtract 1 second in the generic case,
|
||||
# choose one second after a quarter of an hour.
|
||||
# choose one second after a quarter of an hour
|
||||
pre_order.placed_at = dt.datetime(*test_config.DATE, 11, 45, 1)
|
||||
self.test_timestamps_unordered(
|
||||
db_session,
|
||||
|
|
@ -752,7 +752,7 @@ class TestProperties:
|
|||
|
||||
def test_is_not_corrected(self, order):
|
||||
"""Test `Order.corrected` property."""
|
||||
# By default, the `OrderFactory` sets all `.*_corrected` attributes to `False`.
|
||||
# By default, the `OrderFactory` sets all `.*_corrected` attributes to `False`
|
||||
result = order.corrected
|
||||
|
||||
assert result is False
|
||||
|
|
@ -882,7 +882,7 @@ class TestProperties:
|
|||
|
||||
def test_courier_is_early_at_pickup(self, order):
|
||||
"""Test `Order.courier_early` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 999_999
|
||||
|
||||
result = order.courier_early
|
||||
|
|
@ -891,7 +891,7 @@ class TestProperties:
|
|||
|
||||
def test_courier_is_not_early_at_pickup(self, order):
|
||||
"""Test `Order.courier_early` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 1
|
||||
|
||||
result = order.courier_early
|
||||
|
|
@ -900,7 +900,7 @@ class TestProperties:
|
|||
|
||||
def test_courier_is_late_at_pickup(self, order):
|
||||
"""Test `Order.courier_late` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 1
|
||||
|
||||
result = order.courier_late
|
||||
|
|
@ -909,7 +909,7 @@ class TestProperties:
|
|||
|
||||
def test_courier_is_not_late_at_pickup(self, order):
|
||||
"""Test `Order.courier_late` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 999_999
|
||||
|
||||
result = order.courier_late
|
||||
|
|
@ -932,7 +932,7 @@ class TestProperties:
|
|||
|
||||
def test_restaurant_early_at_pickup(self, order):
|
||||
"""Test `Order.restaurant_early` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 999_999
|
||||
|
||||
result = order.restaurant_early
|
||||
|
|
@ -941,7 +941,7 @@ class TestProperties:
|
|||
|
||||
def test_restaurant_is_not_early_at_pickup(self, order):
|
||||
"""Test `Order.restaurant_early` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 1
|
||||
|
||||
result = order.restaurant_early
|
||||
|
|
@ -950,7 +950,7 @@ class TestProperties:
|
|||
|
||||
def test_restaurant_is_late_at_pickup(self, order):
|
||||
"""Test `Order.restaurant_late` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 1
|
||||
|
||||
result = order.restaurant_late
|
||||
|
|
@ -959,7 +959,7 @@ class TestProperties:
|
|||
|
||||
def test_restaurant_is_not_late_at_pickup(self, order):
|
||||
"""Test `Order.restaurant_late` property."""
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`.
|
||||
# Manipulate the attribute that determines `Order.scheduled_pickup_at`
|
||||
order.estimated_prep_duration = 999_999
|
||||
|
||||
result = order.restaurant_late
|
||||
|
|
@ -1038,14 +1038,14 @@ class TestProperties:
|
|||
|
||||
def test_ad_hoc_order_cannot_be_early(self, order):
|
||||
"""Test `Order.delivery_early` property."""
|
||||
# By default, the `OrderFactory` creates ad-hoc orders.
|
||||
# By default, the `OrderFactory` creates ad-hoc orders
|
||||
with pytest.raises(AttributeError, match="scheduled"):
|
||||
int(order.delivery_early)
|
||||
|
||||
def test_scheduled_order_delivered_early(self, make_order):
|
||||
"""Test `Order.delivery_early` property."""
|
||||
order = make_order(scheduled=True)
|
||||
# Schedule the order to a lot later.
|
||||
# Schedule the order to a lot later
|
||||
order.scheduled_delivery_at += dt.timedelta(hours=2)
|
||||
|
||||
result = order.delivery_early
|
||||
|
|
@ -1055,7 +1055,7 @@ class TestProperties:
|
|||
def test_scheduled_order_not_delivered_early(self, make_order):
|
||||
"""Test `Order.delivery_early` property."""
|
||||
order = make_order(scheduled=True)
|
||||
# Schedule the order to a lot earlier.
|
||||
# Schedule the order to a lot earlier
|
||||
order.scheduled_delivery_at -= dt.timedelta(hours=2)
|
||||
|
||||
result = order.delivery_early
|
||||
|
|
@ -1080,14 +1080,14 @@ class TestProperties:
|
|||
|
||||
def test_ad_hoc_order_cannot_be_late(self, order):
|
||||
"""Test Order.delivery_late property."""
|
||||
# By default, the `OrderFactory` creates ad-hoc orders.
|
||||
# By default, the `OrderFactory` creates ad-hoc orders
|
||||
with pytest.raises(AttributeError, match="scheduled"):
|
||||
int(order.delivery_late)
|
||||
|
||||
def test_scheduled_order_delivered_late(self, make_order):
|
||||
"""Test `Order.delivery_early` property."""
|
||||
order = make_order(scheduled=True)
|
||||
# Schedule the order to a lot earlier.
|
||||
# Schedule the order to a lot earlier
|
||||
order.scheduled_delivery_at -= dt.timedelta(hours=2)
|
||||
|
||||
result = order.delivery_late
|
||||
|
|
@ -1097,7 +1097,7 @@ class TestProperties:
|
|||
def test_scheduled_order_not_delivered_late(self, make_order):
|
||||
"""Test `Order.delivery_early` property."""
|
||||
order = make_order(scheduled=True)
|
||||
# Schedule the order to a lot later.
|
||||
# Schedule the order to a lot later
|
||||
order.scheduled_delivery_at += dt.timedelta(hours=2)
|
||||
|
||||
result = order.delivery_late
|
||||
|
|
@ -1162,23 +1162,23 @@ def test_make_random_orders(
|
|||
Ensure that all generated `Address`, `Courier`, `Customer`, `Restaurant`,
|
||||
and `Order` objects adhere to the database constraints.
|
||||
"""
|
||||
# Generate a large number of `Order`s to obtain a large variance of data.
|
||||
# Generate a large number of `Order`s to obtain a large variance of data
|
||||
for _ in range(1_000):
|
||||
# Ad-hoc `Order`s are far more common than pre-orders.
|
||||
# Ad-hoc `Order`s are far more common than pre-orders
|
||||
scheduled = random.choice([True, False, False, False, False])
|
||||
|
||||
# Randomly pass a `address` argument to `make_restaurant()` and
|
||||
# a `restaurant` argument to `make_order()`.
|
||||
# a `restaurant` argument to `make_order()`
|
||||
if random.random() < 0.5:
|
||||
address = random.choice([None, make_address()])
|
||||
restaurant = make_restaurant(address=address)
|
||||
else:
|
||||
restaurant = None
|
||||
|
||||
# Randomly pass a `courier` argument to `make_order()`.
|
||||
# Randomly pass a `courier` argument to `make_order()`
|
||||
courier = random.choice([None, make_courier()])
|
||||
|
||||
# A tiny fraction of `Order`s get cancelled.
|
||||
# A tiny fraction of `Order`s get cancelled
|
||||
if random.random() < 0.05:
|
||||
if random.random() < 0.5:
|
||||
cancel_before_pickup, cancel_after_pickup = True, False
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class TestConstraints:
|
|||
db_session.add(pixel)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Grid).where(db.Grid.id == pixel.grid.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class TestConstraints:
|
|||
db_session.add(restaurant)
|
||||
db_session.commit()
|
||||
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted.
|
||||
# Must delete without ORM as otherwise an UPDATE statement is emitted
|
||||
stmt = sa.delete(db.Address).where(db.Address.id == restaurant.address.id)
|
||||
|
||||
with pytest.raises(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import pytest
|
|||
from velofy.db import utils
|
||||
|
||||
|
||||
# All tests take place in Paris.
|
||||
# All tests take place in Paris
|
||||
MIN_EASTING, MAX_EASTING = 443_100, 461_200
|
||||
MIN_NORTHING, MAX_NORTHING = 5_407_200, 5_416_800
|
||||
ZONE = "31U"
|
||||
|
|
|
|||
Loading…
Reference in a new issue