17
17
import logging .handlers
18
18
from sqlalchemy .dialects .oracle .zxjdbc import ReturningParam
19
19
from sqlalchemy .engine import result as _result , default
20
- from sqlalchemy .engine .base import Connection , Engine
20
+ from sqlalchemy .engine .base import Engine
21
21
from sqlalchemy .testing import fixtures
22
- from sqlalchemy .testing .mock import Mock , call
22
+ from sqlalchemy .testing .mock import Mock , call , patch
23
23
24
24
25
25
users , metadata , users_autoinc = None , None , None
@@ -29,11 +29,11 @@ def setup_class(cls):
29
29
global users , users_autoinc , metadata
30
30
metadata = MetaData (testing .db )
31
31
users = Table ('users' , metadata ,
32
- Column ('user_id' , INT , primary_key = True , autoincrement = False ),
32
+ Column ('user_id' , INT , primary_key = True , autoincrement = False ),
33
33
Column ('user_name' , VARCHAR (20 )),
34
34
)
35
35
users_autoinc = Table ('users_autoinc' , metadata ,
36
- Column ('user_id' , INT , primary_key = True ,
36
+ Column ('user_id' , INT , primary_key = True ,
37
37
test_needs_autoincrement = True ),
38
38
Column ('user_name' , VARCHAR (20 )),
39
39
)
@@ -892,42 +892,42 @@ def __getitem__(self, i):
892
892
def test_no_rowcount_on_selects_inserts (self ):
893
893
"""assert that rowcount is only called on deletes and updates.
894
894
895
- This because cursor.rowcount can be expensive on some dialects
896
- such as Firebird.
895
+ This because cursor.rowcount may can be expensive on some dialects
896
+ such as Firebird, however many dialects require it be called
897
+ before the cursor is closed.
897
898
898
899
"""
899
900
900
901
metadata = self .metadata
901
902
902
903
engine = engines .testing_engine ()
903
- metadata .bind = engine
904
904
905
905
t = Table ('t1' , metadata ,
906
906
Column ('data' , String (10 ))
907
907
)
908
- metadata .create_all ()
908
+ metadata .create_all (engine )
909
909
910
- class BreakRowcountMixin (object ):
911
- @property
912
- def rowcount (self ):
913
- assert False
910
+ with patch .object (engine .dialect .execution_ctx_cls , "rowcount" ) as mock_rowcount :
911
+ mock_rowcount .__get__ = Mock ()
912
+ engine .execute (t .insert (),
913
+ {'data' : 'd1' },
914
+ {'data' : 'd2' },
915
+ {'data' : 'd3' })
914
916
915
- execution_ctx_cls = engine .dialect .execution_ctx_cls
916
- engine .dialect .execution_ctx_cls = type ("FakeCtx" ,
917
- (BreakRowcountMixin ,
918
- execution_ctx_cls ),
919
- {})
917
+ eq_ (len (mock_rowcount .__get__ .mock_calls ), 0 )
920
918
921
- try :
922
- r = t .insert ().execute ({'data' : 'd1' }, {'data' : 'd2' },
923
- {'data' : 'd3' })
924
- eq_ (t .select ().execute ().fetchall (), [('d1' , ), ('d2' , ),
925
- ('d3' , )])
926
- assert_raises (AssertionError , t .update ().execute , {'data'
927
- : 'd4' })
928
- assert_raises (AssertionError , t .delete ().execute )
929
- finally :
930
- engine .dialect .execution_ctx_cls = execution_ctx_cls
919
+ eq_ (
920
+ engine .execute (t .select ()).fetchall (),
921
+ [('d1' , ), ('d2' , ), ('d3' , )]
922
+ )
923
+ eq_ (len (mock_rowcount .__get__ .mock_calls ), 0 )
924
+
925
+ engine .execute (t .update (), {'data' : 'd4' })
926
+
927
+ eq_ (len (mock_rowcount .__get__ .mock_calls ), 1 )
928
+
929
+ engine .execute (t .delete ())
930
+ eq_ (len (mock_rowcount .__get__ .mock_calls ), 2 )
931
931
932
932
933
933
@testing .requires .python26
0 commit comments