8000 Merge pull request #173 from savoirfairelinux/enh_more_robust_helper_… · krishnazure/influxdb-python@6ef9938 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ef9938

Browse files
committed
Merge pull request influxdata#173 from savoirfairelinux/enh_more_robust_helper_test_for_influxdb08
Enh: updated tests to be less strict / more robust.
2 parents 941b5eb + cd44d9e commit 6ef9938

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

tests/influxdb/influxdb08/helper_test.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,26 @@ class Meta:
158158
bulk_size = 0
159159
autocommit = True
160160

161-
with warnings.catch_warnings(record=True) as w:
161+
with warnings.catch_warnings(record=True) as rec_warnings:
162162
warnings.simplefilter("always")
163-
try:
163+
# Server defined in the client is invalid, we're testing
164+
# the warning only.
165+
with self.assertRaises(ConnectionError):
164166
WarnBulkSizeZero(time=159, server_name='us.east-1')
165-
except ConnectionError:
166-
# Server defined in the client is invalid, we're testing
167-
# the warning only.
168-
pass
169-
self.assertEqual(len(w), 1,
170-
'{} call should have generated one warning.'
171-
.format(WarnBulkSizeZero))
172-
self.assertIn('forced to 1', str(w[-1].message),
173-
'Warning message did not contain "forced to 1".')
167+
168+
self.assertGreaterEqual(
169+
len(rec_warnings), 1,
170+
'{} call should have generated one warning.'
171+
'Actual generated warnings: {}'.format(
172+
WarnBulkSizeZero, '\n'.join(map(str, rec_warnings))))
173+
174+
expected_msg = (
175+
'Definition of bulk_size in WarnBulkSizeZero forced to 1, '
176+
'was less than 1.')
177+
178+
self.assertIn(expected_msg, list(w.message.args[0]
179+
for w in rec_warnings),
180+
'Warning message did not contain "forced to 1".')
174181

175182
def testWarnBulkSizeNoEffect(self):
176183
"""
@@ -184,11 +191,24 @@ class Meta:
184191
bulk_size = 5
185192
autocommit = False
186193

187-
with warnings.catch_warnings(record=True) as w:
194+
with warnings.catch_warnings(record=True) as rec_warnings:
188195
warnings.simplefilter("always")
189196
WarnBulkSizeNoEffect(time=159, server_name='us.east-1')
190-
self.assertEqual(len(w), 1,
191-
'{} call should have generated one warning.'
192-
.format(WarnBulkSizeNoEffect))
193-
self.assertIn('has no affect', str(w[-1].message),
194-
'Warning message did not contain "has not affect".')
197+
198+
self.assertGreaterEqual(
199+
len(rec_warnings), 1,
200+
'{} call should have generated one warning.'
201+
'Actual generated warnings: {}'.format(
202+
WarnBulkSizeNoEffect, '\n'.join(map(str, rec_warnings))))
203+
204+
expected_msg = (
205+
'Definition of bulk_size in WarnBulkSizeNoEffect has no affect '
206+
'because autocommit is false.')
207+
208+
self.assertIn(expected_msg, list(w.message.args[0]
209+
for w in rec_warnings),
210+
'Warning message did not contain the expected_msg.')
211+
212+
213+
if __name__ == '__main__':
214+
unittest.main()

0 commit comments

Comments
 (0)
0