Upgrade black
This commit is contained in:
parent
fad875b332
commit
dbdce83067
21 changed files with 1208 additions and 914 deletions
|
|
@ -9,7 +9,13 @@ from velofy.console import gridify
|
|||
|
||||
@pytest.mark.db
|
||||
def test_two_pixels_with_two_addresses( # noqa:WPS211
|
||||
cli, db_session, monkeypatch, city, make_address, make_restaurant, make_order,
|
||||
cli,
|
||||
db_session,
|
||||
monkeypatch,
|
||||
city,
|
||||
make_address,
|
||||
make_restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""Two `Address` objects in distinct `Pixel` objects.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
"""Factory to create `Courier` instances."""
|
||||
|
||||
|
||||
import factory
|
||||
from factory import alchemy
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
|
|||
# Timestamps after `cancelled_at` are discarded
|
||||
# by the `post_generation` hook at the end of the `OrderFactory`.
|
||||
cancel_ = factory.Trait( # noqa:WPS120 -> leading underscore does not work
|
||||
cancelled=True, cancelled_at_corrected=False,
|
||||
cancelled=True,
|
||||
cancelled_at_corrected=False,
|
||||
)
|
||||
cancel_before_pickup = factory.Trait(
|
||||
cancel_=True,
|
||||
|
|
|
|||
|
|
@ -137,7 +137,10 @@ def make_replay_order(make_order, simulation):
|
|||
order = make_order()
|
||||
|
||||
return factories.ReplayedOrderFactory.build(
|
||||
simulation=simulation, actual=order, courier=order.courier, **kwargs,
|
||||
simulation=simulation,
|
||||
actual=order,
|
||||
courier=order.courier,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
return func
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ class TestConstraints:
|
|||
)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_replayed_orders_to_replay_simulations',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_replayed_orders_to_replay_simulations',
|
||||
):
|
||||
db_session.execute(stmt)
|
||||
|
||||
|
|
@ -65,7 +66,10 @@ class TestConstraints:
|
|||
db_session.execute(stmt)
|
||||
|
||||
def test_delete_a_referenced_courier(
|
||||
self, db_session, replayed_order, make_courier,
|
||||
self,
|
||||
db_session,
|
||||
replayed_order,
|
||||
make_courier,
|
||||
):
|
||||
"""Remove a record that is referenced with a FK."""
|
||||
# Need a second courier, one that is
|
||||
|
|
@ -79,7 +83,8 @@ class TestConstraints:
|
|||
stmt = sqla.delete(db.Courier).where(db.Courier.id == replayed_order.courier.id)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_replayed_orders_to_couriers',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_replayed_orders_to_couriers',
|
||||
):
|
||||
db_session.execute(stmt)
|
||||
|
||||
|
|
@ -92,12 +97,15 @@ class TestConstraints:
|
|||
db_session.add(replayed_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='either_ad_hoc_or_scheduled_order',
|
||||
sa_exc.IntegrityError,
|
||||
match='either_ad_hoc_or_scheduled_order',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_scheduled_order_without_scheduled_delivery_at(
|
||||
self, db_session, make_replay_order,
|
||||
self,
|
||||
db_session,
|
||||
make_replay_order,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
replay_order = make_replay_order(scheduled=True)
|
||||
|
|
@ -109,7 +117,8 @@ class TestConstraints:
|
|||
db_session.add(replay_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='either_ad_hoc_or_scheduled_order',
|
||||
sa_exc.IntegrityError,
|
||||
match='either_ad_hoc_or_scheduled_order',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -122,7 +131,8 @@ class TestConstraints:
|
|||
db_session.add(replay_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ad_hoc_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='ad_hoc_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -135,7 +145,8 @@ class TestConstraints:
|
|||
db_session.add(replay_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ad_hoc_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='ad_hoc_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -153,7 +164,8 @@ class TestConstraints:
|
|||
db_session.add(replay_pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -171,7 +183,8 @@ class TestConstraints:
|
|||
db_session.add(replay_pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -210,17 +223,23 @@ class TestConstraints:
|
|||
db_session.add(replay_pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
@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, make_replay_order, minute,
|
||||
self,
|
||||
db_session,
|
||||
make_replay_order,
|
||||
minute,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
scheduled_delivery_at = dt.datetime( # `minute` is not 0, 15, 30, or 45
|
||||
*test_config.DATE, test_config.NOON, minute,
|
||||
*test_config.DATE,
|
||||
test_config.NOON,
|
||||
minute,
|
||||
)
|
||||
replay_pre_order = make_replay_order(
|
||||
scheduled=True,
|
||||
|
|
@ -240,11 +259,17 @@ class TestConstraints:
|
|||
|
||||
@pytest.mark.parametrize('second', list(range(1, 60)))
|
||||
def test_scheduled_order_at_non_quarter_of_an_hour_by_seconds(
|
||||
self, db_session, make_replay_order, second,
|
||||
self,
|
||||
db_session,
|
||||
make_replay_order,
|
||||
second,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
scheduled_delivery_at = dt.datetime(
|
||||
*test_config.DATE, test_config.NOON, 0, second,
|
||||
*test_config.DATE,
|
||||
test_config.NOON,
|
||||
0,
|
||||
second,
|
||||
)
|
||||
replay_pre_order = make_replay_order(
|
||||
scheduled=True,
|
||||
|
|
@ -289,7 +314,8 @@ class TestConstraints:
|
|||
db_session.add(replay_pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_not_within_30_minutes',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_not_within_30_minutes',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -355,10 +381,14 @@ 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, db_session, replayed_order, column,
|
||||
self,
|
||||
db_session,
|
||||
replayed_order,
|
||||
column,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
# Setting `.cancelled_at` to the end of a day
|
||||
|
|
@ -386,27 +416,35 @@ class TestConstraints:
|
|||
|
||||
@pytest.mark.parametrize('duration', [-1, 3601])
|
||||
def test_estimated_prep_duration_out_of_range(
|
||||
self, db_session, replayed_order, duration,
|
||||
self,
|
||||
db_session,
|
||||
replayed_order,
|
||||
duration,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
replayed_order.estimated_prep_duration = duration
|
||||
db_session.add(replayed_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='between_0', # constraint name too long
|
||||
sa_exc.IntegrityError,
|
||||
match='between_0', # constraint name too long
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
@pytest.mark.parametrize('duration', [1, 59, 119, 3599])
|
||||
def test_estimated_prep_duration_not_whole_minute(
|
||||
self, db_session, replayed_order, duration,
|
||||
self,
|
||||
db_session,
|
||||
replayed_order,
|
||||
duration,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
replayed_order.estimated_prep_duration = duration
|
||||
db_session.add(replayed_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='must_be_w', # constraint name too long
|
||||
sa_exc.IntegrityError,
|
||||
match='must_be_w', # constraint name too long
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -417,14 +455,19 @@ class TestConstraints:
|
|||
db_session.add(replayed_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='between_0_and_100',
|
||||
sa_exc.IntegrityError,
|
||||
match='between_0_and_100',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
@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, replayed_order, column, hour,
|
||||
self,
|
||||
db_session,
|
||||
replayed_order,
|
||||
column,
|
||||
hour,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
orig_timestamp = getattr(replayed_order, column)
|
||||
|
|
@ -436,7 +479,8 @@ class TestConstraints:
|
|||
db_session.add(replayed_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -493,7 +537,10 @@ class TestConstraints:
|
|||
],
|
||||
)
|
||||
def test_timestamps_unordered(
|
||||
self, db_session, replayed_order, comparison,
|
||||
self,
|
||||
db_session,
|
||||
replayed_order,
|
||||
comparison,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -522,7 +569,9 @@ class TestConstraints:
|
|||
# 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, replayed_pre_order, 'placed_at < scheduled_delivery_at',
|
||||
db_session,
|
||||
replayed_pre_order,
|
||||
'placed_at < scheduled_delivery_at',
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -539,7 +588,10 @@ class TestConstraints:
|
|||
],
|
||||
)
|
||||
def test_timestamps_unordered_cancelled(
|
||||
self, db_session, replayed_order, comparison,
|
||||
self,
|
||||
db_session,
|
||||
replayed_order,
|
||||
comparison,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ class TestConstraints:
|
|||
db_session.delete(address)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_addresses_to_addresses_via_primary_id',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_addresses_to_addresses_via_primary_id',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -59,7 +60,8 @@ class TestConstraints:
|
|||
stmt = sqla.delete(db.City).where(db.City.id == address.city.id)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_addresses_to_cities_via_city_id',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_addresses_to_cities_via_city_id',
|
||||
):
|
||||
db_session.execute(stmt)
|
||||
|
||||
|
|
@ -70,7 +72,8 @@ class TestConstraints:
|
|||
db_session.add(address)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='latitude_between_90_degrees',
|
||||
sa_exc.IntegrityError,
|
||||
match='latitude_between_90_degrees',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -81,7 +84,8 @@ class TestConstraints:
|
|||
db_session.add(address)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='longitude_between_180_degrees',
|
||||
sa_exc.IntegrityError,
|
||||
match='longitude_between_180_degrees',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ def another_address(make_address):
|
|||
def path(address, another_address, make_address):
|
||||
"""A `Path` from `address` to `another_address`."""
|
||||
air_distance = distance.great_circle( # noqa:WPS317
|
||||
address.location.lat_lng, another_address.location.lat_lng,
|
||||
address.location.lat_lng,
|
||||
another_address.location.lat_lng,
|
||||
).meters
|
||||
|
||||
# We put 5 latitude-longitude pairs as the "path" from
|
||||
|
|
@ -190,7 +191,8 @@ class TestConstraints:
|
|||
db_session.add(path)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='realistic_bicycle_travel_time',
|
||||
sa_exc.IntegrityError,
|
||||
match='realistic_bicycle_travel_time',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -214,7 +216,10 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_make_path_instance(
|
||||
self, db_session, address, another_address,
|
||||
self,
|
||||
db_session,
|
||||
address,
|
||||
another_address,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
assert db_session.query(db.Path).count() == 0
|
||||
|
|
@ -225,7 +230,10 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_make_the_same_path_instance_twice(
|
||||
self, db_session, address, another_address,
|
||||
self,
|
||||
db_session,
|
||||
address,
|
||||
another_address,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
assert db_session.query(db.Path).count() == 0
|
||||
|
|
@ -247,7 +255,10 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_instances_must_have_air_distance(
|
||||
self, db_session, address, another_address,
|
||||
self,
|
||||
db_session,
|
||||
address,
|
||||
another_address,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
paths = db.Path.from_addresses(address, another_address)
|
||||
|
|
@ -258,7 +269,10 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_do_not_sync_instances_with_google_maps(
|
||||
self, db_session, address, another_address,
|
||||
self,
|
||||
db_session,
|
||||
address,
|
||||
another_address,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
paths = db.Path.from_addresses(address, another_address)
|
||||
|
|
@ -270,7 +284,11 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_sync_instances_with_google_maps(
|
||||
self, db_session, address, another_address, monkeypatch,
|
||||
self,
|
||||
db_session,
|
||||
address,
|
||||
another_address,
|
||||
monkeypatch,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
|
||||
|
|
@ -312,7 +330,9 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_make_path_instance_from_order(
|
||||
self, db_session, order,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
assert db_session.query(db.Path).count() == 0
|
||||
|
|
@ -323,7 +343,9 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_make_the_same_path_instance_from_order_twice(
|
||||
self, db_session, order,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
assert db_session.query(db.Path).count() == 0
|
||||
|
|
@ -345,7 +367,10 @@ class TestFromAddresses:
|
|||
|
||||
@pytest.mark.usefixtures('_prepare_db')
|
||||
def test_sync_instance_from_order_with_google_maps(
|
||||
self, db_session, order, monkeypatch,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
monkeypatch,
|
||||
):
|
||||
"""Test instantiation of a new `Path` instance."""
|
||||
|
||||
|
|
|
|||
|
|
@ -79,13 +79,17 @@ class TestConstraints:
|
|||
stmt = sqla.delete(db.Pixel).where(db.Pixel.id == forecast.pixel.id)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_forecasts_to_pixels_via_pixel_id',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_forecasts_to_pixels_via_pixel_id',
|
||||
):
|
||||
db_session.execute(stmt)
|
||||
|
||||
@pytest.mark.parametrize('hour', [10, 23])
|
||||
def test_invalid_start_at_outside_operating_hours(
|
||||
self, db_session, forecast, hour,
|
||||
self,
|
||||
db_session,
|
||||
forecast,
|
||||
hour,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
forecast.start_at = dt.datetime(
|
||||
|
|
@ -97,7 +101,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='within_operating_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='within_operating_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -107,7 +112,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='must_be_quarters_of_the_hour',
|
||||
sa_exc.IntegrityError,
|
||||
match='must_be_quarters_of_the_hour',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -117,7 +123,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='no_seconds',
|
||||
sa_exc.IntegrityError,
|
||||
match='no_seconds',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -127,7 +134,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='no_microseconds',
|
||||
sa_exc.IntegrityError,
|
||||
match='no_microseconds',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -138,7 +146,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='time_step_must_be_positive',
|
||||
sa_exc.IntegrityError,
|
||||
match='time_step_must_be_positive',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -149,7 +158,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='training_horizon_must_be_positive',
|
||||
sa_exc.IntegrityError,
|
||||
match='training_horizon_must_be_positive',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -159,7 +169,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='actuals_must_be_non_negative',
|
||||
sa_exc.IntegrityError,
|
||||
match='actuals_must_be_non_negative',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -184,7 +195,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci_upper_and_lower_bounds',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci_upper_and_lower_bounds',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -196,7 +208,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci_upper_and_lower_bounds',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci_upper_and_lower_bounds',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -208,7 +221,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci_upper_and_lower_bounds',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci_upper_and_lower_bounds',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -220,7 +234,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci_upper_and_lower_bounds',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci_upper_and_lower_bounds',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -233,12 +248,15 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_prediction_smaller_than_low80_without_ci95_set(
|
||||
self, db_session, forecast,
|
||||
self,
|
||||
db_session,
|
||||
forecast,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
forecast.low95 = None
|
||||
|
|
@ -248,7 +266,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -261,12 +280,15 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_prediction_smaller_than_low95_without_ci80_set(
|
||||
self, db_session, forecast,
|
||||
self,
|
||||
db_session,
|
||||
forecast,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
forecast.low80 = None
|
||||
|
|
@ -276,7 +298,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -289,12 +312,15 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_prediction_greater_than_high80_without_ci95_set(
|
||||
self, db_session, forecast,
|
||||
self,
|
||||
db_session,
|
||||
forecast,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
forecast.low95 = None
|
||||
|
|
@ -304,7 +330,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -317,12 +344,15 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_prediction_greater_than_high95_without_ci80_set(
|
||||
self, db_session, forecast,
|
||||
self,
|
||||
db_session,
|
||||
forecast,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
forecast.low80 = None
|
||||
|
|
@ -332,7 +362,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='prediction_must_be_within_ci',
|
||||
sa_exc.IntegrityError,
|
||||
match='prediction_must_be_within_ci',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -353,7 +384,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci_upper_bound_greater_than_lower_bound',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci_upper_bound_greater_than_lower_bound',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -374,7 +406,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci_upper_bound_greater_than_lower_bound',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci_upper_bound_greater_than_lower_bound',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -388,7 +421,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci95_must_be_wider_than_ci80',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci95_must_be_wider_than_ci80',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -405,7 +439,8 @@ class TestConstraints:
|
|||
db_session.add(forecast)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ci95_must_be_wider_than_ci80',
|
||||
sa_exc.IntegrityError,
|
||||
match='ci95_must_be_wider_than_ci80',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -490,7 +525,10 @@ class TestFromDataFrameConstructor:
|
|||
|
||||
@pytest.mark.db
|
||||
def test_persist_predictions_into_database(
|
||||
self, db_session, pixel, prediction_data,
|
||||
self,
|
||||
db_session,
|
||||
pixel,
|
||||
prediction_data,
|
||||
):
|
||||
"""Call `Forecast.from_dataframe()` and persist the results."""
|
||||
forecasts = db.Forecast.from_dataframe(
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ class TestConstraints:
|
|||
stmt = sqla.delete(db.City).where(db.City.id == grid.city.id)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_grids_to_cities_via_city_id',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_grids_to_cities_via_city_id',
|
||||
):
|
||||
db_session.execute(stmt)
|
||||
|
||||
|
|
@ -206,7 +207,13 @@ class TestGridification:
|
|||
@pytest.mark.no_cover
|
||||
@pytest.mark.parametrize('side_length', [250, 500, 1_000, 2_000, 4_000, 8_000])
|
||||
def test_make_random_grids( # noqa:WPS211,WPS218
|
||||
self, db_session, city, make_address, make_restaurant, make_order, side_length,
|
||||
self,
|
||||
db_session,
|
||||
city,
|
||||
make_address,
|
||||
make_restaurant,
|
||||
make_order,
|
||||
side_length,
|
||||
):
|
||||
"""With 100 random `Address` objects, a grid must have ...
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,8 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='either_ad_hoc_or_scheduled_order',
|
||||
sa_exc.IntegrityError,
|
||||
match='either_ad_hoc_or_scheduled_order',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -141,7 +142,8 @@ class TestConstraints:
|
|||
db_session.add(pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='either_ad_hoc_or_scheduled_order',
|
||||
sa_exc.IntegrityError,
|
||||
match='either_ad_hoc_or_scheduled_order',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -152,7 +154,8 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ad_hoc_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='ad_hoc_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -163,20 +166,23 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='ad_hoc_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='ad_hoc_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_scheduled_order_way_too_early(self, db_session, make_order):
|
||||
"""Insert an instance with invalid data."""
|
||||
pre_order = make_order(
|
||||
scheduled=True, scheduled_delivery_at=dt.datetime(*test_config.DATE, 10, 0),
|
||||
scheduled=True,
|
||||
scheduled_delivery_at=dt.datetime(*test_config.DATE, 10, 0),
|
||||
)
|
||||
|
||||
db_session.add(pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -190,7 +196,8 @@ class TestConstraints:
|
|||
db_session.add(pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -214,25 +221,32 @@ class TestConstraints:
|
|||
def test_scheduled_order_too_late(self, db_session, make_order):
|
||||
"""Insert an instance with invalid data."""
|
||||
pre_order = make_order(
|
||||
scheduled=True, scheduled_delivery_at=dt.datetime(*test_config.DATE, 23, 0),
|
||||
scheduled=True,
|
||||
scheduled_delivery_at=dt.datetime(*test_config.DATE, 23, 0),
|
||||
)
|
||||
|
||||
db_session.add(pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_within_business_hours',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_within_business_hours',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
@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, make_order, minute,
|
||||
self,
|
||||
db_session,
|
||||
make_order,
|
||||
minute,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
pre_order = make_order(
|
||||
scheduled=True,
|
||||
scheduled_delivery_at=dt.datetime( # `minute` is not 0, 15, 30, or 45
|
||||
*test_config.DATE, test_config.NOON, minute,
|
||||
*test_config.DATE,
|
||||
test_config.NOON,
|
||||
minute,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -246,13 +260,19 @@ class TestConstraints:
|
|||
|
||||
@pytest.mark.parametrize('second', list(range(1, 60)))
|
||||
def test_scheduled_order_at_non_quarter_of_an_hour_by_seconds(
|
||||
self, db_session, make_order, second,
|
||||
self,
|
||||
db_session,
|
||||
make_order,
|
||||
second,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
pre_order = make_order(
|
||||
scheduled=True,
|
||||
scheduled_delivery_at=dt.datetime(
|
||||
*test_config.DATE, test_config.NOON, 0, second,
|
||||
*test_config.DATE,
|
||||
test_config.NOON,
|
||||
0,
|
||||
second,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -288,7 +308,8 @@ class TestConstraints:
|
|||
db_session.add(pre_order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='scheduled_orders_not_within_30_minutes',
|
||||
sa_exc.IntegrityError,
|
||||
match='scheduled_orders_not_within_30_minutes',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -304,7 +325,8 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='only_cancelled_orders_may_have_cancelled_at',
|
||||
sa_exc.IntegrityError,
|
||||
match='only_cancelled_orders_may_have_cancelled_at',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -317,7 +339,8 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='cancelled_orders_must_not_be_delivered',
|
||||
sa_exc.IntegrityError,
|
||||
match='cancelled_orders_must_not_be_delivered',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -328,20 +351,25 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='between_0_and_2700',
|
||||
sa_exc.IntegrityError,
|
||||
match='between_0_and_2700',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
@pytest.mark.parametrize('duration', [1, 59, 119, 2699])
|
||||
def test_estimated_prep_duration_not_whole_minute(
|
||||
self, db_session, order, duration,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
duration,
|
||||
):
|
||||
"""Insert an instance with invalid data."""
|
||||
order.estimated_prep_duration = duration
|
||||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='must_be_whole_minutes',
|
||||
sa_exc.IntegrityError,
|
||||
match='must_be_whole_minutes',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -352,7 +380,8 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='between_0_and_900',
|
||||
sa_exc.IntegrityError,
|
||||
match='between_0_and_900',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -363,7 +392,8 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='must_be_whole_minutes',
|
||||
sa_exc.IntegrityError,
|
||||
match='must_be_whole_minutes',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -374,7 +404,8 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='between_0_and_100',
|
||||
sa_exc.IntegrityError,
|
||||
match='between_0_and_100',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -393,7 +424,10 @@ class TestConstraints:
|
|||
],
|
||||
)
|
||||
def test_unset_timestamp_column_not_marked_as_uncorrected( # noqa:WPS213
|
||||
self, db_session, order, column,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
column,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -421,12 +455,15 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='corrections_only_for_set_value',
|
||||
sa_exc.IntegrityError,
|
||||
match='corrections_only_for_set_value',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_unset_timestamp_column_not_marked_as_uncorrected_special_case1(
|
||||
self, db_session, order,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -434,11 +471,15 @@ class TestConstraints:
|
|||
"""
|
||||
order.pickup_not_confirmed = None
|
||||
self.test_unset_timestamp_column_not_marked_as_uncorrected(
|
||||
db_session, order, 'pickup_at',
|
||||
db_session,
|
||||
order,
|
||||
'pickup_at',
|
||||
)
|
||||
|
||||
def test_unset_timestamp_column_not_marked_as_uncorrected_special_case2(
|
||||
self, db_session, order,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -447,7 +488,9 @@ class TestConstraints:
|
|||
order.delivery_not_confirmed = None
|
||||
order._courier_waited_at_delivery = None
|
||||
self.test_unset_timestamp_column_not_marked_as_uncorrected(
|
||||
db_session, order, 'delivery_at',
|
||||
db_session,
|
||||
order,
|
||||
'delivery_at',
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -465,7 +508,10 @@ class TestConstraints:
|
|||
],
|
||||
)
|
||||
def test_set_timestamp_column_is_not_unmarked( # noqa:WPS213
|
||||
self, db_session, order, column,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
column,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -493,23 +539,30 @@ class TestConstraints:
|
|||
db_session.add(order)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='corrections_only_for_set_value',
|
||||
sa_exc.IntegrityError,
|
||||
match='corrections_only_for_set_value',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
def test_set_timestamp_column_is_not_unmarked_special_case1(
|
||||
self, db_session, pre_order,
|
||||
self,
|
||||
db_session,
|
||||
pre_order,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
This is one of two special cases. See the generic case above.
|
||||
"""
|
||||
self.test_set_timestamp_column_is_not_unmarked(
|
||||
db_session, pre_order, 'scheduled_delivery_at',
|
||||
db_session,
|
||||
pre_order,
|
||||
'scheduled_delivery_at',
|
||||
)
|
||||
|
||||
def test_set_timestamp_column_is_not_unmarked_special_case2(
|
||||
self, db_session, order,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -524,7 +577,9 @@ class TestConstraints:
|
|||
order._courier_waited_at_delivery = None
|
||||
|
||||
self.test_set_timestamp_column_is_not_unmarked(
|
||||
db_session, order, 'cancelled_at',
|
||||
db_session,
|
||||
order,
|
||||
'cancelled_at',
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -575,7 +630,10 @@ class TestConstraints:
|
|||
],
|
||||
)
|
||||
def test_timestamps_unordered(
|
||||
self, db_session, order, comparison,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
comparison,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -604,7 +662,9 @@ class TestConstraints:
|
|||
# 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, pre_order, 'placed_at < scheduled_delivery_at',
|
||||
db_session,
|
||||
pre_order,
|
||||
'placed_at < scheduled_delivery_at',
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -623,7 +683,10 @@ class TestConstraints:
|
|||
],
|
||||
)
|
||||
def test_timestamps_unordered_cancelled(
|
||||
self, db_session, order, comparison,
|
||||
self,
|
||||
db_session,
|
||||
order,
|
||||
comparison,
|
||||
):
|
||||
"""Insert an instance with invalid data.
|
||||
|
||||
|
|
@ -1021,7 +1084,11 @@ class TestProperties:
|
|||
@pytest.mark.db
|
||||
@pytest.mark.no_cover
|
||||
def test_make_random_orders( # noqa:C901,WPS211,WPS213
|
||||
db_session, make_address, make_courier, make_restaurant, make_order,
|
||||
db_session,
|
||||
make_address,
|
||||
make_courier,
|
||||
make_restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""Sanity check the all the `make_*` fixtures.
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ class TestConstraints:
|
|||
stmt = sqla.delete(db.Grid).where(db.Grid.id == pixel.grid.id)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_pixels_to_grids_via_grid_id',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_pixels_to_grids_via_grid_id',
|
||||
):
|
||||
db_session.execute(stmt)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ class TestConstraints:
|
|||
stmt = sqla.delete(db.Address).where(db.Address.id == restaurant.address.id)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='fk_restaurants_to_addresses_via_address_id',
|
||||
sa_exc.IntegrityError,
|
||||
match='fk_restaurants_to_addresses_via_address_id',
|
||||
):
|
||||
db_session.execute(stmt)
|
||||
|
||||
|
|
@ -54,7 +55,8 @@ class TestConstraints:
|
|||
db_session.add(restaurant)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='realistic_estimated_prep_duration',
|
||||
sa_exc.IntegrityError,
|
||||
match='realistic_estimated_prep_duration',
|
||||
):
|
||||
db_session.commit()
|
||||
|
||||
|
|
@ -64,6 +66,7 @@ class TestConstraints:
|
|||
db_session.add(restaurant)
|
||||
|
||||
with pytest.raises(
|
||||
sa_exc.IntegrityError, match='realistic_estimated_prep_duration',
|
||||
sa_exc.IntegrityError,
|
||||
match='realistic_estimated_prep_duration',
|
||||
):
|
||||
db_session.commit()
|
||||
|
|
|
|||
|
|
@ -80,7 +80,9 @@ class TestSpecialMethods:
|
|||
assert result is False
|
||||
|
||||
def test_compare_utm_coordinates_to_far_away_coordinates(
|
||||
self, location, faraway_location,
|
||||
self,
|
||||
location,
|
||||
faraway_location,
|
||||
):
|
||||
"""Test `Location.__eq__()`."""
|
||||
with pytest.raises(ValueError, match='must be in the same zone'):
|
||||
|
|
@ -173,7 +175,9 @@ class TestRelateTo:
|
|||
location.relate_to(object())
|
||||
|
||||
def test_call_relate_to_with_far_away_other(
|
||||
self, location, faraway_location,
|
||||
self,
|
||||
location,
|
||||
faraway_location,
|
||||
):
|
||||
"""The `other` origin must be in the same UTM zone."""
|
||||
with pytest.raises(ValueError, match='must be in the same zone'):
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ def vertical_datetime_index():
|
|||
which is `12` for `LONG_TIME_STEP` values.
|
||||
"""
|
||||
start_ats = pd.date_range(
|
||||
test_config.START, test_config.END, freq=f'{test_config.LONG_TIME_STEP}T',
|
||||
test_config.START,
|
||||
test_config.END,
|
||||
freq=f'{test_config.LONG_TIME_STEP}T',
|
||||
)
|
||||
gen = (
|
||||
start_at
|
||||
|
|
@ -103,7 +105,9 @@ def order_totals(good_pixel_id):
|
|||
pixel_ids = [good_pixel_id, good_pixel_id + 1]
|
||||
|
||||
start_ats = pd.date_range(
|
||||
test_config.START, test_config.END, freq=f'{test_config.LONG_TIME_STEP}T',
|
||||
test_config.START,
|
||||
test_config.END,
|
||||
freq=f'{test_config.LONG_TIME_STEP}T',
|
||||
)
|
||||
gen = (
|
||||
(pixel_id, start_at)
|
||||
|
|
|
|||
|
|
@ -22,14 +22,18 @@ class TestInvalidArguments:
|
|||
|
||||
with pytest.raises(ValueError, match='`NaN` values'):
|
||||
decomposition.stl(
|
||||
time_series, frequency=test_config.VERTICAL_FREQUENCY_LONG, ns=NS,
|
||||
time_series,
|
||||
frequency=test_config.VERTICAL_FREQUENCY_LONG,
|
||||
ns=NS,
|
||||
)
|
||||
|
||||
def test_ns_not_odd(self, vertical_no_demand):
|
||||
"""`ns` must be odd and `>= 7`."""
|
||||
with pytest.raises(ValueError, match='`ns`'):
|
||||
decomposition.stl(
|
||||
vertical_no_demand, frequency=test_config.VERTICAL_FREQUENCY_LONG, ns=8,
|
||||
vertical_no_demand,
|
||||
frequency=test_config.VERTICAL_FREQUENCY_LONG,
|
||||
ns=8,
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize('ns', [-99, -1, 1, 5])
|
||||
|
|
@ -197,7 +201,9 @@ class TestValidArguments:
|
|||
def test_structure_of_returned_dataframe(self, vertical_no_demand):
|
||||
"""`stl()` returns a `pd.DataFrame` with three columns."""
|
||||
result = decomposition.stl(
|
||||
vertical_no_demand, frequency=test_config.VERTICAL_FREQUENCY_LONG, ns=NS,
|
||||
vertical_no_demand,
|
||||
frequency=test_config.VERTICAL_FREQUENCY_LONG,
|
||||
ns=NS,
|
||||
)
|
||||
|
||||
assert isinstance(result, pd.DataFrame)
|
||||
|
|
@ -216,7 +222,18 @@ class TestValidArguments:
|
|||
@pytest.mark.parametrize('ni', [2, 3])
|
||||
@pytest.mark.parametrize('no', [0, 1])
|
||||
def test_decompose_time_series_with_no_demand( # noqa:WPS211,WPS216
|
||||
self, vertical_no_demand, nt, nl, ds, dt, dl, js, jt, jl, ni, no, # noqa:WPS110
|
||||
self,
|
||||
vertical_no_demand,
|
||||
nt,
|
||||
nl,
|
||||
ds,
|
||||
dt,
|
||||
dl,
|
||||
js,
|
||||
jt,
|
||||
jl,
|
||||
ni,
|
||||
no, # noqa:WPS110
|
||||
):
|
||||
"""Decomposing a time series with no demand ...
|
||||
|
||||
|
|
|
|||
|
|
@ -21,14 +21,24 @@ def forecast_interval():
|
|||
"""
|
||||
future_day = test_config.END.date() + dt.timedelta(days=1)
|
||||
first_start_at = dt.datetime(
|
||||
future_day.year, future_day.month, future_day.day, config.SERVICE_START, 0,
|
||||
future_day.year,
|
||||
future_day.month,
|
||||
future_day.day,
|
||||
config.SERVICE_START,
|
||||
0,
|
||||
)
|
||||
end_of_day = dt.datetime(
|
||||
future_day.year, future_day.month, future_day.day, config.SERVICE_END, 0,
|
||||
future_day.year,
|
||||
future_day.month,
|
||||
future_day.day,
|
||||
config.SERVICE_END,
|
||||
0,
|
||||
)
|
||||
|
||||
start_ats = pd.date_range(
|
||||
first_start_at, end_of_day, freq=f'{test_config.LONG_TIME_STEP}T',
|
||||
first_start_at,
|
||||
end_of_day,
|
||||
freq=f'{test_config.LONG_TIME_STEP}T',
|
||||
)
|
||||
gen = (
|
||||
start_at
|
||||
|
|
@ -48,7 +58,11 @@ def forecast_time_step():
|
|||
future_day = test_config.END.date() + dt.timedelta(days=1)
|
||||
|
||||
start_at = dt.datetime(
|
||||
future_day.year, future_day.month, future_day.day, test_config.NOON, 0,
|
||||
future_day.year,
|
||||
future_day.month,
|
||||
future_day.day,
|
||||
test_config.NOON,
|
||||
0,
|
||||
)
|
||||
|
||||
index = pd.Index([start_at])
|
||||
|
|
@ -59,13 +73,17 @@ def forecast_time_step():
|
|||
|
||||
@pytest.mark.r
|
||||
@pytest.mark.parametrize(
|
||||
'func', [arima.predict, ets.predict, extrapolate_season.predict],
|
||||
'func',
|
||||
[arima.predict, ets.predict, extrapolate_season.predict],
|
||||
)
|
||||
class TestMakePredictions:
|
||||
"""Make predictions with `arima.predict()` and `ets.predict()`."""
|
||||
|
||||
def test_training_data_contains_nan_values(
|
||||
self, func, vertical_no_demand, forecast_interval,
|
||||
self,
|
||||
func,
|
||||
vertical_no_demand,
|
||||
forecast_interval,
|
||||
):
|
||||
"""`training_ts` must not contain `NaN` values."""
|
||||
vertical_no_demand.iloc[0] = pd.NA
|
||||
|
|
@ -78,7 +96,10 @@ class TestMakePredictions:
|
|||
)
|
||||
|
||||
def test_structure_of_returned_dataframe(
|
||||
self, func, vertical_no_demand, forecast_interval,
|
||||
self,
|
||||
func,
|
||||
vertical_no_demand,
|
||||
forecast_interval,
|
||||
):
|
||||
"""Both `.predict()` return a `pd.DataFrame` with five columns."""
|
||||
result = func(
|
||||
|
|
@ -97,7 +118,10 @@ class TestMakePredictions:
|
|||
]
|
||||
|
||||
def test_predict_horizontal_time_series_with_no_demand(
|
||||
self, func, horizontal_no_demand, forecast_time_step,
|
||||
self,
|
||||
func,
|
||||
horizontal_no_demand,
|
||||
forecast_time_step,
|
||||
):
|
||||
"""Predicting a horizontal time series with no demand ...
|
||||
|
||||
|
|
@ -114,7 +138,10 @@ class TestMakePredictions:
|
|||
assert result == 0
|
||||
|
||||
def test_predict_vertical_time_series_with_no_demand(
|
||||
self, func, vertical_no_demand, forecast_interval,
|
||||
self,
|
||||
func,
|
||||
vertical_no_demand,
|
||||
forecast_interval,
|
||||
):
|
||||
"""Predicting a vertical time series with no demand ...
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
"""Tests for the `velofy.forecasts.models` sub-package."""
|
||||
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
|
|
@ -62,7 +61,11 @@ class TestGenericForecastingModelProperties:
|
|||
|
||||
@pytest.mark.r
|
||||
def test_make_prediction_structure(
|
||||
self, model_cls, order_history, pixel, predict_at,
|
||||
self,
|
||||
model_cls,
|
||||
order_history,
|
||||
pixel,
|
||||
predict_at,
|
||||
):
|
||||
"""`*Model.predict()` returns a `pd.DataFrame` ...
|
||||
|
||||
|
|
@ -88,7 +91,11 @@ class TestGenericForecastingModelProperties:
|
|||
|
||||
@pytest.mark.r
|
||||
def test_make_prediction_for_given_time_step(
|
||||
self, model_cls, order_history, pixel, predict_at,
|
||||
self,
|
||||
model_cls,
|
||||
order_history,
|
||||
pixel,
|
||||
predict_at,
|
||||
):
|
||||
"""`*Model.predict()` returns a row for ...
|
||||
|
||||
|
|
@ -106,7 +113,11 @@ class TestGenericForecastingModelProperties:
|
|||
|
||||
@pytest.mark.r
|
||||
def test_make_prediction_contains_actual_values(
|
||||
self, model_cls, order_history, pixel, predict_at,
|
||||
self,
|
||||
model_cls,
|
||||
order_history,
|
||||
pixel,
|
||||
predict_at,
|
||||
):
|
||||
"""`*Model.predict()` returns a `pd.DataFrame` ...
|
||||
|
||||
|
|
@ -126,7 +137,12 @@ class TestGenericForecastingModelProperties:
|
|||
@pytest.mark.db
|
||||
@pytest.mark.r
|
||||
def test_make_forecast( # noqa:WPS211
|
||||
self, db_session, model_cls, order_history, pixel, predict_at,
|
||||
self,
|
||||
db_session,
|
||||
model_cls,
|
||||
order_history,
|
||||
pixel,
|
||||
predict_at,
|
||||
):
|
||||
"""`*Model.make_forecast()` returns a `Forecast` object.""" # noqa:RST215
|
||||
model = model_cls(order_history=order_history)
|
||||
|
|
@ -145,7 +161,12 @@ class TestGenericForecastingModelProperties:
|
|||
@pytest.mark.db
|
||||
@pytest.mark.r
|
||||
def test_make_forecast_is_cached( # noqa:WPS211
|
||||
self, db_session, model_cls, order_history, pixel, predict_at,
|
||||
self,
|
||||
db_session,
|
||||
model_cls,
|
||||
order_history,
|
||||
pixel,
|
||||
predict_at,
|
||||
):
|
||||
"""`*Model.make_forecast()` caches the `Forecast` object.""" # noqa:RST215
|
||||
model = model_cls(order_history=order_history)
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant.orders) == 0 # noqa:WPS507 sanity check
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
|
||||
grid=one_pixel_grid,
|
||||
time_step=test_config.LONG_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
@ -65,7 +66,11 @@ class TestAggregateOrders:
|
|||
assert len(result) == 0 # noqa:WPS507
|
||||
|
||||
def test_evenly_distributed_ad_hoc_orders(
|
||||
self, db_session, one_pixel_grid, restaurant, make_order,
|
||||
self,
|
||||
db_session,
|
||||
one_pixel_grid,
|
||||
restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""12 ad-hoc orders, one per operating hour."""
|
||||
# Create one order per hour and 12 orders in total.
|
||||
|
|
@ -82,7 +87,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant.orders) == 12 # sanity check
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
|
||||
grid=one_pixel_grid,
|
||||
time_step=test_config.LONG_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
@ -94,7 +100,11 @@ class TestAggregateOrders:
|
|||
assert result['n_orders'].sum() == 12
|
||||
|
||||
def test_evenly_distributed_ad_hoc_orders_with_no_demand_late( # noqa:WPS218
|
||||
self, db_session, one_pixel_grid, restaurant, make_order,
|
||||
self,
|
||||
db_session,
|
||||
one_pixel_grid,
|
||||
restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""10 ad-hoc orders, one per hour, no orders after 21."""
|
||||
# Create one order per hour and 10 orders in total.
|
||||
|
|
@ -111,7 +121,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant.orders) == 10 # sanity check
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
|
||||
grid=one_pixel_grid,
|
||||
time_step=test_config.LONG_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
@ -125,7 +136,11 @@ class TestAggregateOrders:
|
|||
assert result.iloc[10:]['n_orders'].sum() == 0
|
||||
|
||||
def test_one_ad_hoc_order_every_other_hour(
|
||||
self, db_session, one_pixel_grid, restaurant, make_order,
|
||||
self,
|
||||
db_session,
|
||||
one_pixel_grid,
|
||||
restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""6 ad-hoc orders, one every other hour."""
|
||||
# Create one order every other hour.
|
||||
|
|
@ -142,7 +157,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant.orders) == 6 # sanity check
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
|
||||
grid=one_pixel_grid,
|
||||
time_step=test_config.LONG_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
@ -154,7 +170,11 @@ class TestAggregateOrders:
|
|||
assert result['n_orders'].sum() == 6
|
||||
|
||||
def test_one_ad_hoc_and_one_pre_order(
|
||||
self, db_session, one_pixel_grid, restaurant, make_order,
|
||||
self,
|
||||
db_session,
|
||||
one_pixel_grid,
|
||||
restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""1 ad-hoc and 1 scheduled order.
|
||||
|
||||
|
|
@ -180,7 +200,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant.orders) == 2 # sanity check
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
|
||||
grid=one_pixel_grid,
|
||||
time_step=test_config.LONG_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
@ -192,7 +213,11 @@ class TestAggregateOrders:
|
|||
assert result['n_orders'].sum() == 1
|
||||
|
||||
def test_evenly_distributed_ad_hoc_orders_with_half_hour_time_steps( # noqa:WPS218
|
||||
self, db_session, one_pixel_grid, restaurant, make_order,
|
||||
self,
|
||||
db_session,
|
||||
one_pixel_grid,
|
||||
restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""12 ad-hoc orders, one per hour, with 30 minute time windows.
|
||||
|
||||
|
|
@ -212,7 +237,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant.orders) == 12 # sanity check
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=one_pixel_grid, time_step=test_config.SHORT_TIME_STEP,
|
||||
grid=one_pixel_grid,
|
||||
time_step=test_config.SHORT_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
@ -226,7 +252,11 @@ class TestAggregateOrders:
|
|||
assert result.iloc[1::2]['n_orders'].sum() == 0
|
||||
|
||||
def test_ad_hoc_orders_over_two_days(
|
||||
self, db_session, one_pixel_grid, restaurant, make_order,
|
||||
self,
|
||||
db_session,
|
||||
one_pixel_grid,
|
||||
restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""First day 12 ad-hoc orders, one per operating hour ...
|
||||
|
||||
|
|
@ -262,7 +292,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant.orders) == 18 # sanity check
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
|
||||
grid=one_pixel_grid,
|
||||
time_step=test_config.LONG_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
@ -275,7 +306,12 @@ class TestAggregateOrders:
|
|||
|
||||
@pytest.fixture
|
||||
def two_pixel_grid( # noqa:WPS211
|
||||
self, db_session, city, make_address, make_restaurant, addresses_mock,
|
||||
self,
|
||||
db_session,
|
||||
city,
|
||||
make_address,
|
||||
make_restaurant,
|
||||
addresses_mock,
|
||||
):
|
||||
"""A persisted `Grid` with two `Pixel` objects."""
|
||||
# One `Address` in the lower-left `Pixel`, ...
|
||||
|
|
@ -301,7 +337,10 @@ class TestAggregateOrders:
|
|||
return grid
|
||||
|
||||
def test_two_pixels_with_shifted_orders( # noqa:WPS218
|
||||
self, db_session, two_pixel_grid, make_order,
|
||||
self,
|
||||
db_session,
|
||||
two_pixel_grid,
|
||||
make_order,
|
||||
):
|
||||
"""One restaurant with one order every other hour ...
|
||||
|
||||
|
|
@ -356,7 +395,8 @@ class TestAggregateOrders:
|
|||
assert len(restaurant2.orders) == 24
|
||||
|
||||
oh = timify.OrderHistory(
|
||||
grid=two_pixel_grid, time_step=test_config.LONG_TIME_STEP,
|
||||
grid=two_pixel_grid,
|
||||
time_step=test_config.LONG_TIME_STEP,
|
||||
)
|
||||
|
||||
result = oh.aggregate_orders()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ class TestAverageDailyDemand:
|
|||
"""Tests for the `OrderHistory.avg_daily_demand()` method."""
|
||||
|
||||
def test_avg_daily_demand_with_constant_demand(
|
||||
self, order_history, good_pixel_id, predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
predict_at,
|
||||
):
|
||||
"""The average daily demand must be the number of time steps ...
|
||||
|
||||
|
|
@ -34,7 +37,10 @@ class TestAverageDailyDemand:
|
|||
assert result == 12.0
|
||||
|
||||
def test_avg_daily_demand_with_no_demand(
|
||||
self, order_history, good_pixel_id, predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
predict_at,
|
||||
):
|
||||
"""Without demand, the average daily demand must be `0.0`."""
|
||||
order_history._data.loc[:, 'n_orders'] = 0
|
||||
|
|
@ -52,7 +58,10 @@ class TestChooseTacticalModel:
|
|||
"""Tests for the `OrderHistory.choose_tactical_model()` method."""
|
||||
|
||||
def test_best_model_with_high_demand(
|
||||
self, order_history, good_pixel_id, predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
predict_at,
|
||||
):
|
||||
"""With high demand, the average daily demand is `.>= 25.0`."""
|
||||
# With 12 time steps per day, the ADD becomes `36.0`.
|
||||
|
|
@ -67,7 +76,10 @@ class TestChooseTacticalModel:
|
|||
assert isinstance(result, models.HorizontalETSModel)
|
||||
|
||||
def test_best_model_with_medium_demand(
|
||||
self, order_history, good_pixel_id, predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
predict_at,
|
||||
):
|
||||
"""With medium demand, the average daily demand is `>= 10.0` and `< 25.0`."""
|
||||
# With 12 time steps per day, the ADD becomes `24.0`.
|
||||
|
|
@ -82,7 +94,10 @@ class TestChooseTacticalModel:
|
|||
assert isinstance(result, models.HorizontalETSModel)
|
||||
|
||||
def test_best_model_with_low_demand(
|
||||
self, order_history, good_pixel_id, predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
predict_at,
|
||||
):
|
||||
"""With low demand, the average daily demand is `>= 2.5` and `< 10.0`."""
|
||||
# With 12 time steps per day, the ADD becomes `12.0` ...
|
||||
|
|
@ -115,7 +130,10 @@ class TestChooseTacticalModel:
|
|||
assert isinstance(result, models.HorizontalSMAModel)
|
||||
|
||||
def test_best_model_with_no_demand(
|
||||
self, order_history, good_pixel_id, predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
predict_at,
|
||||
):
|
||||
"""Without demand, the average daily demand is `< 2.5`."""
|
||||
order_history._data.loc[:, 'n_orders'] = 0
|
||||
|
|
@ -129,7 +147,10 @@ class TestChooseTacticalModel:
|
|||
assert isinstance(result, models.TrivialModel)
|
||||
|
||||
def test_best_model_for_unknown_train_horizon(
|
||||
self, order_history, good_pixel_id, predict_at, # noqa:RST215
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
predict_at, # noqa:RST215
|
||||
):
|
||||
"""For `train_horizon` values not included in the rule-based system ...
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,11 @@ def bad_predict_at():
|
|||
"""
|
||||
predict_day = test_config.END - datetime.timedelta(weeks=6, days=1)
|
||||
return datetime.datetime(
|
||||
predict_day.year, predict_day.month, predict_day.day, test_config.NOON, 0,
|
||||
predict_day.year,
|
||||
predict_day.month,
|
||||
predict_day.day,
|
||||
test_config.NOON,
|
||||
0,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -57,7 +61,11 @@ class TestMakeHorizontalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_time_series_are_series(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The time series come as a `pd.Series`."""
|
||||
result = order_history.make_horizontal_ts(
|
||||
|
|
@ -75,7 +83,11 @@ class TestMakeHorizontalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_time_series_have_correct_length(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The length of a training time series must be a multiple of `7` ...
|
||||
|
||||
|
|
@ -94,7 +106,11 @@ class TestMakeHorizontalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_frequency_is_number_of_weekdays(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The `frequency` must be `7`."""
|
||||
result = order_history.make_horizontal_ts(
|
||||
|
|
@ -109,7 +125,11 @@ class TestMakeHorizontalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_no_long_enough_history1(
|
||||
self, order_history, good_pixel_id, bad_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
bad_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""If the `predict_at` day is too early in the `START`-`END` horizon ...
|
||||
|
||||
|
|
@ -123,7 +143,10 @@ class TestMakeHorizontalTimeSeries:
|
|||
)
|
||||
|
||||
def test_no_long_enough_history2(
|
||||
self, order_history, good_pixel_id, good_predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
):
|
||||
"""If the `train_horizon` is longer than the `START`-`END` horizon ...
|
||||
|
||||
|
|
@ -131,7 +154,9 @@ class TestMakeHorizontalTimeSeries:
|
|||
"""
|
||||
with pytest.raises(RuntimeError):
|
||||
order_history.make_horizontal_ts(
|
||||
pixel_id=good_pixel_id, predict_at=good_predict_at, train_horizon=999,
|
||||
pixel_id=good_pixel_id,
|
||||
predict_at=good_predict_at,
|
||||
train_horizon=999,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -150,7 +175,11 @@ class TestMakeVerticalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_time_series_are_series(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The time series come as `pd.Series`."""
|
||||
result = order_history.make_vertical_ts(
|
||||
|
|
@ -168,7 +197,11 @@ class TestMakeVerticalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_time_series_have_correct_length(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The length of a training time series is the product of the ...
|
||||
|
||||
|
|
@ -197,7 +230,11 @@ class TestMakeVerticalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_frequency_is_number_number_of_weekly_time_steps(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The `frequency` is the number of weekly time steps."""
|
||||
result = order_history.make_vertical_ts(
|
||||
|
|
@ -218,7 +255,11 @@ class TestMakeVerticalTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_no_long_enough_history1(
|
||||
self, order_history, good_pixel_id, bad_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
bad_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""If the `predict_at` day is too early in the `START`-`END` horizon ...
|
||||
|
||||
|
|
@ -232,7 +273,10 @@ class TestMakeVerticalTimeSeries:
|
|||
)
|
||||
|
||||
def test_no_long_enough_history2(
|
||||
self, order_history, good_pixel_id, good_predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
):
|
||||
"""If the `train_horizon` is longer than the `START`-`END` horizon ...
|
||||
|
||||
|
|
@ -261,7 +305,11 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_time_series_are_series(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The time series come as `pd.Series`."""
|
||||
result = order_history.make_realtime_ts(
|
||||
|
|
@ -279,7 +327,11 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_time_series_have_correct_length1(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The length of a training time series is the product of the ...
|
||||
|
||||
|
|
@ -297,7 +349,9 @@ class TestMakeRealTimeTimeSeries:
|
|||
0,
|
||||
)
|
||||
result = order_history.make_realtime_ts(
|
||||
pixel_id=good_pixel_id, predict_at=predict_at, train_horizon=train_horizon,
|
||||
pixel_id=good_pixel_id,
|
||||
predict_at=predict_at,
|
||||
train_horizon=train_horizon,
|
||||
)
|
||||
|
||||
training_ts, _, actuals_ts = result
|
||||
|
|
@ -313,7 +367,11 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_time_series_have_correct_length2(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The length of a training time series is the product of the ...
|
||||
|
||||
|
|
@ -352,7 +410,11 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_frequency_is_number_number_of_weekly_time_steps(
|
||||
self, order_history, good_pixel_id, good_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""The `frequency` is the number of weekly time steps."""
|
||||
result = order_history.make_realtime_ts(
|
||||
|
|
@ -373,7 +435,11 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
|
||||
def test_no_long_enough_history1(
|
||||
self, order_history, good_pixel_id, bad_predict_at, train_horizon,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
bad_predict_at,
|
||||
train_horizon,
|
||||
):
|
||||
"""If the `predict_at` day is too early in the `START`-`END` horizon ...
|
||||
|
||||
|
|
@ -387,7 +453,10 @@ class TestMakeRealTimeTimeSeries:
|
|||
)
|
||||
|
||||
def test_no_long_enough_history2(
|
||||
self, order_history, good_pixel_id, good_predict_at,
|
||||
self,
|
||||
order_history,
|
||||
good_pixel_id,
|
||||
good_predict_at,
|
||||
):
|
||||
"""If the `train_horizon` is longer than the `START`-`END` horizon ...
|
||||
|
||||
|
|
@ -395,5 +464,7 @@ class TestMakeRealTimeTimeSeries:
|
|||
"""
|
||||
with pytest.raises(RuntimeError):
|
||||
order_history.make_realtime_ts(
|
||||
pixel_id=good_pixel_id, predict_at=good_predict_at, train_horizon=999,
|
||||
pixel_id=good_pixel_id,
|
||||
predict_at=good_predict_at,
|
||||
train_horizon=999,
|
||||
)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue