#NEWLINE# def _roundtrip( self , Employee , Manager , Engineer , Boss , polymorphic = True , explicit_type = False ) : #NEWLINE# #INDENT# Base . metadata . create_all ( ) #NEWLINE# sess = create_session ( ) #NEWLINE# e1 = Engineer ( name = 'dilbert' , primary_language = 'java' ) #NEWLINE# e2 = Engineer ( name = 'wally' , primary_language = 'c++' ) #NEWLINE# m1 = Manager ( name = 'dogbert' , golf_swing = 'fore!' ) #NEWLINE# e3 = Engineer ( name = 'vlad' , primary_language = 'cobol' ) #NEWLINE# b1 = Boss ( name = 'pointy haired' ) #NEWLINE# if polymorphic : #NEWLINE# #INDENT# for obj in [ e1 , e2 , m1 , e3 , b1 ] : #NEWLINE# #INDENT# if explicit_type : #NEWLINE# #INDENT# eq_ ( obj . type , obj . __mapper__ . polymorphic_identity ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert_raises_message ( AttributeError , "does not implement attribute .?'type' at the instance level." , getattr , obj , 'type' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# assert ( 'type' not in Engineer . __dict__ ) #NEWLINE# assert ( 'type' not in Manager . __dict__ ) #NEWLINE# assert ( 'type' not in Boss . __dict__ ) #NEWLINE# #UNINDENT# sess . add_all ( [ e1 , e2 , e3 , e3 , b1 ] ) #NEWLINE# sess . flush ( ) #NEWLINE# sess . expunge_all ( ) #NEWLINE# if polymorphic : #NEWLINE# #INDENT# eq_ ( sess . query ( Employee ) . order_by ( Employee . name ) . all ( ) , [ Engineer ( name = 'dilbert' ) , Manager ( name = 'dogbert' ) , Boss ( name = 'pointy haired' ) , Engineer ( name = 'vlad' ) , Engineer ( name = 'wally' ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# eq_ ( sess . query ( Engineer ) . order_by ( Engineer . name ) . all ( ) , [ Engineer ( name = 'dilbert' ) , Engineer ( name = 'vlad' ) , Engineer ( name = 'wally' ) ] ) #NEWLINE# eq_ ( sess . query ( Manager ) . all ( ) , [ Manager ( name = 'dogbert' ) ] ) #NEWLINE# eq_ ( sess . query ( Boss ) . all ( ) , [ Boss ( name = 'pointy haired' ) ] )