<s> from sqlalchemy import MetaData , Table , Column , String , Unicode , Integer , create_engine <EOL> from sqlalchemy . testing import fixtures , AssertsExecutionResults , profiling <EOL> from sqlalchemy import testing <EOL> from sqlalchemy . testing import eq_ <EOL> from sqlalchemy . util import u <EOL> from sqlalchemy . engine . result import RowProxy <EOL> import sys <EOL> NUM_FIELDS = <NUM_LIT:10> <EOL> NUM_RECORDS = <NUM_LIT:1000> <EOL> t = t2 = metadata = None <EOL> class ResultSetTest ( fixtures . TestBase , AssertsExecutionResults ) : <EOL> __backend__ = True <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> global t , t2 , metadata <EOL> metadata = MetaData ( testing . db ) <EOL> t = Table ( '<STR_LIT>' , metadata , * [ Column ( '<STR_LIT>' % fnum , String ( <NUM_LIT:50> ) ) <EOL> for fnum in range ( NUM_FIELDS ) ] ) <EOL> t2 = Table ( <EOL> '<STR_LIT>' , metadata , * <EOL> [ Column ( '<STR_LIT>' % fnum , Unicode ( <NUM_LIT:50> ) ) <EOL> for fnum in range ( NUM_FIELDS ) ] ) <EOL> def setup ( self ) : <EOL> metadata . create_all ( ) <EOL> t . insert ( ) . execute ( [ dict ( ( '<STR_LIT>' % fnum , u ( '<STR_LIT>' % fnum ) ) <EOL> for fnum in range ( NUM_FIELDS ) ) for r_num in <EOL> range ( NUM_RECORDS ) ] ) <EOL> t2 . insert ( ) . execute ( [ dict ( ( '<STR_LIT>' % fnum , u ( '<STR_LIT>' % fnum ) ) <EOL> for fnum in range ( NUM_FIELDS ) ) for r_num in <EOL> range ( NUM_RECORDS ) ] ) <EOL> t . select ( ) . execute ( ) . fetchall ( ) <EOL> t2 . select ( ) . execute ( ) . fetchall ( ) <EOL> def teardown ( self ) : <EOL> metadata . drop_all ( ) <EOL> @ profiling . function_call_count ( ) <EOL> def test_string ( self ) : <EOL> [ tuple ( row ) for row in t . select ( ) . execute ( ) . fetchall ( ) ] <EOL> @ profiling . function_call_count ( ) <EOL> def test_unicode ( self ) : <EOL> [ tuple ( row ) for row in t2 . select ( ) . execute ( ) . fetchall ( ) ] <EOL> def test_contains_doesnt_compile ( self ) : <EOL> row = t . select ( ) . execute ( ) . first ( ) <EOL> c1 = Column ( '<STR_LIT>' , Integer ) + Column ( "<STR_LIT>" , Integer ) <EOL> @ profiling . function_call_count ( ) <EOL> def go ( ) : <EOL> c1 in row <EOL> go ( ) <EOL> class ExecutionTest ( fixtures . TestBase ) : <EOL> __backend__ = True <EOL> def test_minimal_connection_execute ( self ) : <EOL> e = create_engine ( '<STR_LIT>' ) <EOL> c = e . connect ( ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> @ profiling . function_call_count ( ) <EOL> def go ( ) : <EOL> c . execute ( "<STR_LIT>" ) <EOL> try : <EOL> go ( ) <EOL> finally : <EOL> c . close ( ) <EOL> def test_minimal_engine_execute ( self , variance = <NUM_LIT> ) : <EOL> e = create_engine ( '<STR_LIT>' ) <EOL> e . execute ( "<STR_LIT>" ) <EOL> @ profiling . function_call_count ( ) <EOL> def go ( ) : <EOL> e . execute ( "<STR_LIT>" ) <EOL> go ( ) <EOL> class RowProxyTest ( fixtures . TestBase ) : <EOL> __requires__ = '<STR_LIT>' , <EOL> __backend__ = True <EOL> def _rowproxy_fixture ( self , keys , processors , row ) : <EOL> class MockMeta ( object ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> metadata = MockMeta ( ) <EOL> keymap = { } <EOL> for index , ( keyobjs , processor , values ) in enumerate ( list ( zip ( keys , processors , row ) ) ) : <EOL> for key in keyobjs : <EOL> keymap [ key ] = ( processor , key , index ) <EOL> keymap [ index ] = ( processor , key , index ) <EOL> return RowProxy ( metadata , row , processors , keymap ) <EOL> def _test_getitem_value_refcounts ( self , seq_factory ) : <EOL> col1 , col2 = object ( ) , object ( ) <EOL> def proc1 ( value ) : <EOL> return value <EOL> value1 , value2 = "<STR_LIT:x>" , "<STR_LIT:y>" <EOL> row = self . _rowproxy_fixture ( <EOL> [ ( col1 , "<STR_LIT:a>" ) , ( col2 , "<STR_LIT:b>" ) ] , <EOL> [ proc1 , None ] , <EOL> seq_factory ( [ value1 , value2 ] ) <EOL> ) <EOL> v1_refcount = sys . getrefcount ( value1 ) <EOL> v2_refcount = sys . getrefcount ( value2 ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> row [ col1 ] <EOL> row [ "<STR_LIT:a>" ] <EOL> row [ col2 ] <EOL> row [ "<STR_LIT:b>" ] <EOL> row [ <NUM_LIT:0> ] <EOL> row [ <NUM_LIT:1> ] <EOL> row [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> eq_ ( sys . getrefcount ( value1 ) , v1_refcount ) <EOL> eq_ ( sys . getrefcount ( value2 ) , v2_refcount ) <EOL> def test_value_refcounts_pure_tuple ( self ) : <EOL> self . _test_getitem_value_refcounts ( tuple ) <EOL> def test_value_refcounts_custom_seq ( self ) : <EOL> class CustomSeq ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . data = data <EOL> def __getitem__ ( self , item ) : <EOL> return self . data [ item ] <EOL> def __iter__ ( self ) : <EOL> return iter ( self . data ) <EOL> self . _test_getitem_value_refcounts ( CustomSeq ) </s>
