<s> from sqlalchemy import * <EOL> from sqlalchemy import exc as sa_exc <EOL> from sqlalchemy . orm import * <EOL> from sqlalchemy . testing import assert_raises_message <EOL> from sqlalchemy . testing import fixtures <EOL> from sqlalchemy import testing <EOL> class CompileTest ( fixtures . ORMTest ) : <EOL> """<STR_LIT>""" <EOL> def teardown ( self ) : <EOL> clear_mappers ( ) <EOL> def test_with_polymorphic ( self ) : <EOL> metadata = MetaData ( testing . db ) <EOL> order = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) , <EOL> Column ( '<STR_LIT:type>' , Unicode ( <NUM_LIT:16> ) ) ) <EOL> employee = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT:name>' , Unicode ( <NUM_LIT:16> ) , unique = True , nullable = False ) ) <EOL> product = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> ) <EOL> orderproduct = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( "<STR_LIT>" ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( "<STR_LIT>" ) , nullable = False ) , <EOL> ) <EOL> class Order ( object ) : <EOL> pass <EOL> class Employee ( object ) : <EOL> pass <EOL> class Product ( object ) : <EOL> pass <EOL> class OrderProduct ( object ) : <EOL> pass <EOL> order_join = order . select ( ) . alias ( '<STR_LIT>' ) <EOL> order_mapper = mapper ( Order , order , <EOL> with_polymorphic = ( '<STR_LIT:*>' , order_join ) , <EOL> polymorphic_on = order_join . c . type , <EOL> polymorphic_identity = '<STR_LIT>' , <EOL> properties = { <EOL> '<STR_LIT>' : relationship ( OrderProduct , lazy = '<STR_LIT>' , backref = '<STR_LIT>' ) } <EOL> ) <EOL> mapper ( Product , product , <EOL> properties = { <EOL> '<STR_LIT>' : relationship ( OrderProduct , lazy = '<STR_LIT>' , backref = '<STR_LIT>' ) } <EOL> ) <EOL> mapper ( Employee , employee , <EOL> properties = { <EOL> '<STR_LIT>' : relationship ( Order , lazy = '<STR_LIT>' , backref = '<STR_LIT>' ) } ) <EOL> mapper ( OrderProduct , orderproduct ) <EOL> configure_mappers ( ) <EOL> def test_conflicting_backref_one ( self ) : <EOL> """<STR_LIT>""" <EOL> metadata = MetaData ( testing . db ) <EOL> order = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT:type>' , Unicode ( <NUM_LIT:16> ) ) ) <EOL> product = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> ) <EOL> orderproduct = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( "<STR_LIT>" ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( "<STR_LIT>" ) , nullable = False ) , <EOL> ) <EOL> class Order ( object ) : <EOL> pass <EOL> class Product ( object ) : <EOL> pass <EOL> class OrderProduct ( object ) : <EOL> pass <EOL> order_join = order . select ( ) . alias ( '<STR_LIT>' ) <EOL> order_mapper = mapper ( Order , order , <EOL> with_polymorphic = ( '<STR_LIT:*>' , order_join ) , <EOL> polymorphic_on = order_join . c . type , <EOL> polymorphic_identity = '<STR_LIT>' , <EOL> properties = { <EOL> '<STR_LIT>' : relationship ( OrderProduct , lazy = '<STR_LIT>' , backref = '<STR_LIT>' ) } <EOL> ) <EOL> mapper ( Product , product , <EOL> properties = { <EOL> '<STR_LIT>' : relationship ( OrderProduct , lazy = '<STR_LIT>' , backref = '<STR_LIT>' ) } <EOL> ) <EOL> mapper ( OrderProduct , orderproduct ) <EOL> assert_raises_message ( <EOL> sa_exc . ArgumentError , <EOL> "<STR_LIT>" , <EOL> configure_mappers <EOL> ) <EOL> def test_misc_one ( self ) : <EOL> metadata = MetaData ( testing . db ) <EOL> node_table = Table ( "<STR_LIT>" , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , nullable = True ) , <EOL> ) <EOL> node_name_table = Table ( "<STR_LIT>" , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:64> ) , nullable = False ) , <EOL> ) <EOL> host_table = Table ( "<STR_LIT:host>" , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:64> ) , nullable = False , <EOL> unique = True ) , <EOL> ) <EOL> metadata . create_all ( ) <EOL> try : <EOL> node_table . insert ( ) . execute ( node_id = <NUM_LIT:1> , node_index = <NUM_LIT:5> ) <EOL> class Node ( object ) : pass <EOL> class NodeName ( object ) : pass <EOL> class Host ( object ) : pass <EOL> node_mapper = mapper ( Node , node_table ) <EOL> host_mapper = mapper ( Host , host_table ) <EOL> node_name_mapper = mapper ( NodeName , node_name_table , <EOL> properties = { <EOL> '<STR_LIT>' : relationship ( Node , backref = backref ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:host>' : relationship ( Host ) , <EOL> } <EOL> ) <EOL> sess = create_session ( ) <EOL> assert sess . query ( Node ) . get ( <NUM_LIT:1> ) . names == [ ] <EOL> finally : <EOL> metadata . drop_all ( ) <EOL> def test_conflicting_backref_two ( self ) : <EOL> meta = MetaData ( ) <EOL> a = Table ( '<STR_LIT:a>' , meta , Column ( '<STR_LIT:id>' , Integer , primary_key = True ) ) <EOL> b = Table ( '<STR_LIT:b>' , meta , Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) ) <EOL> class A ( object ) : <EOL> pass <EOL> class B ( object ) : <EOL> pass <EOL> mapper ( A , a , properties = { <EOL> '<STR_LIT:b>' : relationship ( B , backref = '<STR_LIT:a>' ) <EOL> } ) <EOL> mapper ( B , b , properties = { <EOL> '<STR_LIT:a>' : relationship ( A , backref = '<STR_LIT:b>' ) <EOL> } ) <EOL> assert_raises_message ( <EOL> sa_exc . ArgumentError , <EOL> "<STR_LIT>" , <EOL> configure_mappers <EOL> ) <EOL> def test_conflicting_backref_subclass ( self ) : <EOL> meta = MetaData ( ) <EOL> a = Table ( '<STR_LIT:a>' , meta , Column ( '<STR_LIT:id>' , Integer , primary_key = True ) ) <EOL> b = Table ( '<STR_LIT:b>' , meta , Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) ) <EOL> class A ( object ) : <EOL> pass <EOL> class B ( object ) : <EOL> pass <EOL> class C ( B ) : <EOL> pass <EOL> mapper ( A , a , properties = { <EOL> '<STR_LIT:b>' : relationship ( B , backref = '<STR_LIT:a>' ) , <EOL> '<STR_LIT:c>' : relationship ( C , backref = '<STR_LIT:a>' ) <EOL> } ) <EOL> mapper ( B , b ) <EOL> mapper ( C , None , inherits = B ) <EOL> assert_raises_message ( <EOL> sa_exc . ArgumentError , <EOL> "<STR_LIT>" , <EOL> configure_mappers <EOL> ) </s>
