#NEWLINE# def testReachDefGCD( self ) : #NEWLINE# #INDENT# n1 = self . _CreateMockNode ( 'n1' , 0 , [ ( [ 'a' ] , 'c' ) , ( [ 'b' ] , 'd' ) ] ) #NEWLINE# n2 = self . _CreateMockNode ( 'n2' , 2 , [ ( [ 'c' ] , None ) ] ) #NEWLINE# n3 = self . _CreateMockNode ( 'n3' , 3 , [ ( [ 'd' ] , 'ret' ) ] ) #NEWLINE# n4 = self . _CreateMockNode ( 'n4' , 4 , [ ( [ 'd' ] , None ) ] ) #NEWLINE# n5 = self . _CreateMockNode ( 'n5' , 5 , [ ( [ 'c' , 'd' ] , None ) ] ) #NEWLINE# n6 = self . _CreateMockNode ( 'n6' , 6 , [ ( [ 'c' , 'd' ] , 'c' ) ] ) #NEWLINE# n7 = self . _CreateMockNode ( 'n7' , 7 , [ ( [ 'c' , 'd' ] , 'd' ) ] ) #NEWLINE# n8 = self . _CreateMockNode ( 'n8' , 8 , [ ( [ 'c' ] , 'ret' ) ] ) #NEWLINE# n9 = self . _CreateMockNode ( 'n9' , 9 , [ ( [ 'ret' ] , None ) ] ) #NEWLINE# sucs = { #NEWLINE# #INDENT# n1 : [ n2 ] , #NEWLINE# n2 : [ n3 , n4 ] , #NEWLINE# n3 : [ n9 ] , #NEWLINE# n4 : [ n5 , n8 ] , #NEWLINE# n5 : [ n6 , n7 ] , #NEWLINE# n6 : [ add_edge ] , #NEWLINE# n7 : [ n8 ] , #NEWLINE# n8 : [ n9 ] , #NEWLINE# #UNINDENT# } #NEWLINE# preds = collections . defaultdict ( list ) #NEWLINE# for ( pred , lsucs ) in sucs . iteritems ( ) : #NEWLINE# #INDENT# for suc in lsucs : #NEWLINE# #INDENT# preds [ suc ] . append ( pred ) #NEWLINE# #UNINDENT# #UNINDENT# def add_edge( x , y ) : #NEWLINE# #INDENT# sucs . setdefault ( x , [ ] ) . append ( y ) #NEWLINE# preds . setdefault ( y , [ ] ) . append ( x ) #NEWLINE# #UNINDENT# graph_mock = mock . create_autospec ( graph . Graph ) #NEWLINE# graph_mock . entry = n1 #NEWLINE# graph_mock . exit = n9 #NEWLINE# graph_mock . rpo = [ n1 , n2 , n3 , n4 , n5 , n6 , n7 , n8 , n9 ] #NEWLINE# graph_mock . all_preds . side_effect = ( lambda x : preds [ x ] ) #NEWLINE# graph_mock . all_sucs . side_effect = ( lambda x : sucs . get ( x , [ ] ) ) #NEWLINE# graph_mock . add_edge . side_effect = add_edge #NEWLINE# with mock . patch . object ( dataflow , 'DummyNode' ) as dummynode_mock : #NEWLINE# #INDENT# dummy_entry_mock = mock . Mock ( name = 'entry' ) #NEWLINE# dummy_exit_mock = mock . Mock ( name = 'exit' ) #NEWLINE# for dummy_mock in ( dummy_entry_mock , dummy_exit_mock ) : #NEWLINE# #INDENT# dummy_mock . get_loc_with_ins . return_value = [ ] #NEWLINE# #UNINDENT# dummynode_mock . side_effect = [ dummy_entry_mock , dummy_exit_mock ] #NEWLINE# analysis = dataflow . reach_def_analysis ( graph_mock , set ( [ 'a' , 'b' ] ) ) #NEWLINE# #UNINDENT# expected_A = { #NEWLINE# #INDENT# dummy_entry_mock : set ( [ ( - 2 ) , ( - 1 ) ] ) , #NEWLINE# n1 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n2 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n3 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 , 3 ] ) , #NEWLINE# n4 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n5 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n6 : set ( [ ( - 2 ) , ( - 1 ) , 1 , 6 ] ) , #NEWLINE# n7 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 7 ] ) , #NEWLINE# n8 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 , 6 , 7 , 8 ] ) , #NEWLINE# n9 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 , 3 , 6 , 7 , 8 ] ) , #NEWLINE# dummy_exit_mock : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 , 3 , 6 , 7 , 8 ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# expected_R = { #NEWLINE# #INDENT# n1 : set ( [ ( - 2 ) , ( - 1 ) ] ) , #NEWLINE# n2 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n3 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n4 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n5 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n6 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n7 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 ] ) , #NEWLINE# n8 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 , 6 , 7 ] ) , #NEWLINE# n9 : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 , 3 , 6 , 7 , 8 ] ) , #NEWLINE# dummy_exit_mock : set ( [ ( - 2 ) , ( - 1 ) , 0 , 1 , 3 , 6 , 7 , 8 ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# expected_def_to_loc = { #NEWLINE# #INDENT# 'a' : set ( [ ( - 1 ) ] ) , #NEWLINE# 'b' : set ( [ ( - 2 ) ] ) , #NEWLINE# 'c' : set ( [ 0 , 6 ] ) , #NEWLINE# 'd' : set ( [ 1 , 7 ] ) , #NEWLINE# 'ret' : set ( [ 3 , 8 ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertDictEqual ( analysis . A , expected_A ) #NEWLINE# self . assertDictEqual ( analysis . R , expected_R ) #NEWLINE# self . assertDictEqual ( analysis . def_to_loc , expected_def_to_loc )