Use double quotes

This commit is contained in:
Alexander Hess 2026-11-28 03:08:55 +01:00
commit ea8f1a13e3
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
35 changed files with 2464 additions and 2466 deletions

View file

@ -20,14 +20,14 @@ from velofy import db
# 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')
if not os.getenv("TESTING"):
raise RuntimeError("Tests must be executed with TESTING set in the environment")
if not config.TESTING:
raise RuntimeError('The testing configuration was not loaded')
raise RuntimeError("The testing configuration was not loaded")
@pytest.fixture(scope='session', params=['all_at_once', 'sequentially'])
@pytest.fixture(scope="session", params=["all_at_once", "sequentially"])
def db_connection(request):
"""Create all tables given the ORM models.
@ -53,13 +53,13 @@ def db_connection(request):
db.engine = engine
db.connection = connection
if request.param == 'all_at_once':
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 {config.CLEAN_SCHEMA};"))
db.Base.metadata.create_all(connection)
else:
cfg = migrations_config.Config('alembic.ini')
migrations_cmd.upgrade(cfg, 'head')
cfg = migrations_config.Config("alembic.ini")
migrations_cmd.upgrade(cfg, "head")
try:
yield connection
@ -70,13 +70,13 @@ 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 {config.CLEAN_SCHEMA} CASCADE;"))
if request.param == 'sequentially':
tmp_alembic_version = f'{config.ALEMBIC_TABLE}_{config.CLEAN_SCHEMA}'
if request.param == "sequentially":
tmp_alembic_version = f"{config.ALEMBIC_TABLE}_{config.CLEAN_SCHEMA}"
cleanup.execute(
sa.text(
f'DROP TABLE {config.ALEMBIC_TABLE_SCHEMA}.{tmp_alembic_version};', # noqa:E501
f"DROP TABLE {config.ALEMBIC_TABLE_SCHEMA}.{tmp_alembic_version};", # noqa:E501
),
)

View file

@ -44,7 +44,7 @@ def test_two_pixels_with_two_addresses(
side_length = max(city.total_x // 2, city.total_y // 2) + 1
# Hack the configuration regarding the grids to be created.
monkeypatch.setattr(velofy.config, 'GRID_SIDE_LENGTHS', [side_length])
monkeypatch.setattr(velofy.config, "GRID_SIDE_LENGTHS", [side_length])
result = cli.invoke(gridify.gridify)

View file

@ -25,35 +25,35 @@ class TestShowVersion:
def test_no_version(self, capsys, ctx):
"""Test the early exit branch without any output."""
main.show_version(ctx, _param='discarded', value=False)
main.show_version(ctx, _param="discarded", value=False)
captured = capsys.readouterr()
assert captured.out == ''
assert captured.out == ""
def test_final_version(self, capsys, ctx, monkeypatch):
"""For final versions, NO "development" warning is emitted."""
version = '1.2.3'
monkeypatch.setattr(main.velofy, '__version__', version)
version = "1.2.3"
monkeypatch.setattr(main.velofy, "__version__", version)
with pytest.raises(click.exceptions.Exit):
main.show_version(ctx, _param='discarded', value=True)
main.show_version(ctx, _param="discarded", value=True)
captured = capsys.readouterr()
assert captured.out.endswith(f', version {version}\n')
assert captured.out.endswith(f", version {version}\n")
def test_develop_version(self, capsys, ctx, monkeypatch):
"""For develop versions, a warning thereof is emitted."""
version = '1.2.3.dev0'
monkeypatch.setattr(main.velofy, '__version__', version)
version = "1.2.3.dev0"
monkeypatch.setattr(main.velofy, "__version__", version)
with pytest.raises(click.exceptions.Exit):
main.show_version(ctx, _param='discarded', value=True)
main.show_version(ctx, _param="discarded", value=True)
captured = capsys.readouterr()
assert captured.out.strip().endswith(f', version {version} (development)')
assert captured.out.strip().endswith(f", version {version} (development)")
class TestCLIWithoutCommand:
@ -72,28 +72,28 @@ class TestCLIWithoutCommand:
# The following test cases validate the --version / -V option.
version_options = ('--version', '-V')
version_options = ("--version", "-V")
@pytest.mark.no_cover
@pytest.mark.parametrize('option', version_options)
@pytest.mark.parametrize("option", version_options)
def test_final_version(self, cli, monkeypatch, option):
"""For final versions, NO "development" warning is emitted."""
version = '1.2.3'
monkeypatch.setattr(main.velofy, '__version__', version)
version = "1.2.3"
monkeypatch.setattr(main.velofy, "__version__", version)
result = cli.invoke(main.entry_point, option)
assert result.exit_code == 0
assert result.output.strip().endswith(f', version {version}')
assert result.output.strip().endswith(f", version {version}")
@pytest.mark.no_cover
@pytest.mark.parametrize('option', version_options)
@pytest.mark.parametrize("option", version_options)
def test_develop_version(self, cli, monkeypatch, option):
"""For develop versions, a warning thereof is emitted."""
version = '1.2.3.dev0'
monkeypatch.setattr(main.velofy, '__version__', version)
version = "1.2.3.dev0"
monkeypatch.setattr(main.velofy, "__version__", version)
result = cli.invoke(main.entry_point, option)
assert result.exit_code == 0
assert result.output.strip().endswith(f', version {version} (development)')
assert result.output.strip().endswith(f", version {version} (development)")

View file

@ -15,7 +15,7 @@ class AddressFactory(alchemy.SQLAlchemyModelFactory):
class Meta:
model = db.Address
sqlalchemy_get_or_create = ('id',)
sqlalchemy_get_or_create = ("id",)
id = factory.Sequence(lambda num: num)
created_at = factory.LazyFunction(utils.early_in_the_morning)
@ -28,13 +28,13 @@ class AddressFactory(alchemy.SQLAlchemyModelFactory):
# 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)),
lambda: "".join(random.choice(string.ascii_lowercase) for _ in range(20)),
)
# Place the addresses somewhere in downtown Paris.
latitude = factory.Faker('coordinate', center=48.855, radius=0.01)
longitude = factory.Faker('coordinate', center=2.34, radius=0.03)
latitude = factory.Faker("coordinate", center=48.855, radius=0.01)
longitude = factory.Faker("coordinate", center=2.34, radius=0.03)
# city -> set by the `make_address` fixture as there is only one `city`
city_name = 'Paris'
city_name = "Paris"
zip_code = factory.LazyFunction(lambda: random.randint(75001, 75020))
street = factory.Faker('street_address', locale='fr_FR')
street = factory.Faker("street_address", locale="fr_FR")

View file

@ -12,11 +12,11 @@ class CourierFactory(alchemy.SQLAlchemyModelFactory):
class Meta:
model = db.Courier
sqlalchemy_get_or_create = ('id',)
sqlalchemy_get_or_create = ("id",)
id = factory.Sequence(lambda num: num)
created_at = factory.LazyFunction(utils.early_in_the_morning)
vehicle = 'bicycle'
vehicle = "bicycle"
historic_speed = 7.89
capacity = 100
pay_per_hour = 750

View file

@ -11,6 +11,6 @@ class CustomerFactory(alchemy.SQLAlchemyModelFactory):
class Meta:
model = db.Customer
sqlalchemy_get_or_create = ('id',)
sqlalchemy_get_or_create = ("id",)
id = factory.Sequence(lambda num: num)

View file

@ -26,7 +26,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
class Meta:
model = db.Order
sqlalchemy_get_or_create = ('id',)
sqlalchemy_get_or_create = ("id",)
class Params:
"""Define flags that overwrite some attributes.

View file

@ -17,7 +17,7 @@ class ReplayedOrderFactory(alchemy.SQLAlchemyModelFactory):
class Meta:
model = db.ReplayedOrder
sqlalchemy_get_or_create = ('simulation_id', 'order_id')
sqlalchemy_get_or_create = ("simulation_id", "order_id")
# Generic columns
# simulation -> set by the `make_replay_order` fixture for better control

View file

@ -16,7 +16,7 @@ class RestaurantFactory(alchemy.SQLAlchemyModelFactory):
class Meta:
model = db.Restaurant
sqlalchemy_get_or_create = ('id',)
sqlalchemy_get_or_create = ("id",)
id = factory.Sequence(lambda num: num)
created_at = factory.LazyFunction(utils.early_in_the_morning)

View file

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

View file

@ -9,16 +9,16 @@ from velofy import db
def city_data():
"""The data for the one and only `City` object as a `dict`."""
return {
'id': 1,
'name': 'Paris',
'kml': "<?xml version='1.0' encoding='UTF-8'?> ...",
'center_latitude': 48.856614,
'center_longitude': 2.3522219,
'northeast_latitude': 48.9021449,
'northeast_longitude': 2.4699208,
'southwest_latitude': 48.815573,
'southwest_longitude': 2.225193,
'initial_zoom': 12,
"id": 1,
"name": "Paris",
"kml": "<?xml version='1.0' encoding='UTF-8'?> ...",
"center_latitude": 48.856614,
"center_longitude": 2.3522219,
"northeast_latitude": 48.9021449,
"northeast_longitude": 2.4699208,
"southwest_latitude": 48.815573,
"southwest_longitude": 2.225193,
"initial_zoom": 12,
}
@ -86,10 +86,10 @@ def pixel(grid):
def simulation_data(city):
"""The data for the one and only `ReplaySimulation` object as a `dict`."""
return {
'id': 1,
'city': city,
'strategy': 'best_possible_routing',
'run': 0,
"id": 1,
"city": city,
"strategy": "best_possible_routing",
"run": 0,
}

View file

@ -21,7 +21,7 @@ class TestSpecialMethods:
"""`ReplayedOrder` has a non-literal text representation."""
result = repr(replayed_order)
assert result == f'<ReplayedOrder(#{replayed_order.actual.id})>'
assert result == f"<ReplayedOrder(#{replayed_order.actual.id})>"
@pytest.mark.db
@ -50,7 +50,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_replayed_orders_to_replay_simulations',
match="fk_replayed_orders_to_replay_simulations",
):
db_session.execute(stmt)
@ -62,7 +62,7 @@ class TestConstraints:
# Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Order).where(db.Order.id == replayed_order.actual.id)
with pytest.raises(sa_exc.IntegrityError, match='fk_replayed_orders_to_orders'):
with pytest.raises(sa_exc.IntegrityError, match="fk_replayed_orders_to_orders"):
db_session.execute(stmt)
def test_delete_a_referenced_courier(
@ -84,7 +84,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_replayed_orders_to_couriers',
match="fk_replayed_orders_to_couriers",
):
db_session.execute(stmt)
@ -98,7 +98,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='either_ad_hoc_or_scheduled_order',
match="either_ad_hoc_or_scheduled_order",
):
db_session.commit()
@ -118,7 +118,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='either_ad_hoc_or_scheduled_order',
match="either_ad_hoc_or_scheduled_order",
):
db_session.commit()
@ -132,7 +132,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ad_hoc_orders_within_business_hours',
match="ad_hoc_orders_within_business_hours",
):
db_session.commit()
@ -146,7 +146,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ad_hoc_orders_within_business_hours',
match="ad_hoc_orders_within_business_hours",
):
db_session.commit()
@ -165,7 +165,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='scheduled_orders_within_business_hours',
match="scheduled_orders_within_business_hours",
):
db_session.commit()
@ -184,7 +184,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='scheduled_orders_within_business_hours',
match="scheduled_orders_within_business_hours",
):
db_session.commit()
@ -224,11 +224,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='scheduled_orders_within_business_hours',
match="scheduled_orders_within_business_hours",
):
db_session.commit()
@pytest.mark.parametrize('minute', [min_ for min_ in range(60) if min_ % 15 != 0])
@pytest.mark.parametrize("minute", [min_ for min_ in range(60) if min_ % 15 != 0])
def test_scheduled_order_at_non_quarter_of_an_hour(
self,
db_session,
@ -253,11 +253,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='scheduled_orders_must_be_at_quart', # constraint name too long
match="scheduled_orders_must_be_at_quart", # constraint name too long
):
db_session.commit()
@pytest.mark.parametrize('second', list(range(1, 60)))
@pytest.mark.parametrize("second", list(range(1, 60)))
def test_scheduled_order_at_non_quarter_of_an_hour_by_seconds(
self,
db_session,
@ -283,7 +283,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='scheduled_orders_must_be_at_quart', # constraint name too long
match="scheduled_orders_must_be_at_quart", # constraint name too long
):
db_session.commit()
@ -315,25 +315,25 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='scheduled_orders_not_within_30_minutes',
match="scheduled_orders_not_within_30_minutes",
):
db_session.commit()
@pytest.mark.parametrize(
'column',
"column",
[
'restaurant_notified_at',
'restaurant_confirmed_at',
'restaurant_ready_at',
'dispatch_at',
'courier', # not `.courier_id`
'courier_notified_at',
'courier_accepted_at',
'reached_pickup_at',
'pickup_at',
'left_pickup_at',
'reached_delivery_at',
'delivery_at',
"restaurant_notified_at",
"restaurant_confirmed_at",
"restaurant_ready_at",
"dispatch_at",
"courier", # not `.courier_id`
"courier_notified_at",
"courier_accepted_at",
"reached_pickup_at",
"pickup_at",
"left_pickup_at",
"reached_delivery_at",
"delivery_at",
],
)
def test_not_fully_simulated_order(self, db_session, replayed_order, column):
@ -346,21 +346,21 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='either_cancelled_o', # constraint name too long
match="either_cancelled_o", # constraint name too long
):
db_session.commit()
@pytest.mark.parametrize(
'column',
"column",
[
'restaurant_notified_at',
'restaurant_confirmed_at',
'restaurant_ready_at',
'dispatch_at',
'courier_id',
'courier_notified_at',
'courier_accepted_at',
'reached_pickup_at',
"restaurant_notified_at",
"restaurant_confirmed_at",
"restaurant_ready_at",
"dispatch_at",
"courier_id",
"courier_notified_at",
"courier_accepted_at",
"reached_pickup_at",
],
)
def test_simulated_cancellation(self, db_session, replayed_order, column):
@ -381,8 +381,8 @@ class TestConstraints:
db_session.commit()
@pytest.mark.parametrize(
'column',
['pickup_at', 'left_pickup_at', 'reached_delivery_at', 'delivery_at'],
"column",
["pickup_at", "left_pickup_at", "reached_delivery_at", "delivery_at"],
)
def test_no_simulated_cancellation_after_pickup(
self,
@ -398,10 +398,10 @@ class TestConstraints:
# Set all timestamps after `.reached_pickup_at` to NULL
# except the one under test.
for unset_column in (
'pickup_at',
'left_pickup_at',
'reached_delivery_at',
'delivery_at',
"pickup_at",
"left_pickup_at",
"reached_delivery_at",
"delivery_at",
):
if unset_column != column:
setattr(replayed_order, unset_column, None)
@ -410,11 +410,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='cancellations_may_only_occur_befo', # constraint name too long
match="cancellations_may_only_occur_befo", # constraint name too long
):
db_session.commit()
@pytest.mark.parametrize('duration', [-1, 3601])
@pytest.mark.parametrize("duration", [-1, 3601])
def test_estimated_prep_duration_out_of_range(
self,
db_session,
@ -427,11 +427,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='between_0', # constraint name too long
match="between_0", # constraint name too long
):
db_session.commit()
@pytest.mark.parametrize('duration', [1, 59, 119, 3599])
@pytest.mark.parametrize("duration", [1, 59, 119, 3599])
def test_estimated_prep_duration_not_whole_minute(
self,
db_session,
@ -444,11 +444,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='must_be_w', # constraint name too long
match="must_be_w", # constraint name too long
):
db_session.commit()
@pytest.mark.parametrize('utilization', [-1, 101])
@pytest.mark.parametrize("utilization", [-1, 101])
def test_utilization_out_of_range(self, db_session, replayed_order, utilization):
"""Insert an instance with invalid data."""
replayed_order.utilization = utilization
@ -456,12 +456,12 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='between_0_and_100',
match="between_0_and_100",
):
db_session.commit()
@pytest.mark.parametrize('column', ['restaurant_notified_at', 'dispatch_at'])
@pytest.mark.parametrize('hour', [0, 10])
@pytest.mark.parametrize("column", ["restaurant_notified_at", "dispatch_at"])
@pytest.mark.parametrize("hour", [0, 10])
def test_order_dispatched_in_non_business_hour(
self,
db_session,
@ -480,60 +480,60 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='business_hours',
match="business_hours",
):
db_session.commit()
@pytest.mark.parametrize(
'comparison',
"comparison",
[
'placed_at < restaurant_notified_at',
'placed_at < restaurant_confirmed_at',
'placed_at < restaurant_ready_at',
'placed_at < dispatch_at',
'placed_at < first_estimated_delivery_at',
'placed_at < courier_notified_at',
'placed_at < courier_accepted_at',
'placed_at < reached_pickup_at',
'placed_at < pickup_at',
'placed_at < left_pickup_at',
'placed_at < reached_delivery_at',
'placed_at < delivery_at',
'restaurant_notified_at < restaurant_confirmed_at',
'restaurant_notified_at < restaurant_ready_at',
'restaurant_notified_at < pickup_at',
'restaurant_confirmed_at < restaurant_ready_at',
'restaurant_confirmed_at < pickup_at',
'restaurant_ready_at < pickup_at',
'dispatch_at < first_estimated_delivery_at',
'dispatch_at < courier_notified_at',
'dispatch_at < courier_accepted_at',
'dispatch_at < reached_pickup_at',
'dispatch_at < pickup_at',
'dispatch_at < left_pickup_at',
'dispatch_at < reached_delivery_at',
'dispatch_at < delivery_at',
'courier_notified_at < courier_accepted_at',
'courier_notified_at < reached_pickup_at',
'courier_notified_at < pickup_at',
'courier_notified_at < left_pickup_at',
'courier_notified_at < reached_delivery_at',
'courier_notified_at < delivery_at',
'courier_accepted_at < reached_pickup_at',
'courier_accepted_at < pickup_at',
'courier_accepted_at < left_pickup_at',
'courier_accepted_at < reached_delivery_at',
'courier_accepted_at < delivery_at',
'reached_pickup_at < pickup_at',
'reached_pickup_at < left_pickup_at',
'reached_pickup_at < reached_delivery_at',
'reached_pickup_at < delivery_at',
'pickup_at < left_pickup_at',
'pickup_at < reached_delivery_at',
'pickup_at < delivery_at',
'left_pickup_at < reached_delivery_at',
'left_pickup_at < delivery_at',
'reached_delivery_at < delivery_at',
"placed_at < restaurant_notified_at",
"placed_at < restaurant_confirmed_at",
"placed_at < restaurant_ready_at",
"placed_at < dispatch_at",
"placed_at < first_estimated_delivery_at",
"placed_at < courier_notified_at",
"placed_at < courier_accepted_at",
"placed_at < reached_pickup_at",
"placed_at < pickup_at",
"placed_at < left_pickup_at",
"placed_at < reached_delivery_at",
"placed_at < delivery_at",
"restaurant_notified_at < restaurant_confirmed_at",
"restaurant_notified_at < restaurant_ready_at",
"restaurant_notified_at < pickup_at",
"restaurant_confirmed_at < restaurant_ready_at",
"restaurant_confirmed_at < pickup_at",
"restaurant_ready_at < pickup_at",
"dispatch_at < first_estimated_delivery_at",
"dispatch_at < courier_notified_at",
"dispatch_at < courier_accepted_at",
"dispatch_at < reached_pickup_at",
"dispatch_at < pickup_at",
"dispatch_at < left_pickup_at",
"dispatch_at < reached_delivery_at",
"dispatch_at < delivery_at",
"courier_notified_at < courier_accepted_at",
"courier_notified_at < reached_pickup_at",
"courier_notified_at < pickup_at",
"courier_notified_at < left_pickup_at",
"courier_notified_at < reached_delivery_at",
"courier_notified_at < delivery_at",
"courier_accepted_at < reached_pickup_at",
"courier_accepted_at < pickup_at",
"courier_accepted_at < left_pickup_at",
"courier_accepted_at < reached_delivery_at",
"courier_accepted_at < delivery_at",
"reached_pickup_at < pickup_at",
"reached_pickup_at < left_pickup_at",
"reached_pickup_at < reached_delivery_at",
"reached_pickup_at < delivery_at",
"pickup_at < left_pickup_at",
"pickup_at < reached_delivery_at",
"pickup_at < delivery_at",
"left_pickup_at < reached_delivery_at",
"left_pickup_at < delivery_at",
"reached_delivery_at < delivery_at",
],
)
def test_timestamps_unordered(
@ -547,7 +547,7 @@ class TestConstraints:
There are two special cases for this test case below,
where other attributes on `replayed_order` must be unset.
"""
smaller, bigger = comparison.split(' < ')
smaller, bigger = comparison.split(" < ")
assert smaller is not None
@ -556,7 +556,7 @@ class TestConstraints:
db_session.add(replayed_order)
with pytest.raises(sa_exc.IntegrityError, match='ordered_timestamps'):
with pytest.raises(sa_exc.IntegrityError, match="ordered_timestamps"):
db_session.commit()
def test_timestamps_unordered_scheduled(self, db_session, make_replay_order):
@ -571,20 +571,20 @@ class TestConstraints:
self.test_timestamps_unordered(
db_session,
replayed_pre_order,
'placed_at < scheduled_delivery_at',
"placed_at < scheduled_delivery_at",
)
@pytest.mark.parametrize(
'comparison',
"comparison",
[
'placed_at < cancelled_at',
'restaurant_notified_at < cancelled_at',
'restaurant_confirmed_at < cancelled_at',
'restaurant_ready_at < cancelled_at',
'dispatch_at < cancelled_at',
'courier_notified_at < cancelled_at',
'courier_accepted_at < cancelled_at',
'reached_pickup_at < cancelled_at',
"placed_at < cancelled_at",
"restaurant_notified_at < cancelled_at",
"restaurant_confirmed_at < cancelled_at",
"restaurant_ready_at < cancelled_at",
"dispatch_at < cancelled_at",
"courier_notified_at < cancelled_at",
"courier_accepted_at < cancelled_at",
"reached_pickup_at < cancelled_at",
],
)
def test_timestamps_unordered_cancelled(

View file

@ -12,6 +12,6 @@ class TestSpecialMethods:
"""`ReplaySimulation` has a non-literal text representation."""
result = repr(simulation)
assert result.startswith('<ReplaySimulation(')
assert result.startswith("<ReplaySimulation(")
assert simulation.city.name in result
assert simulation.strategy in result

View file

@ -19,7 +19,7 @@ class TestSpecialMethods:
"""`Address` has a non-literal text representation."""
result = repr(address)
assert result == f'<Address({address.street} in {address.city_name})>'
assert result == f"<Address({address.street} in {address.city_name})>"
@pytest.mark.db
@ -47,7 +47,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_to_addresses_via_primary_id',
match="fk_addresses_to_addresses_via_primary_id",
):
db_session.commit()
@ -61,11 +61,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_to_cities_via_city_id',
match="fk_addresses_to_cities_via_city_id",
):
db_session.execute(stmt)
@pytest.mark.parametrize('latitude', [-91, 91])
@pytest.mark.parametrize("latitude", [-91, 91])
def test_invalid_latitude(self, db_session, address, latitude):
"""Insert an instance with invalid data."""
address.latitude = latitude
@ -73,11 +73,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='latitude_between_90_degrees',
match="latitude_between_90_degrees",
):
db_session.commit()
@pytest.mark.parametrize('longitude', [-181, 181])
@pytest.mark.parametrize("longitude", [-181, 181])
def test_invalid_longitude(self, db_session, address, longitude):
"""Insert an instance with invalid data."""
address.longitude = longitude
@ -85,26 +85,26 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='longitude_between_180_degrees',
match="longitude_between_180_degrees",
):
db_session.commit()
@pytest.mark.parametrize('zip_code', [-1, 0, 9999, 100000])
@pytest.mark.parametrize("zip_code", [-1, 0, 9999, 100000])
def test_invalid_zip_code(self, db_session, address, zip_code):
"""Insert an instance with invalid data."""
address.zip_code = zip_code
db_session.add(address)
with pytest.raises(sa_exc.IntegrityError, match='valid_zip_code'):
with pytest.raises(sa_exc.IntegrityError, match="valid_zip_code"):
db_session.commit()
@pytest.mark.parametrize('floor', [-1, 41])
@pytest.mark.parametrize("floor", [-1, 41])
def test_invalid_floor(self, db_session, address, floor):
"""Insert an instance with invalid data."""
address.floor = floor
db_session.add(address)
with pytest.raises(sa_exc.IntegrityError, match='realistic_floor'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_floor"):
db_session.commit()

View file

@ -77,7 +77,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_addresses_to_addresses_via_first_address', # shortened
match="fk_addresses_addresses_to_addresses_via_first_address", # shortened
):
db_session.execute(stmt)
@ -91,7 +91,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_addresses_to_addresses_via_second_address', # shortened
match="fk_addresses_addresses_to_addresses_via_second_address", # shortened
):
db_session.execute(stmt)
@ -112,7 +112,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_addresses_to_addresses_via_first_address', # shortened
match="fk_addresses_addresses_to_addresses_via_first_address", # shortened
):
db_session.execute(stmt)
@ -130,7 +130,7 @@ class TestConstraints:
air_distance=path.air_distance,
)
with pytest.raises(sa_exc.IntegrityError, match='duplicate key value'):
with pytest.raises(sa_exc.IntegrityError, match="duplicate key value"):
db_session.execute(stmt)
def test_symmetric_addresses(self, db_session, path):
@ -147,7 +147,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ck_addresses_addresses_on_distances_are_symmetric_for_bicycles',
match="ck_addresses_addresses_on_distances_are_symmetric_for_bicycles",
):
db_session.commit()
@ -156,7 +156,7 @@ class TestConstraints:
path.air_distance = -1
db_session.add(path)
with pytest.raises(sa_exc.IntegrityError, match='realistic_air_distance'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_air_distance"):
db_session.commit()
def test_air_distance_too_large(self, db_session, path):
@ -165,7 +165,7 @@ class TestConstraints:
path.bicycle_distance = 21_000
db_session.add(path)
with pytest.raises(sa_exc.IntegrityError, match='realistic_air_distance'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_air_distance"):
db_session.commit()
def test_bicycle_distance_too_large(self, db_session, path):
@ -173,7 +173,7 @@ class TestConstraints:
path.bicycle_distance = 25_000
db_session.add(path)
with pytest.raises(sa_exc.IntegrityError, match='realistic_bicycle_distance'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_bicycle_distance"):
db_session.commit()
def test_air_distance_shorter_than_bicycle_distance(self, db_session, path):
@ -181,10 +181,10 @@ class TestConstraints:
path.bicycle_distance = round(0.75 * path.air_distance)
db_session.add(path)
with pytest.raises(sa_exc.IntegrityError, match='air_distance_is_shortest'):
with pytest.raises(sa_exc.IntegrityError, match="air_distance_is_shortest"):
db_session.commit()
@pytest.mark.parametrize('duration', [-1, 3601])
@pytest.mark.parametrize("duration", [-1, 3601])
def test_unrealistic_bicycle_travel_time(self, db_session, path, duration):
"""Insert an instance with invalid data."""
path.bicycle_duration = duration
@ -192,7 +192,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='realistic_bicycle_travel_time',
match="realistic_bicycle_travel_time",
):
db_session.commit()
@ -214,7 +214,7 @@ class TestFromAddresses:
"""
db_session.add(address)
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_make_path_instance(
self,
db_session,
@ -228,7 +228,7 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_make_the_same_path_instance_twice(
self,
db_session,
@ -246,14 +246,14 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_structure_of_return_value(self, db_session, address, another_address):
"""Test instantiation of a new `Path` instance."""
results = db.Path.from_addresses(address, another_address)
assert isinstance(results, list)
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_instances_must_have_air_distance(
self,
db_session,
@ -267,7 +267,7 @@ class TestFromAddresses:
assert result.air_distance is not None
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_do_not_sync_instances_with_google_maps(
self,
db_session,
@ -282,7 +282,7 @@ class TestFromAddresses:
assert result.bicycle_distance is None
assert result.bicycle_duration is None
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_sync_instances_with_google_maps(
self,
db_session,
@ -296,7 +296,7 @@ class TestFromAddresses:
self.bicycle_distance = 1.25 * self.air_distance
self.bicycle_duration = 300
monkeypatch.setattr(db.Path, 'sync_with_google_maps', sync)
monkeypatch.setattr(db.Path, "sync_with_google_maps", sync)
paths = db.Path.from_addresses(address, another_address, google_maps=True)
@ -305,21 +305,21 @@ class TestFromAddresses:
assert result.bicycle_distance is not None
assert result.bicycle_duration is not None
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_one_path_for_two_addresses(self, db_session, address, another_address):
"""Test instantiation of a new `Path` instance."""
result = len(db.Path.from_addresses(address, another_address))
assert result == 1
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_two_paths_for_three_addresses(self, db_session, make_address):
"""Test instantiation of a new `Path` instance."""
result = len(db.Path.from_addresses(*[make_address() for _ in range(3)]))
assert result == 3
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_six_paths_for_four_addresses(self, db_session, make_address):
"""Test instantiation of a new `Path` instance."""
result = len(db.Path.from_addresses(*[make_address() for _ in range(4)]))
@ -328,7 +328,7 @@ class TestFromAddresses:
# Tests for the `Path.from_order()` convenience method.
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_make_path_instance_from_order(
self,
db_session,
@ -341,7 +341,7 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_make_the_same_path_instance_from_order_twice(
self,
db_session,
@ -358,14 +358,14 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_structure_of_return_value_from_order(self, db_session, order):
"""Test instantiation of a new `Path` instance."""
result = db.Path.from_order(order)
assert isinstance(result, db.Path)
@pytest.mark.usefixtures('_prepare_db')
@pytest.mark.usefixtures("_prepare_db")
def test_sync_instance_from_order_with_google_maps(
self,
db_session,
@ -378,7 +378,7 @@ class TestFromAddresses:
self.bicycle_distance = 1.25 * self.air_distance
self.bicycle_duration = 300
monkeypatch.setattr(db.Path, 'sync_with_google_maps', sync)
monkeypatch.setattr(db.Path, "sync_with_google_maps", sync)
result = db.Path.from_order(order, google_maps=True)
@ -395,251 +395,251 @@ class TestSyncWithGoogleMaps:
"""A typical (shortened) response by the Google Maps Directions API."""
return [
{
'bounds': {
'northeast': {'lat': 44.8554284, 'lng': -0.5652398},
'southwest': {'lat': 44.8342256, 'lng': -0.5708206},
"bounds": {
"northeast": {"lat": 44.8554284, "lng": -0.5652398},
"southwest": {"lat": 44.8342256, "lng": -0.5708206},
},
'copyrights': 'Map data ©2021',
'legs': [
"copyrights": "Map data ©2021",
"legs": [
{
# 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.
'distance': {'text': '3.0 km', 'value': 9999},
'duration': {'text': '10 mins', 'value': 596},
'end_address': '13 Place Paul et Jean Paul Avisseau, ...',
'end_location': {'lat': 44.85540839999999, 'lng': -0.5672105},
'start_address': '59 Rue Saint-François, 33000 Bordeaux, ...',
'start_location': {'lat': 44.8342256, 'lng': -0.570372},
'steps': [
"distance": {"text": "3.0 km", "value": 9999},
"duration": {"text": "10 mins", "value": 596},
"end_address": "13 Place Paul et Jean Paul Avisseau, ...",
"end_location": {"lat": 44.85540839999999, "lng": -0.5672105},
"start_address": "59 Rue Saint-François, 33000 Bordeaux, ...",
"start_location": {"lat": 44.8342256, "lng": -0.570372},
"steps": [
{
'distance': {'text': '0.1 km', 'value': 138},
'duration': {'text': '1 min', 'value': 43},
'end_location': {
'lat': 44.83434380000001,
'lng': -0.5690105999999999,
"distance": {"text": "0.1 km", "value": 138},
"duration": {"text": "1 min", "value": 43},
"end_location": {
"lat": 44.83434380000001,
"lng": -0.5690105999999999,
},
'html_instructions': 'Head <b>east</b> on <b> ...',
'polyline': {'points': '}tspGxknBKcDIkB'},
'start_location': {'lat': 44.8342256, 'lng': -0.57032},
'travel_mode': 'BICYCLING',
"html_instructions": "Head <b>east</b> on <b> ...",
"polyline": {"points": "}tspGxknBKcDIkB"},
"start_location": {"lat": 44.8342256, "lng": -0.57032},
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.1 km', 'value': 115},
'duration': {'text': '1 min', 'value': 22},
'end_location': {'lat': 44.8353651, 'lng': -0.569199},
'html_instructions': 'Turn <b>left</b> onto <b> ...',
'maneuver': 'turn-left',
'polyline': {'points': 'suspGhcnBc@JE@_@DiAHA?w@F'},
'start_location': {
'lat': 44.83434380000001,
'lng': -0.5690105999999999,
"distance": {"text": "0.1 km", "value": 115},
"duration": {"text": "1 min", "value": 22},
"end_location": {"lat": 44.8353651, "lng": -0.569199},
"html_instructions": "Turn <b>left</b> onto <b> ...",
"maneuver": "turn-left",
"polyline": {"points": "suspGhcnBc@JE@_@DiAHA?w@F"},
"start_location": {
"lat": 44.83434380000001,
"lng": -0.5690105999999999,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.3 km', 'value': 268},
'duration': {'text': '1 min', 'value': 59},
'end_location': {'lat': 44.8362675, 'lng': -0.5660914},
'html_instructions': 'Turn <b>right</b> onto <b> ...',
'maneuver': 'turn-right',
'polyline': {
'points': 'a|spGndnBEYEQKi@Mi@Is@CYCOE]CQIq@ ...',
"distance": {"text": "0.3 km", "value": 268},
"duration": {"text": "1 min", "value": 59},
"end_location": {"lat": 44.8362675, "lng": -0.5660914},
"html_instructions": "Turn <b>right</b> onto <b> ...",
"maneuver": "turn-right",
"polyline": {
"points": "a|spGndnBEYEQKi@Mi@Is@CYCOE]CQIq@ ...",
},
'start_location': {'lat': 44.8353651, 'lng': -0.56919},
'travel_mode': 'BICYCLING',
"start_location": {"lat": 44.8353651, "lng": -0.56919},
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.1 km', 'value': 95},
'duration': {'text': '1 min', 'value': 29},
'end_location': {'lat': 44.8368458, 'lng': -0.5652398},
'html_instructions': 'Slight <b>left</b> onto <b> ...',
'maneuver': 'turn-slight-left',
'polyline': {
'points': 'uatpG`qmBg@aAGM?ACE[k@CICGACEGCCAAEAG?',
"distance": {"text": "0.1 km", "value": 95},
"duration": {"text": "1 min", "value": 29},
"end_location": {"lat": 44.8368458, "lng": -0.5652398},
"html_instructions": "Slight <b>left</b> onto <b> ...",
"maneuver": "turn-slight-left",
"polyline": {
"points": "uatpG`qmBg@aAGM?ACE[k@CICGACEGCCAAEAG?",
},
'start_location': {
'lat': 44.8362675,
'lng': -0.5660914,
"start_location": {
"lat": 44.8362675,
"lng": -0.5660914,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '23 m', 'value': 23},
'duration': {'text': '1 min', 'value': 4},
'end_location': {'lat': 44.83697, 'lng': -0.5654425},
'html_instructions': 'Slight <b>left</b> to stay ...',
'maneuver': 'turn-slight-left',
'polyline': {
'points': 'ietpGvkmBA@C?CBCBEHA@AB?B?B?B?@',
"distance": {"text": "23 m", "value": 23},
"duration": {"text": "1 min", "value": 4},
"end_location": {"lat": 44.83697, "lng": -0.5654425},
"html_instructions": "Slight <b>left</b> to stay ...",
"maneuver": "turn-slight-left",
"polyline": {
"points": "ietpGvkmBA@C?CBCBEHA@AB?B?B?B?@",
},
'start_location': {
'lat': 44.8368458,
'lng': -0.5652398,
"start_location": {
"lat": 44.8368458,
"lng": -0.5652398,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.2 km', 'value': 185},
'duration': {'text': '1 min', 'value': 23},
'end_location': {'lat': 44.8382126, 'lng': -0.5669969},
'html_instructions': 'Take the ramp to <b>Le Lac ...',
'polyline': {
'points': 'aftpG~lmBY^[^sAdB]`@CDKLQRa@h@A@IZ',
"distance": {"text": "0.2 km", "value": 185},
"duration": {"text": "1 min", "value": 23},
"end_location": {"lat": 44.8382126, "lng": -0.5669969},
"html_instructions": "Take the ramp to <b>Le Lac ...",
"polyline": {
"points": "aftpG~lmBY^[^sAdB]`@CDKLQRa@h@A@IZ",
},
'start_location': {'lat': 44.83697, 'lng': -0.5654425},
'travel_mode': 'BICYCLING',
"start_location": {"lat": 44.83697, "lng": -0.5654425},
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.3 km', 'value': 253},
'duration': {'text': '1 min', 'value': 43},
'end_location': {'lat': 44.840163, 'lng': -0.5686525},
'html_instructions': 'Merge onto <b>Quai Richelieu</b>',
'maneuver': 'merge',
'polyline': {
'points': 'ymtpGvvmBeAbAe@b@_@ZUN[To@f@e@^A?g ...',
"distance": {"text": "0.3 km", "value": 253},
"duration": {"text": "1 min", "value": 43},
"end_location": {"lat": 44.840163, "lng": -0.5686525},
"html_instructions": "Merge onto <b>Quai Richelieu</b>",
"maneuver": "merge",
"polyline": {
"points": "ymtpGvvmBeAbAe@b@_@ZUN[To@f@e@^A?g ...",
},
'start_location': {
'lat': 44.8382126,
'lng': -0.5669969,
"start_location": {
"lat": 44.8382126,
"lng": -0.5669969,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.1 km', 'value': 110},
'duration': {'text': '1 min', 'value': 21},
'end_location': {'lat': 44.841079, 'lng': -0.5691835},
'html_instructions': 'Continue onto <b>Quai de la ...',
'polyline': {'points': '_ztpG`anBUNQLULUJOHMFKDWN'},
'start_location': {'lat': 44.840163, 'lng': -0.56865},
'travel_mode': 'BICYCLING',
"distance": {"text": "0.1 km", "value": 110},
"duration": {"text": "1 min", "value": 21},
"end_location": {"lat": 44.841079, "lng": -0.5691835},
"html_instructions": "Continue onto <b>Quai de la ...",
"polyline": {"points": "_ztpG`anBUNQLULUJOHMFKDWN"},
"start_location": {"lat": 44.840163, "lng": -0.56865},
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.3 km', 'value': 262},
'duration': {'text': '1 min', 'value': 44},
'end_location': {'lat': 44.8433375, 'lng': -0.5701161},
'html_instructions': 'Continue onto <b>Quai du ...',
'polyline': {
'points': 'w_upGjdnBeBl@sBn@gA^[JIBc@Nk@Nk@L',
"distance": {"text": "0.3 km", "value": 262},
"duration": {"text": "1 min", "value": 44},
"end_location": {"lat": 44.8433375, "lng": -0.5701161},
"html_instructions": "Continue onto <b>Quai du ...",
"polyline": {
"points": "w_upGjdnBeBl@sBn@gA^[JIBc@Nk@Nk@L",
},
'start_location': {'lat': 44.841079, 'lng': -0.56915},
'travel_mode': 'BICYCLING',
"start_location": {"lat": 44.841079, "lng": -0.56915},
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.6 km', 'value': 550},
'duration': {'text': '2 mins', 'value': 97},
'end_location': {
'lat': 44.84822339999999,
'lng': -0.5705307,
"distance": {"text": "0.6 km", "value": 550},
"duration": {"text": "2 mins", "value": 97},
"end_location": {
"lat": 44.84822339999999,
"lng": -0.5705307,
},
'html_instructions': 'Continue onto <b>Quai ...',
'polyline': {
'points': '{mupGfjnBYFI@IBaAPUD{AX}@NK@]Fe@H ...',
"html_instructions": "Continue onto <b>Quai ...",
"polyline": {
"points": "{mupGfjnBYFI@IBaAPUD{AX}@NK@]Fe@H ...",
},
'start_location': {
'lat': 44.8433375,
'lng': -0.5701161,
"start_location": {
"lat": 44.8433375,
"lng": -0.5701161,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.5 km', 'value': 508},
'duration': {'text': '1 min', 'value': 87},
'end_location': {'lat': 44.8523224, 'lng': -0.5678223},
'html_instructions': 'Continue onto ...',
'polyline': {
'points': 'klvpGxlnBWEUGWGSGMEOEOE[KMEQGIA] ...',
"distance": {"text": "0.5 km", "value": 508},
"duration": {"text": "1 min", "value": 87},
"end_location": {"lat": 44.8523224, "lng": -0.5678223},
"html_instructions": "Continue onto ...",
"polyline": {
"points": "klvpGxlnBWEUGWGSGMEOEOE[KMEQGIA] ...",
},
'start_location': {
'lat': 44.84822339999999,
'lng': -0.5705307,
"start_location": {
"lat": 44.84822339999999,
"lng": -0.5705307,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '28 m', 'value': 28},
'duration': {'text': '1 min', 'value': 45},
'end_location': {
'lat': 44.85245620000001,
'lng': -0.5681259,
"distance": {"text": "28 m", "value": 28},
"duration": {"text": "1 min", "value": 45},
"end_location": {
"lat": 44.85245620000001,
"lng": -0.5681259,
},
'html_instructions': 'Turn <b>left</b> onto <b> ...',
'maneuver': 'turn-left',
'polyline': {'points': '_fwpGz{mBGLADGPCFEN'},
'start_location': {
'lat': 44.8523224,
'lng': -0.5678223,
"html_instructions": "Turn <b>left</b> onto <b> ...",
"maneuver": "turn-left",
"polyline": {"points": "_fwpGz{mBGLADGPCFEN"},
"start_location": {
"lat": 44.8523224,
"lng": -0.5678223,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.2 km', 'value': 176},
'duration': {'text': '1 min', 'value': 31},
'end_location': {'lat': 44.8536857, 'lng': -0.5667282},
'html_instructions': 'Turn <b>right</b> onto <b> ...',
'maneuver': 'turn-right',
'polyline': {
'points': '{fwpGx}mB_@c@mAuAOQi@m@m@y@_@c@',
"distance": {"text": "0.2 km", "value": 176},
"duration": {"text": "1 min", "value": 31},
"end_location": {"lat": 44.8536857, "lng": -0.5667282},
"html_instructions": "Turn <b>right</b> onto <b> ...",
"maneuver": "turn-right",
"polyline": {
"points": "{fwpGx}mB_@c@mAuAOQi@m@m@y@_@c@",
},
'start_location': {
'lat': 44.85245620000001,
'lng': -0.5681259,
"start_location": {
"lat": 44.85245620000001,
"lng": -0.5681259,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.2 km', 'value': 172},
'duration': {'text': '1 min', 'value': 28},
'end_location': {'lat': 44.8547766, 'lng': -0.5682825},
'html_instructions': 'Turn <b>left</b> onto <b> ... ',
'maneuver': 'turn-left',
'polyline': {'points': 'qnwpG`umBW`@UkDtF'},
'start_location': {
'lat': 44.8536857,
'lng': -0.5667282,
"distance": {"text": "0.2 km", "value": 172},
"duration": {"text": "1 min", "value": 28},
"end_location": {"lat": 44.8547766, "lng": -0.5682825},
"html_instructions": "Turn <b>left</b> onto <b> ... ",
"maneuver": "turn-left",
"polyline": {"points": "qnwpG`umBW`@UkDtF"},
"start_location": {
"lat": 44.8536857,
"lng": -0.5667282,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '0.1 km', 'value': 101},
'duration': {'text': '1 min', 'value': 17},
'end_location': {'lat': 44.8554284, 'lng': -0.5673822},
'html_instructions': 'Turn <b>right</b> onto ...',
'maneuver': 'turn-right',
'polyline': {'points': 'kuwpGv~mBa@q@cA_B[a@'},
'start_location': {
'lat': 44.8547766,
'lng': -0.5682825,
"distance": {"text": "0.1 km", "value": 101},
"duration": {"text": "1 min", "value": 17},
"end_location": {"lat": 44.8554284, "lng": -0.5673822},
"html_instructions": "Turn <b>right</b> onto ...",
"maneuver": "turn-right",
"polyline": {"points": "kuwpGv~mBa@q@cA_B[a@"},
"start_location": {
"lat": 44.8547766,
"lng": -0.5682825,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
{
'distance': {'text': '15 m', 'value': 15},
'duration': {'text': '1 min', 'value': 3},
'end_location': {
'lat': 44.85540839999999,
'lng': -0.5672105,
"distance": {"text": "15 m", "value": 15},
"duration": {"text": "1 min", "value": 3},
"end_location": {
"lat": 44.85540839999999,
"lng": -0.5672105,
},
'html_instructions': 'Turn <b>right</b> onto <b> ...',
'maneuver': 'turn-right',
'polyline': {'points': 'mywpGbymBBC@C?E?C?E?EAC'},
'start_location': {
'lat': 44.8554284,
'lng': -0.5673822,
"html_instructions": "Turn <b>right</b> onto <b> ...",
"maneuver": "turn-right",
"polyline": {"points": "mywpGbymBBC@C?E?C?E?EAC"},
"start_location": {
"lat": 44.8554284,
"lng": -0.5673822,
},
'travel_mode': 'BICYCLING',
"travel_mode": "BICYCLING",
},
],
'traffic_speed_entry': [],
'via_waypoint': [],
"traffic_speed_entry": [],
"via_waypoint": [],
},
],
'overview_polyline': {
'points': '}tspGxknBUoGi@LcDVe@_CW{Ba@sC[eA_@} ...',
"overview_polyline": {
"points": "}tspGxknBUoGi@LcDVe@_CW{Ba@sC[eA_@} ...",
},
'summary': 'Quai des Chartrons',
'warnings': ['Bicycling directions are in beta ...'],
'waypoint_order': [],
"summary": "Quai des Chartrons",
"warnings": ["Bicycling directions are in beta ..."],
"waypoint_order": [],
},
]
@ -650,9 +650,9 @@ class TestSyncWithGoogleMaps:
def directions(_self, *_args, **_kwargs):
return api_response
monkeypatch.setattr(googlemaps.Client, 'directions', directions)
monkeypatch.setattr(googlemaps.Client, "directions", directions)
@pytest.mark.usefixtures('_fake_google_api')
@pytest.mark.usefixtures("_fake_google_api")
def test_sync_instances_with_google_maps(self, db_session, path):
"""Call the method for a `Path` object without Google data."""
path.bicycle_distance = None
@ -665,7 +665,7 @@ class TestSyncWithGoogleMaps:
assert path.bicycle_duration == 596
assert path._directions is not None
@pytest.mark.usefixtures('_fake_google_api')
@pytest.mark.usefixtures("_fake_google_api")
def test_repeated_sync_instances_with_google_maps(self, db_session, path):
"""Call the method for a `Path` object with Google data.

View file

@ -60,7 +60,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_pixels_to_addresses_via_address_id_city_id',
match="fk_addresses_pixels_to_addresses_via_address_id_city_id",
):
db_session.execute(stmt)
@ -81,7 +81,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_pixels_to_addresses_via_address_id_city_id',
match="fk_addresses_pixels_to_addresses_via_address_id_city_id",
):
db_session.execute(stmt)
@ -102,7 +102,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_pixels_to_grids_via_grid_id_city_id',
match="fk_addresses_pixels_to_grids_via_grid_id_city_id",
):
db_session.execute(stmt)
@ -116,7 +116,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_addresses_pixels_to_pixels_via_pixel_id_grid_id',
match="fk_addresses_pixels_to_pixels_via_pixel_id_grid_id",
):
db_session.execute(stmt)
@ -131,5 +131,5 @@ class TestConstraints:
db_session.add(another_assoc)
with pytest.raises(sa_exc.IntegrityError, match='duplicate key value'):
with pytest.raises(sa_exc.IntegrityError, match="duplicate key value"):
db_session.commit()

View file

@ -17,7 +17,7 @@ class TestSpecialMethods:
"""`City` has a non-literal text representation."""
result = repr(city)
assert result == f'<City({city.name})>'
assert result == f"<City({city.name})>"
@pytest.mark.db
@ -43,8 +43,8 @@ class TestProperties:
result = city.center
assert isinstance(result, utils.Location)
assert result.latitude == pytest.approx(city_data['center_latitude'])
assert result.longitude == pytest.approx(city_data['center_longitude'])
assert result.latitude == pytest.approx(city_data["center_latitude"])
assert result.longitude == pytest.approx(city_data["center_longitude"])
def test_center_is_cached(self, city):
"""Test `City.center` property."""
@ -58,8 +58,8 @@ class TestProperties:
result = city.northeast
assert isinstance(result, utils.Location)
assert result.latitude == pytest.approx(city_data['northeast_latitude'])
assert result.longitude == pytest.approx(city_data['northeast_longitude'])
assert result.latitude == pytest.approx(city_data["northeast_latitude"])
assert result.longitude == pytest.approx(city_data["northeast_longitude"])
def test_northeast_is_cached(self, city):
"""Test `City.northeast` property."""
@ -73,8 +73,8 @@ class TestProperties:
result = city.southwest
assert isinstance(result, utils.Location)
assert result.latitude == pytest.approx(city_data['southwest_latitude'])
assert result.longitude == pytest.approx(city_data['southwest_longitude'])
assert result.latitude == pytest.approx(city_data["southwest_latitude"])
assert result.longitude == pytest.approx(city_data["southwest_longitude"])
def test_southwest_is_cached(self, city):
"""Test `City.southwest` property."""

View file

@ -17,7 +17,7 @@ class TestSpecialMethods:
"""`Courier` has a non-literal text representation."""
result = repr(courier)
assert result == f'<Courier(#{courier.id})>'
assert result == f"<Courier(#{courier.id})>"
@pytest.mark.db
@ -36,10 +36,10 @@ class TestConstraints:
def test_invalid_vehicle(self, db_session, courier):
"""Insert an instance with invalid data."""
courier.vehicle = 'invalid'
courier.vehicle = "invalid"
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='available_vehicle_types'):
with pytest.raises(sa_exc.IntegrityError, match="available_vehicle_types"):
db_session.commit()
def test_negative_speed(self, db_session, courier):
@ -47,7 +47,7 @@ class TestConstraints:
courier.historic_speed = -1
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='realistic_speed'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_speed"):
db_session.commit()
def test_unrealistic_speed(self, db_session, courier):
@ -55,7 +55,7 @@ class TestConstraints:
courier.historic_speed = 999
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='realistic_speed'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_speed"):
db_session.commit()
def test_negative_capacity(self, db_session, courier):
@ -63,7 +63,7 @@ class TestConstraints:
courier.capacity = -1
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='capacity_under_200_liters'):
with pytest.raises(sa_exc.IntegrityError, match="capacity_under_200_liters"):
db_session.commit()
def test_too_much_capacity(self, db_session, courier):
@ -71,7 +71,7 @@ class TestConstraints:
courier.capacity = 999
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='capacity_under_200_liters'):
with pytest.raises(sa_exc.IntegrityError, match="capacity_under_200_liters"):
db_session.commit()
def test_negative_pay_per_hour(self, db_session, courier):
@ -79,7 +79,7 @@ class TestConstraints:
courier.pay_per_hour = -1
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='realistic_pay_per_hour'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_pay_per_hour"):
db_session.commit()
def test_too_much_pay_per_hour(self, db_session, courier):
@ -87,7 +87,7 @@ class TestConstraints:
courier.pay_per_hour = 9999
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='realistic_pay_per_hour'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_pay_per_hour"):
db_session.commit()
def test_negative_pay_per_order(self, db_session, courier):
@ -95,7 +95,7 @@ class TestConstraints:
courier.pay_per_order = -1
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='realistic_pay_per_order'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_pay_per_order"):
db_session.commit()
def test_too_much_pay_per_order(self, db_session, courier):
@ -103,5 +103,5 @@ class TestConstraints:
courier.pay_per_order = 999
db_session.add(courier)
with pytest.raises(sa_exc.IntegrityError, match='realistic_pay_per_order'):
with pytest.raises(sa_exc.IntegrityError, match="realistic_pay_per_order"):
db_session.commit()

View file

@ -16,7 +16,7 @@ class TestSpecialMethods:
"""`Customer` has a non-literal text representation."""
result = repr(customer)
assert result == f'<Customer(#{customer.id})>'
assert result == f"<Customer(#{customer.id})>"
@pytest.mark.db

View file

@ -11,7 +11,7 @@ from tests import config as test_config
from velofy import db
MODEL = 'hets'
MODEL = "hets"
@pytest.fixture
@ -52,7 +52,7 @@ class TestSpecialMethods:
assert (
result
== f'<Forecast: {forecast.prediction} for pixel ({forecast.pixel.n_x}|{forecast.pixel.n_y}) at {forecast.start_at}>' # noqa:E501
== f"<Forecast: {forecast.prediction} for pixel ({forecast.pixel.n_x}|{forecast.pixel.n_y}) at {forecast.start_at}>" # noqa:E501
)
@ -80,11 +80,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='fk_forecasts_to_pixels_via_pixel_id',
match="fk_forecasts_to_pixels_via_pixel_id",
):
db_session.execute(stmt)
@pytest.mark.parametrize('hour', [10, 23])
@pytest.mark.parametrize("hour", [10, 23])
def test_invalid_start_at_outside_operating_hours(
self,
db_session,
@ -102,7 +102,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='within_operating_hours',
match="within_operating_hours",
):
db_session.commit()
@ -113,7 +113,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='must_be_quarters_of_the_hour',
match="must_be_quarters_of_the_hour",
):
db_session.commit()
@ -124,7 +124,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='no_seconds',
match="no_seconds",
):
db_session.commit()
@ -135,11 +135,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='no_microseconds',
match="no_microseconds",
):
db_session.commit()
@pytest.mark.parametrize('value', [-1, 0])
@pytest.mark.parametrize("value", [-1, 0])
def test_positive_time_step(self, db_session, forecast, value):
"""Insert an instance with invalid data."""
forecast.time_step = value
@ -147,11 +147,11 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='time_step_must_be_positive',
match="time_step_must_be_positive",
):
db_session.commit()
@pytest.mark.parametrize('value', [-1, 0])
@pytest.mark.parametrize("value", [-1, 0])
def test_positive_train_horizon(self, db_session, forecast, value):
"""Insert an instance with invalid data."""
forecast.train_horizon = value
@ -159,7 +159,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='training_horizon_must_be_positive',
match="training_horizon_must_be_positive",
):
db_session.commit()
@ -170,7 +170,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='actuals_must_be_non_negative',
match="actuals_must_be_non_negative",
):
db_session.commit()
@ -196,7 +196,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci_upper_and_lower_bounds',
match="ci_upper_and_lower_bounds",
):
db_session.commit()
@ -209,7 +209,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci_upper_and_lower_bounds',
match="ci_upper_and_lower_bounds",
):
db_session.commit()
@ -222,7 +222,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci_upper_and_lower_bounds',
match="ci_upper_and_lower_bounds",
):
db_session.commit()
@ -235,7 +235,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci_upper_and_lower_bounds',
match="ci_upper_and_lower_bounds",
):
db_session.commit()
@ -249,7 +249,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -267,7 +267,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -281,7 +281,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -299,7 +299,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -313,7 +313,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -331,7 +331,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -345,7 +345,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -363,7 +363,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='prediction_must_be_within_ci',
match="prediction_must_be_within_ci",
):
db_session.commit()
@ -385,7 +385,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci_upper_bound_greater_than_lower_bound',
match="ci_upper_bound_greater_than_lower_bound",
):
db_session.commit()
@ -407,7 +407,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci_upper_bound_greater_than_lower_bound',
match="ci_upper_bound_greater_than_lower_bound",
):
db_session.commit()
@ -422,7 +422,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci95_must_be_wider_than_ci80',
match="ci95_must_be_wider_than_ci80",
):
db_session.commit()
@ -440,7 +440,7 @@ class TestConstraints:
with pytest.raises(
sa_exc.IntegrityError,
match='ci95_must_be_wider_than_ci80',
match="ci95_must_be_wider_than_ci80",
):
db_session.commit()
@ -464,7 +464,7 @@ class TestConstraints:
)
db_session.add(another_forecast)
with pytest.raises(sa_exc.IntegrityError, match='duplicate key value'):
with pytest.raises(sa_exc.IntegrityError, match="duplicate key value"):
db_session.commit()
@ -495,16 +495,16 @@ class TestFromDataFrameConstructor:
noon_start_at + dt.timedelta(minutes=test_config.LONG_TIME_STEP),
],
)
index.name = 'start_at'
index.name = "start_at"
return pd.DataFrame(
data={
'actual': (11, 12, 13),
'prediction': (11.3, 12.3, 13.3),
'low80': (1.123, 1.23, 1.323),
'high80': (112.34, 123.4, 132.34),
'low95': (0.1123, 0.123, 0.1323),
'high95': (1123.45, 1234.5, 1323.45),
"actual": (11, 12, 13),
"prediction": (11.3, 12.3, 13.3),
"low80": (1.123, 1.23, 1.323),
"high80": (112.34, 123.4, 132.34),
"low95": (0.1123, 0.123, 0.1323),
"high95": (1123.45, 1234.5, 1323.45),
},
index=index,
)

Some files were not shown because too many files have changed in this diff Show more