@@ -120,9 +120,9 @@ class Meta:
120
120
AttributeError , cls , ** {'time' : 159 ,
121
121
'server_name' : 'us.east-1' })
122
122
123
- def testWarnings (self ):
123
+ def testWarnBulkSizeZero (self ):
124
124
'''
125
- Tests warnings for code coverage test .
125
+ Tests warning for an invalid bulk size .
126
126
'''
127
127
class WarnBulkSizeZero (SeriesHelper ):
128
128
@@ -133,6 +133,24 @@ class Meta:
133
133
bulk_size = 0
134
134
autocommit = True
135
135
136
+ with warnings .catch_warnings (record = True ) as w :
137
+ warnings .simplefilter ("always" )
138
+ try :
139
+ WarnBulkSizeZero (time = 159 , server_name = 'us.east-1' )
140
+ except ConnectionError :
141
+ # Server defined in the client is invalid, we're testing
142
+ # the warning only.
143
+ pass
144
+ self .assertEqual (len (w ), 1 ,
145
+ '{} call should have generated one warning.'
146
+ .format (WarnBulkSizeZero ))
147
+ self .assertIn ('forced to 1' , str (w [- 1 ].message ),
148
+ 'Warning message did not contain "forced to 1".' )
149
+
150
+ def testWarnBulkSizeNoEffect (self ):
151
+ '''
152
+ Tests warning for a set bulk size but autocommit False.
153
+ '''
136
154
class WarnBulkSizeNoEffect (SeriesHelper ):
137
155
138
156
class Meta :
@@ -141,15 +159,11 @@ class Meta:
141
159
bulk_size = 5
142
160
autocommit = False
143
161
144
- for cls in [WarnBulkSizeNoEffect , WarnBulkSizeZero ]:
145
- with warnings .catch_warnings (record = True ) as w :
146
- warnings .simplefilter ("always" )
147
- try :
148
- cls (time = 159 , server_name = 'us.east-1' )
149
- except ConnectionError :
150
- # Server defined in the client is invalid, we're testing
151
- # the warning only.
152
- pass
153
- self .assertEqual (len (w ), 1 ,
154
- '{} call should have generated one warning.'
155
- .format (cls ))
162
+ with warnings .catch_warnings (record = True ) as w :
163
+ warnings .simplefilter ("always" )
164
+ WarnBulkSizeNoEffect (time = 159 , server_name = 'us.east-1' )
165
+ self .assertEqual (len (w ), 1 ,
166
+ '{} call should have generated one warning.'
167
+ .format (WarnBulkSizeNoEffect ))
168
+ self .assertIn ('has no affect' , str (w [- 1 ].message ),
169
+ 'Warning message did not contain "has not affect".' )
0 commit comments