<s> from nose . tools import with_setup , eq_ as eq <EOL> from test_common import vim , cleanup <EOL> cid = vim . channel_id <EOL> @ with_setup ( setup = cleanup ) <EOL> def test_call_and_reply ( ) : <EOL> def setup_cb ( ) : <EOL> cmd = '<STR_LIT>' % cid <EOL> vim . command ( cmd ) <EOL> eq ( vim . vars [ '<STR_LIT:result>' ] , [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> vim . stop_loop ( ) <EOL> def request_cb ( name , args ) : <EOL> eq ( name , '<STR_LIT>' ) <EOL> eq ( args , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> return [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> vim . run_loop ( request_cb , None , setup_cb ) <EOL> @ with_setup ( setup = cleanup ) <EOL> def test_call_api_before_reply ( ) : <EOL> def setup_cb ( ) : <EOL> cmd = '<STR_LIT>' % cid <EOL> vim . command ( cmd ) <EOL> eq ( vim . vars [ '<STR_LIT:result>' ] , [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] ) <EOL> vim . stop_loop ( ) <EOL> def request_cb ( name , args ) : <EOL> vim . command ( '<STR_LIT>' ) <EOL> return vim . vars [ '<STR_LIT>' ] <EOL> vim . run_loop ( request_cb , None , setup_cb ) <EOL> @ with_setup ( setup = cleanup ) <EOL> def test_async_call ( ) : <EOL> def request_cb ( name , args ) : <EOL> if name == "<STR_LIT>" : <EOL> vim . vars [ '<STR_LIT:result>' ] = <NUM_LIT> <EOL> vim . stop_loop ( ) <EOL> vim . funcs . rpcrequest ( vim . channel_id , "<STR_LIT>" , async = True ) <EOL> vim . run_loop ( request_cb , None , None ) <EOL> eq ( vim . vars [ '<STR_LIT:result>' ] , <NUM_LIT> ) <EOL> @ with_setup ( setup = cleanup ) <EOL> def test_recursion ( ) : <EOL> def setup_cb ( ) : <EOL> vim . vars [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> vim . vars [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> vim . vars [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> vim . vars [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> cmd = '<STR_LIT>' % ( cid , <NUM_LIT:2> , ) <EOL> vim . command ( cmd ) <EOL> eq ( vim . vars [ '<STR_LIT>' ] , <NUM_LIT:4> ) <EOL> eq ( vim . vars [ '<STR_LIT>' ] , <NUM_LIT:8> ) <EOL> eq ( vim . vars [ '<STR_LIT>' ] , <NUM_LIT:16> ) <EOL> eq ( vim . vars [ '<STR_LIT>' ] , <NUM_LIT:32> ) <EOL> vim . stop_loop ( ) <EOL> def request_cb ( name , args ) : <EOL> n = args [ <NUM_LIT:0> ] <EOL> n *= <NUM_LIT:2> <EOL> if n <= <NUM_LIT:16> : <EOL> if n == <NUM_LIT:4> : <EOL> cmd = '<STR_LIT>' % ( cid , n , ) <EOL> elif n == <NUM_LIT:8> : <EOL> cmd = '<STR_LIT>' % ( cid , n , ) <EOL> elif n == <NUM_LIT:16> : <EOL> cmd = '<STR_LIT>' % ( cid , n , ) <EOL> vim . command ( cmd ) <EOL> return n <EOL> vim . run_loop ( request_cb , None , setup_cb ) </s>
