<s> from nose . tools import * <EOL> from lctools . shortcuts import get_node_or_fail <EOL> class TestShortCuts ( object ) : <EOL> def setup ( self ) : <EOL> class MyNode ( object ) : <EOL> def __init__ ( self , id ) : <EOL> self . id = id <EOL> class MyConn ( object ) : <EOL> def __init__ ( self , nodes ) : <EOL> self . nodes = nodes <EOL> def list_nodes ( self ) : <EOL> return self . nodes <EOL> self . node_cls = MyNode <EOL> self . conn_cls = MyConn <EOL> def test_that_get_node_or_fail_returns_node_object_for_existing_node ( self ) : <EOL> conn = self . conn_cls ( [ self . node_cls ( "<STR_LIT>" ) , self . node_cls ( "<STR_LIT>" ) ] ) <EOL> node = get_node_or_fail ( conn , "<STR_LIT>" ) <EOL> assert_equal ( node . id , "<STR_LIT>" ) <EOL> def test_that_get_node_or_fail_returns_none_in_fail_case ( self ) : <EOL> conn = self . conn_cls ( [ ] ) <EOL> node = get_node_or_fail ( conn , "<STR_LIT>" ) <EOL> assert_true ( node is None ) <EOL> def test_that_get_node_or_fail_calls_coroutine_in_fail_case ( self ) : <EOL> class CallableCheck ( object ) : <EOL> called = False <EOL> args = None <EOL> kwargs = None <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> self . called = True <EOL> self . args = args <EOL> self . kwargs = kwargs <EOL> coroutine = CallableCheck ( ) <EOL> cargs = ( "<STR_LIT>" , ) <EOL> ckwargs = { "<STR_LIT>" : "<STR_LIT>" } <EOL> conn = self . conn_cls ( [ ] ) <EOL> node = get_node_or_fail ( conn , "<STR_LIT>" , <EOL> coroutine , cargs , ckwargs ) <EOL> assert_true ( coroutine . called ) <EOL> assert_equal ( coroutine . args , cargs ) <EOL> assert_equal ( coroutine . kwargs , ckwargs ) </s>
