<s> import pytest <EOL> from mock import Mock <EOL> from calvin . utilities . calvin_callback import CalvinCB , CalvinCBGroup , CalvinCBClass <EOL> pytestmark = pytest . mark . unittest <EOL> def test_call_callback ( ) : <EOL> func = Mock ( ) <EOL> cb = CalvinCB ( func = func ) <EOL> cb ( ) <EOL> assert func . called <EOL> def test_call_callback_with_args ( ) : <EOL> func = Mock ( ) <EOL> cb = CalvinCB ( func , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> cb ( ) <EOL> func . assert_called_with ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> def test_call_callback_with_kwargs ( ) : <EOL> func = Mock ( ) <EOL> cb = CalvinCB ( func , a = <NUM_LIT:1> , b = <NUM_LIT:2> , c = <NUM_LIT:3> ) <EOL> cb ( ) <EOL> func . assert_called_with ( a = <NUM_LIT:1> , b = <NUM_LIT:2> , c = <NUM_LIT:3> ) <EOL> def test_args_update ( ) : <EOL> func = Mock ( ) <EOL> cb = CalvinCB ( func , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> cb . args_append ( <NUM_LIT:3> ) <EOL> cb ( ) <EOL> func . assert_called_with ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> def test_kwargs_update ( ) : <EOL> func = Mock ( ) <EOL> cb = CalvinCB ( func , <NUM_LIT:1> , b = <NUM_LIT:2> ) <EOL> cb . kwargs_update ( c = <NUM_LIT:3> ) <EOL> cb ( ) <EOL> func . assert_called_with ( <NUM_LIT:1> , b = <NUM_LIT:2> , c = <NUM_LIT:3> ) <EOL> def test_calvin_cb_group ( ) : <EOL> func1 = Mock ( ) <EOL> func2 = Mock ( ) <EOL> cb1 = CalvinCB ( func1 ) <EOL> cb2 = CalvinCB ( func2 ) <EOL> cbs = CalvinCBGroup ( [ cb1 , cb2 ] ) <EOL> cbs ( <NUM_LIT:1> , <NUM_LIT:2> , a = <NUM_LIT:3> ) <EOL> func1 . assert_called_with ( <NUM_LIT:1> , <NUM_LIT:2> , a = <NUM_LIT:3> ) <EOL> func2 . assert_called_with ( <NUM_LIT:1> , <NUM_LIT:2> , a = <NUM_LIT:3> ) <EOL> def test_calvin_cb_class ( ) : <EOL> func = Mock ( ) <EOL> cb = CalvinCB ( func ) <EOL> func2 = Mock ( ) <EOL> cb2 = CalvinCB ( func2 ) <EOL> cb = CalvinCBClass ( callbacks = { '<STR_LIT:f>' : [ cb ] } ) <EOL> assert '<STR_LIT:f>' in cb . callback_valid_names ( ) <EOL> cb . callback_register ( '<STR_LIT>' , cb2 ) <EOL> assert '<STR_LIT>' in cb . callback_valid_names ( ) <EOL> cb . callback_unregister ( cb2 . id ) <EOL> assert '<STR_LIT>' not in cb . callback_valid_names ( ) <EOL> cb . _callback_execute ( '<STR_LIT:f>' , <NUM_LIT:1> , <NUM_LIT:2> , a = <NUM_LIT:3> ) <EOL> func . assert_called_with ( <NUM_LIT:1> , <NUM_LIT:2> , a = <NUM_LIT:3> ) </s>
