<s> import unittest <EOL> from datetime import timedelta <EOL> from rx import Observable <EOL> from rx . testing import TestScheduler , ReactiveTest , is_prime , MockDisposable <EOL> from rx . disposables import Disposable , SerialDisposable <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 TestWindowWithTime ( unittest . TestCase ) : <EOL> def test_window_with_time_or_count_basic ( self ) : <EOL> scheduler = TestScheduler ( ) <EOL> xs = scheduler . create_hot_observable ( 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> ) , on_next ( <NUM_LIT> , <NUM_LIT:9> ) , on_completed ( <NUM_LIT> ) ) <EOL> def create ( ) : <EOL> def projection ( w , i ) : <EOL> def inner_proj ( x ) : <EOL> return "<STR_LIT>" % ( i , x ) <EOL> return w . map ( inner_proj ) <EOL> return xs . window_with_time_or_count ( <NUM_LIT> , <NUM_LIT:3> , scheduler ) . map ( projection ) . merge_observable ( ) <EOL> results = scheduler . start ( create ) <EOL> results . messages . assert_equal ( on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_completed ( <NUM_LIT> ) ) <EOL> xs . subscriptions . assert_equal ( subscribe ( <NUM_LIT:200> , <NUM_LIT> ) ) <EOL> def test_window_with_time_or_count_error ( self ) : <EOL> ex = '<STR_LIT>' <EOL> scheduler = TestScheduler ( ) <EOL> xs = scheduler . create_hot_observable ( 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> ) , on_next ( <NUM_LIT> , <NUM_LIT:9> ) , on_error ( <NUM_LIT> , ex ) ) <EOL> def create ( ) : <EOL> def projection ( w , i ) : <EOL> def inner_proj ( x ) : <EOL> return "<STR_LIT>" % ( i , x ) <EOL> return w . map ( inner_proj ) <EOL> return xs . window_with_time_or_count ( <NUM_LIT> , <NUM_LIT:3> , scheduler ) . map ( projection ) . merge_observable ( ) <EOL> results = scheduler . start ( create ) <EOL> results . messages . assert_equal ( on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_error ( <NUM_LIT> , ex ) ) <EOL> xs . subscriptions . assert_equal ( subscribe ( <NUM_LIT:200> , <NUM_LIT> ) ) <EOL> def test_window_with_time_or_count_disposed ( self ) : <EOL> scheduler = TestScheduler ( ) <EOL> xs = scheduler . create_hot_observable ( 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> ) , on_next ( <NUM_LIT> , <NUM_LIT:9> ) , on_completed ( <NUM_LIT> ) ) <EOL> def create ( ) : <EOL> def projection ( w , i ) : <EOL> def inner_proj ( x ) : <EOL> return "<STR_LIT>" % ( i , x ) <EOL> return w . map ( inner_proj ) <EOL> return xs . window_with_time_or_count ( <NUM_LIT> , <NUM_LIT:3> , scheduler ) . map ( projection ) . merge_observable ( ) <EOL> results = scheduler . start ( create , disposed = <NUM_LIT> ) <EOL> results . messages . assert_equal ( on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) , on_next ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> xs . subscriptions . assert_equal ( subscribe ( <NUM_LIT:200> , <NUM_LIT> ) ) </s>
