<s> import unittest <EOL> from nose import SkipTest <EOL> import rx <EOL> asyncio = rx . config [ '<STR_LIT>' ] <EOL> if asyncio is None : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> Future = rx . config [ '<STR_LIT>' ] <EOL> from rx import Observable <EOL> class TestFromFuture ( unittest . TestCase ) : <EOL> def test_future_success ( self ) : <EOL> loop = asyncio . get_event_loop ( ) <EOL> success = [ False , True , False ] <EOL> @ asyncio . coroutine <EOL> def go ( ) : <EOL> future = Future ( ) <EOL> future . set_result ( <NUM_LIT> ) <EOL> source = Observable . from_future ( future ) <EOL> def on_next ( x ) : <EOL> success [ <NUM_LIT:0> ] = <NUM_LIT> == x <EOL> def on_error ( err ) : <EOL> success [ <NUM_LIT:1> ] = False <EOL> def on_completed ( ) : <EOL> success [ <NUM_LIT:2> ] = True <EOL> subscription = source . subscribe ( on_next , on_error , on_completed ) <EOL> loop . run_until_complete ( go ( ) ) <EOL> assert ( all ( success ) ) <EOL> def test_future_failure ( self ) : <EOL> loop = asyncio . get_event_loop ( ) <EOL> success = [ True , False , True ] <EOL> @ asyncio . coroutine <EOL> def go ( ) : <EOL> error = Exception ( '<STR_LIT>' ) <EOL> future = Future ( ) <EOL> future . set_exception ( error ) <EOL> source = Observable . from_future ( future ) <EOL> def on_next ( x ) : <EOL> success [ <NUM_LIT:0> ] = False <EOL> def on_error ( err ) : <EOL> success [ <NUM_LIT:1> ] = str ( err ) == str ( error ) <EOL> def on_completed ( ) : <EOL> success [ <NUM_LIT:2> ] = False <EOL> subscription = source . subscribe ( on_next , on_error , on_completed ) <EOL> loop . run_until_complete ( go ( ) ) <EOL> assert ( all ( success ) ) <EOL> def test_future_dispose ( self ) : <EOL> loop = asyncio . get_event_loop ( ) <EOL> success = [ True , True , True ] <EOL> @ asyncio . coroutine <EOL> def go ( ) : <EOL> future = Future ( ) <EOL> future . set_result ( <NUM_LIT> ) <EOL> source = Observable . from_future ( future ) <EOL> def on_next ( x ) : <EOL> success [ <NUM_LIT:0> ] = False <EOL> def on_error ( err ) : <EOL> success [ <NUM_LIT:1> ] = False <EOL> def on_completed ( ) : <EOL> success [ <NUM_LIT:2> ] = False <EOL> subscription = source . subscribe ( on_next , on_error , on_completed ) <EOL> subscription . dispose ( ) <EOL> loop . run_until_complete ( go ( ) ) <EOL> assert ( all ( success ) ) </s>
