async def test_remove_event(price_events_manager): event_1 = price_events_manager.add_event(random_price(), random_timestamp(), True) event_2 = price_events_manager.add_event(random_price(), random_timestamp(), False) if not os.getenv('CYTHON_IGNORE'): assert price_events_manager.events price_events_manager.remove_event(event_1) assert event_1 not in price_events_manager.events assert len(price_events_manager.events) == 1 price_events_manager.remove_event(Event()) assert len(price_events_manager.events) == 1 price_events_manager.remove_event(event_2) assert event_2 not in price_events_manager.events assert len(price_events_manager.events) == 0
async def test_handle_recent_trades(price_events_manager): random_price_1 = random_price(min_value=2) random_timestamp_1 = random_timestamp(min_value=2, max_value=1000) price_event_1 = price_events_manager.add_event(random_price_1, random_timestamp_1, True) with patch.object(price_event_1, 'set', new=Mock()) as price_event_1_set: price_events_manager.handle_recent_trades([]) with pytest.raises(AssertionError): price_event_1_set.assert_called_once() price_events_manager.handle_recent_trades([ random_recent_trade( price=random_price(max_value=random_price_1 - 1), timestamp=random_timestamp(max_value=random_timestamp_1 - 1)), random_recent_trade( price=random_price(max_value=random_price_1 - 1), timestamp=random_timestamp(max_value=random_timestamp_1 - 1)), random_recent_trade( price=random_price(max_value=random_price_1 - 1), timestamp=random_timestamp(max_value=random_timestamp_1 - 1)) ]) with pytest.raises(AssertionError): price_event_1_set.assert_called_once() price_events_manager.handle_recent_trades([ random_recent_trade(price=random_price(max_value=random_price_1 - 1)), random_recent_trade(price=random_price_1, timestamp=random_timestamp_1), random_recent_trade(price=random_price(max_value=random_price_1 - 1)), random_recent_trade(price=random_price(max_value=random_price_1 - 1)) ]) price_event_1_set.assert_called_once()
async def test_add_event(price_events_manager): price_events_manager.add_event(random_price(), random_timestamp(), True) price_events_manager.add_event(random_price(), random_timestamp(), False) if not os.getenv('CYTHON_IGNORE'): assert price_events_manager.events assert len(price_events_manager.events) == 2