def test_append_to_empty(): f = Quotes(1) ps = f.close f.append_list( Quote.mock_ohlcv_points([(1, 2.2, 0.9, 2), (2, 3.1, 1.9, 3), (3, 5.1, 2.9, 5)], t_start=10, t_step=1)) assert ps.sample_points() == [(10, 2), (11, 3), (12, 5)]
def test_close_points_during_update(): f = Quotes(1) points = f.close callback_count = 0 assert np.array_equal(points.sample_points(), []) def callback(*args): nonlocal callback_count callback_count += 1 assert points.sample_points() == [(10, 2), (11, 3), (12, 5)] points.add_observer(end=callback) f.append_list( Quote.mock_ohlcv_points([(1, 2.2, 0.9, 2), (2, 3.1, 1.9, 3), (3, 5.1, 2.9, 5)], t_start=10, t_step=1)) assert callback_count == 1