<s> import unittest <EOL> from datetime import datetime , timedelta <EOL> from rx import Observable <EOL> from rx . testing import TestScheduler , ReactiveTest , is_prime , MockDisposable <EOL> from rx . disposables import Disposable , SerialDisposable <EOL> from rx . subjects import Subject <EOL> on_next = ReactiveTest . on_next <EOL> on_completed = ReactiveTest . on_completed <EOL> on_error = ReactiveTest . on_error <EOL> subscribe = ReactiveTest . subscribe <EOL> subscribed = ReactiveTest . subscribed <EOL> disposed = ReactiveTest . disposed <EOL> created = ReactiveTest . created <EOL> class RxException ( Exception ) : <EOL> pass <EOL> def _raise ( ex ) : <EOL> raise RxException ( ex ) <EOL> class TestTimeInterval ( unittest . TestCase ) : <EOL> def test_interval_timespan_basic ( self ) : <EOL> scheduler = TestScheduler ( ) <EOL> def create ( ) : <EOL> return Observable . interval ( <NUM_LIT:100> , scheduler = scheduler ) <EOL> results = scheduler . start ( create ) <EOL> results . messages . assert_equal ( on_next ( <NUM_LIT> , <NUM_LIT:0> ) , on_next ( <NUM_LIT> , <NUM_LIT:1> ) , on_next ( <NUM_LIT> , <NUM_LIT:2> ) , on_next ( <NUM_LIT> , <NUM_LIT:3> ) , on_next ( <NUM_LIT> , <NUM_LIT:4> ) , on_next ( <NUM_LIT> , <NUM_LIT:5> ) , on_next ( <NUM_LIT> , <NUM_LIT:6> ) ) <EOL> def test_interval_timespan_zero ( self ) : <EOL> scheduler = TestScheduler ( ) <EOL> def create ( ) : <EOL> return Observable . interval ( <NUM_LIT:0> , scheduler = scheduler ) <EOL> results = scheduler . start ( create , disposed = <NUM_LIT> ) <EOL> results . messages . assert_equal ( on_next ( <NUM_LIT> , <NUM_LIT:0> ) , on_next ( <NUM_LIT> , <NUM_LIT:1> ) , on_next ( <NUM_LIT> , <NUM_LIT:2> ) , on_next ( <NUM_LIT> , <NUM_LIT:3> ) , on_next ( <NUM_LIT> , <NUM_LIT:4> ) , on_next ( <NUM_LIT> , <NUM_LIT:5> ) , on_next ( <NUM_LIT> , <NUM_LIT:6> ) , on_next ( <NUM_LIT> , <NUM_LIT:7> ) , on_next ( <NUM_LIT> , <NUM_LIT:8> ) ) <EOL> def test_interval_timespan_negative ( self ) : <EOL> scheduler = TestScheduler ( ) <EOL> def create ( ) : <EOL> return Observable . interval ( - <NUM_LIT:1> , scheduler = scheduler ) <EOL> results = scheduler . start ( create , disposed = <NUM_LIT> ) <EOL> results . messages . assert_equal ( on_next ( <NUM_LIT> , <NUM_LIT:0> ) , on_next ( <NUM_LIT> , <NUM_LIT:1> ) , on_next ( <NUM_LIT> , <NUM_LIT:2> ) , on_next ( <NUM_LIT> , <NUM_LIT:3> ) , on_next ( <NUM_LIT> , <NUM_LIT:4> ) , on_next ( <NUM_LIT> , <NUM_LIT:5> ) , on_next ( <NUM_LIT> , <NUM_LIT:6> ) , on_next ( <NUM_LIT> , <NUM_LIT:7> ) , on_next ( <NUM_LIT> , <NUM_LIT:8> ) ) <EOL> def test_interval_timespan_disposed ( self ) : <EOL> scheduler = TestScheduler ( ) <EOL> def create ( ) : <EOL> return Observable . interval ( <NUM_LIT:1000> , scheduler = scheduler ) <EOL> results = scheduler . start ( create ) <EOL> results . messages . assert_equal ( ) <EOL> def test_interval_timespan_observer_throws ( self ) : <EOL> scheduler = TestScheduler ( ) <EOL> xs = Observable . interval ( <NUM_LIT:1> , scheduler = scheduler ) <EOL> xs . subscribe ( lambda x : _raise ( "<STR_LIT>" ) ) <EOL> with self . assertRaises ( RxException ) : <EOL> scheduler . start ( ) </s>
