<s> import pytest <EOL> import sqlalchemy as sa <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> from nplusone . core import signals <EOL> import nplusone . ext . sqlalchemy <EOL> from tests import utils <EOL> Base = declarative_base ( ) <EOL> models = utils . make_models ( Base ) <EOL> @ pytest . fixture ( ) <EOL> def session ( ) : <EOL> engine = sa . create_engine ( '<STR_LIT>' ) <EOL> Session = sa . orm . sessionmaker ( bind = engine ) <EOL> Base . metadata . create_all ( bind = engine ) <EOL> return Session ( ) <EOL> @ pytest . fixture ( ) <EOL> def objects ( session ) : <EOL> hobby = models . Hobby ( ) <EOL> address = models . Address ( ) <EOL> user = models . User ( addresses = [ address ] , hobbies = [ hobby ] ) <EOL> session . add ( user ) <EOL> session . commit ( ) <EOL> session . close ( ) <EOL> class TestManyToOne : <EOL> def test_many_to_one ( self , session , objects , calls ) : <EOL> users = session . query ( models . User ) . all ( ) <EOL> users [ <NUM_LIT:0> ] . addresses <EOL> assert len ( calls ) == <NUM_LIT:1> <EOL> call = calls [ <NUM_LIT:0> ] <EOL> assert call . objects == ( models . User , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in '<STR_LIT>' . join ( call . frame [ <NUM_LIT:4> ] ) <EOL> def test_many_to_one_ignore ( self , session , objects , calls ) : <EOL> users = session . query ( models . User ) . all ( ) <EOL> with signals . ignore ( signals . lazy_load ) : <EOL> users [ <NUM_LIT:0> ] . addresses <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_many_to_one_subquery ( self , session , objects , calls ) : <EOL> users = session . query ( <EOL> models . User <EOL> ) . options ( <EOL> sa . orm . subqueryload ( '<STR_LIT>' ) <EOL> ) . all ( ) <EOL> users [ <NUM_LIT:0> ] . addresses <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_many_to_one_joined ( self , session , objects , calls ) : <EOL> users = session . query ( models . User ) . options ( sa . orm . joinedload ( '<STR_LIT>' ) ) . all ( ) <EOL> users [ <NUM_LIT:0> ] . addresses <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_many_to_one_reverse ( self , session , objects , calls ) : <EOL> addresses = session . query ( models . Address ) . all ( ) <EOL> addresses [ <NUM_LIT:0> ] . user <EOL> assert len ( calls ) == <NUM_LIT:1> <EOL> call = calls [ <NUM_LIT:0> ] <EOL> assert call . objects == ( models . Address , '<STR_LIT>' , '<STR_LIT:user>' ) <EOL> assert '<STR_LIT>' in '<STR_LIT>' . join ( call . frame [ <NUM_LIT:4> ] ) <EOL> def test_many_to_one_reverse_subquery ( self , session , objects , calls ) : <EOL> addresses = session . query ( <EOL> models . Address <EOL> ) . options ( <EOL> sa . orm . subqueryload ( '<STR_LIT:user>' ) <EOL> ) . all ( ) <EOL> addresses [ <NUM_LIT:0> ] . user <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_many_to_one_reverse_joined ( self , session , objects , calls ) : <EOL> address = session . query ( models . Address ) . options ( sa . orm . joinedload ( '<STR_LIT:user>' ) ) . first ( ) <EOL> address . user <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> class TestManyToMany : <EOL> def test_many_to_many ( self , session , objects , calls ) : <EOL> users = session . query ( models . User ) . all ( ) <EOL> users [ <NUM_LIT:0> ] . hobbies <EOL> assert len ( calls ) == <NUM_LIT:1> <EOL> call = calls [ <NUM_LIT:0> ] <EOL> assert call . objects == ( models . User , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in '<STR_LIT>' . join ( call . frame [ <NUM_LIT:4> ] ) <EOL> def test_many_to_many_subquery ( self , session , objects , calls ) : <EOL> user = session . query ( models . User ) . options ( sa . orm . subqueryload ( '<STR_LIT>' ) ) . first ( ) <EOL> user . hobbies <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_many_to_many_joined ( self , session , objects , calls ) : <EOL> user = session . query ( models . User ) . options ( sa . orm . joinedload ( '<STR_LIT>' ) ) . first ( ) <EOL> user . hobbies <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_many_to_many_reverse ( self , session , objects , calls ) : <EOL> hobbies = session . query ( models . Hobby ) . all ( ) <EOL> hobbies [ <NUM_LIT:0> ] . users <EOL> assert len ( calls ) == <NUM_LIT:1> <EOL> call = calls [ <NUM_LIT:0> ] <EOL> assert call . objects == ( models . Hobby , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in '<STR_LIT>' . join ( call . frame [ <NUM_LIT:4> ] ) <EOL> def test_many_to_many_reverse_subquery ( self , session , objects , calls ) : <EOL> hobby = session . query ( models . Hobby ) . options ( sa . orm . subqueryload ( '<STR_LIT>' ) ) . first ( ) <EOL> hobby . users <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_many_to_many_reverse_joined ( self , session , objects , calls ) : <EOL> hobby = session . query ( models . Hobby ) . options ( sa . orm . joinedload ( '<STR_LIT>' ) ) . first ( ) <EOL> hobby . users <EOL> assert len ( calls ) == <NUM_LIT:0> <EOL> def test_non_orm_query ( session , objects , lazy_listener ) : <EOL> session . query ( models . Address . id ) . all ( ) </s>
