Add OrderHistory.time_step
property
This commit is contained in:
parent
fd404e2b89
commit
d45c60b764
2 changed files with 27 additions and 12 deletions
|
@ -39,6 +39,11 @@ class OrderHistory:
|
||||||
# The `_data` are populated by `.aggregate_orders()`.
|
# The `_data` are populated by `.aggregate_orders()`.
|
||||||
self._data = None
|
self._data = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def time_step(self) -> int:
|
||||||
|
"""The length of one time step."""
|
||||||
|
return self._time_step
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def totals(self) -> pd.DataFrame:
|
def totals(self) -> pd.DataFrame:
|
||||||
"""The order totals by `Pixel` and `.time_step`.
|
"""The order totals by `Pixel` and `.time_step`.
|
||||||
|
|
|
@ -6,33 +6,43 @@ from tests import config as test_config
|
||||||
from urban_meal_delivery.forecasts import timify
|
from urban_meal_delivery.forecasts import timify
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def order_history(grid):
|
||||||
|
"""An `OrderHistory` object."""
|
||||||
|
return timify.OrderHistory(grid=grid, time_step=test_config.LONG_TIME_STEP)
|
||||||
|
|
||||||
|
|
||||||
class TestSpecialMethods:
|
class TestSpecialMethods:
|
||||||
"""Test the special methods in `OrderHistory`."""
|
"""Test the special methods in `OrderHistory`."""
|
||||||
|
|
||||||
@pytest.mark.parametrize('time_step', test_config.TIME_STEPS)
|
def test_instantiate(self, order_history):
|
||||||
def test_instantiate(self, grid, time_step):
|
|
||||||
"""Test `OrderHistory.__init__()`."""
|
"""Test `OrderHistory.__init__()`."""
|
||||||
oh = timify.OrderHistory(grid=grid, time_step=time_step)
|
assert order_history is not None
|
||||||
|
|
||||||
assert oh is not None
|
|
||||||
|
|
||||||
|
|
||||||
class TestProperties:
|
class TestProperties:
|
||||||
"""Test the properties in `OrderHistory`."""
|
"""Test the properties in `OrderHistory`."""
|
||||||
|
|
||||||
def test_totals_is_cached(self, grid, monkeypatch):
|
@pytest.mark.parametrize('time_step', test_config.TIME_STEPS)
|
||||||
"""Test `.totals` property.
|
def test_time_step(self, grid, time_step):
|
||||||
|
"""Test `OrderHistory.time_step` property."""
|
||||||
|
order_history = timify.OrderHistory(grid=grid, time_step=time_step)
|
||||||
|
|
||||||
|
result = order_history.time_step
|
||||||
|
|
||||||
|
assert result == time_step
|
||||||
|
|
||||||
|
def test_totals_is_cached(self, order_history, monkeypatch):
|
||||||
|
"""Test `OrderHistory.totals` property.
|
||||||
|
|
||||||
The result of the `OrderHistory.aggregate_orders()` method call
|
The result of the `OrderHistory.aggregate_orders()` method call
|
||||||
is cached in the `OrderHistory.totals` property.
|
is cached in the `OrderHistory.totals` property.
|
||||||
"""
|
"""
|
||||||
oh = timify.OrderHistory(grid=grid, time_step=test_config.LONG_TIME_STEP)
|
|
||||||
|
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
monkeypatch.setattr(oh, 'aggregate_orders', lambda: sentinel)
|
monkeypatch.setattr(order_history, 'aggregate_orders', lambda: sentinel)
|
||||||
|
|
||||||
result1 = oh.totals
|
result1 = order_history.totals
|
||||||
result2 = oh.totals
|
result2 = order_history.totals
|
||||||
|
|
||||||
assert result1 is result2
|
assert result1 is result2
|
||||||
assert result1 is sentinel
|
assert result1 is sentinel
|
||||||
|
|
Loading…
Reference in a new issue