<s> from Cython . Compiler . ModuleNode import ModuleNode <EOL> from Cython . Compiler . Symtab import ModuleScope <EOL> from Cython . TestUtils import TransformTest <EOL> from Cython . Compiler . Visitor import MethodDispatcherTransform <EOL> from Cython . Compiler . ParseTreeTransforms import ( <EOL> NormalizeTree , AnalyseDeclarationsTransform , <EOL> AnalyseExpressionsTransform , InterpretCompilerDirectives ) <EOL> class TestMethodDispatcherTransform ( TransformTest ) : <EOL> _tree = None <EOL> def _build_tree ( self ) : <EOL> if self . _tree is None : <EOL> context = None <EOL> def fake_module ( node ) : <EOL> scope = ModuleScope ( '<STR_LIT:test>' , None , None ) <EOL> return ModuleNode ( node . pos , doc = None , body = node , <EOL> scope = scope , full_module_name = '<STR_LIT:test>' , <EOL> directive_comments = { } ) <EOL> pipeline = [ <EOL> fake_module , <EOL> NormalizeTree ( context ) , <EOL> InterpretCompilerDirectives ( context , { } ) , <EOL> AnalyseDeclarationsTransform ( context ) , <EOL> AnalyseExpressionsTransform ( context ) , <EOL> ] <EOL> self . _tree = self . run_pipeline ( pipeline , u"""<STR_LIT>""" ) <EOL> return self . _tree <EOL> def test_builtin_method ( self ) : <EOL> calls = [ <NUM_LIT:0> ] <EOL> class Test ( MethodDispatcherTransform ) : <EOL> def _handle_simple_method_dict_get ( self , node , func , args , unbound ) : <EOL> calls [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> return node <EOL> tree = self . _build_tree ( ) <EOL> Test ( None ) ( tree ) <EOL> self . assertEqual ( <NUM_LIT:1> , calls [ <NUM_LIT:0> ] ) <EOL> def test_binop_method ( self ) : <EOL> calls = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT:object>' : <NUM_LIT:0> } <EOL> class Test ( MethodDispatcherTransform ) : <EOL> def _handle_simple_method_bytes___mul__ ( self , node , func , args , unbound ) : <EOL> calls [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> return node <EOL> def _handle_simple_method_object___mul__ ( self , node , func , args , unbound ) : <EOL> calls [ '<STR_LIT:object>' ] += <NUM_LIT:1> <EOL> return node <EOL> tree = self . _build_tree ( ) <EOL> Test ( None ) ( tree ) <EOL> self . assertEqual ( <NUM_LIT:1> , calls [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , calls [ '<STR_LIT:object>' ] ) </s>
