<s> import time <EOL> import unittest <EOL> import rpyc <EOL> class TestAsync ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . conn = rpyc . classic . connect_thread ( ) <EOL> self . a_sleep = rpyc . async ( self . conn . modules . time . sleep ) <EOL> self . a_int = rpyc . async ( self . conn . builtin . int ) <EOL> def tearDown ( self ) : <EOL> self . conn . close ( ) <EOL> def test_asyncresult_api ( self ) : <EOL> res = self . a_sleep ( <NUM_LIT:2> ) <EOL> self . assertFalse ( res . ready ) <EOL> res . wait ( ) <EOL> self . assertTrue ( res . ready ) <EOL> self . assertFalse ( res . expired ) <EOL> self . assertFalse ( res . error ) <EOL> self . assertEqual ( res . value , None ) <EOL> def test_asyncresult_expiry ( self ) : <EOL> res = self . a_sleep ( <NUM_LIT:5> ) <EOL> res . set_expiry ( <NUM_LIT:4> ) <EOL> t0 = time . time ( ) <EOL> self . assertRaises ( rpyc . AsyncResultTimeout , res . wait ) <EOL> dt = time . time ( ) - t0 <EOL> self . assertTrue ( dt >= <NUM_LIT> , str ( dt ) ) <EOL> self . assertTrue ( dt <= <NUM_LIT> , str ( dt ) ) <EOL> def test_asyncresult_callbacks ( self ) : <EOL> res = self . a_sleep ( <NUM_LIT:2> ) <EOL> visited = [ ] <EOL> def f ( res ) : <EOL> assert res . ready <EOL> assert not res . error <EOL> visited . append ( "<STR_LIT:f>" ) <EOL> def g ( res ) : <EOL> visited . append ( "<STR_LIT:g>" ) <EOL> res . add_callback ( f ) <EOL> res . add_callback ( g ) <EOL> res . wait ( ) <EOL> self . assertEqual ( set ( visited ) , set ( [ "<STR_LIT:f>" , "<STR_LIT:g>" ] ) ) <EOL> def test_timed ( self ) : <EOL> timed_sleep = rpyc . timed ( self . conn . modules . time . sleep , <NUM_LIT:5> ) <EOL> res = timed_sleep ( <NUM_LIT:3> ) <EOL> res . value <EOL> res = timed_sleep ( <NUM_LIT:7> ) <EOL> self . assertRaises ( rpyc . AsyncResultTimeout , lambda : res . value ) <EOL> def test_exceptions ( self ) : <EOL> res = self . a_int ( "<STR_LIT:foo>" ) <EOL> res . wait ( ) <EOL> self . assertTrue ( res . error ) <EOL> self . assertRaises ( ValueError , lambda : res . value ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
