diff --git a/src/gsy_e/models/market/future.py b/src/gsy_e/models/market/future.py index a179e2ca1..11fead2c0 100644 --- a/src/gsy_e/models/market/future.py +++ b/src/gsy_e/models/market/future.py @@ -178,8 +178,10 @@ def create_future_markets(self, current_market_time_slot: DateTime, slot_length: duration, config: "SimulationConfig") -> None: """Add sub dicts in order dictionaries for future market slots.""" + if not GlobalConfig.FUTURE_MARKET_DURATION_HOURS: + return future_time_slot = current_market_time_slot.add(minutes=slot_length.total_minutes()) - most_future_slot = (future_time_slot + + most_future_slot = (current_market_time_slot + duration(hours=GlobalConfig.FUTURE_MARKET_DURATION_HOURS)) while future_time_slot <= most_future_slot: if (future_time_slot not in self.slot_bid_mapping and diff --git a/tests/market/test_future.py b/tests/market/test_future.py index 12bed9059..3436e1b1f 100644 --- a/tests/market/test_future.py +++ b/tests/market/test_future.py @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +from unittest.mock import patch, MagicMock + import pytest from gsy_framework.constants_limits import GlobalConfig, DATE_TIME_FORMAT from gsy_framework.data_classes import Bid, Offer, Trade, TradeBidOfferInfo @@ -84,12 +86,32 @@ class TestFutureMarkets: """Tests that target the future markets.""" @staticmethod + @patch("gsy_e.models.market.future.is_time_slot_in_simulation_duration", + MagicMock()) def test_create_future_markets(future_market): """Test if all future time_slots are created in the order buffers.""" + future_market.offers = {} + future_market.bids = {} + + with patch("gsy_e.models.market.future.GlobalConfig." + "FUTURE_MARKET_DURATION_HOURS", 0): + future_market.create_future_markets( + DEFAULT_CURRENT_MARKET_SLOT, DEFAULT_SLOT_LENGTH, MagicMock() + ) for buffer in [future_market.slot_bid_mapping, future_market.slot_offer_mapping, future_market.slot_trade_mapping]: - assert len(buffer.keys()) == 5 + assert len(buffer.keys()) == 0 + + with patch("gsy_e.models.market.future.GlobalConfig." + "FUTURE_MARKET_DURATION_HOURS", 1): + future_market.create_future_markets( + DEFAULT_CURRENT_MARKET_SLOT, DEFAULT_SLOT_LENGTH, MagicMock() + ) + for buffer in [future_market.slot_bid_mapping, + future_market.slot_offer_mapping, + future_market.slot_trade_mapping]: + assert len(buffer.keys()) == 4 future_time_slot = DEFAULT_CURRENT_MARKET_SLOT.add( minutes=DEFAULT_SLOT_LENGTH.total_minutes()) most_future_slot = (future_time_slot + @@ -108,10 +130,10 @@ def test_delete_old_future_markets(future_market): time_slot=time_slot) future_market.trades.append(trade) - count_orders_in_buffers(future_market, 5) + count_orders_in_buffers(future_market, 4) first_future_market = next(iter(future_market.slot_bid_mapping)) future_market.delete_orders_in_old_future_markets(first_future_market) - count_orders_in_buffers(future_market, 4) + count_orders_in_buffers(future_market, 3) @staticmethod def test_offer_is_posted_correctly(future_market):