import rx import rx.operators as ops from rx.testing import TestScheduler def test_observable(): scheduler = TestScheduler() xs = scheduler.create_hot_observable(on_next(100, 1), on_next(200, 2), on_completed(250)) res = scheduler.start(create=lambda: xs.pipe(ops.sum())) assert res.messages == [on_next(250, 3), on_completed(250)]
import rx from rx.testing import TestScheduler def test_timeout(): scheduler = TestScheduler() observable = rx.timer(1000, scheduler=scheduler) result = scheduler.start(lambda: observable, created=0, subscribed=0, disposed=2000) assert result.messages == [on_completed(1000)]This example shows how to use the TestScheduler to test a timeout operation. We create a timer that emits a single event after 1000 milliseconds, and use the `start()` method to trigger the event. We also set the `created`, `subscribed`, and `disposed` parameters to control the timing of the observable's lifecycle. Finally, we verify that the expected output is produced.