|
18 | 18 | except ImportError: |
19 | 19 | import unittest # noqa |
20 | 20 |
|
21 | | -from mock import Mock, PropertyMock |
| 21 | +from mock import Mock, PropertyMock, patch |
22 | 22 |
|
23 | 23 | from cassandra.cluster import ResultSet |
24 | 24 |
|
@@ -195,19 +195,15 @@ def test_one(self): |
195 | 195 |
|
196 | 196 | self.assertEqual(rs.one(), first) |
197 | 197 |
|
198 | | - def test_indexing_deprecation(self): |
199 | | - import warnings |
200 | | - |
| 198 | + @patch('cassandra.cluster.warn') |
| 199 | + def test_indexing_deprecation(self, mocked_warn): |
| 200 | + # normally we'd use catch_warnings to test this, but that doesn't work |
| 201 | + # pre-Py3.0 for some reason |
201 | 202 | first, second = Mock(), Mock() |
202 | 203 | rs = ResultSet(Mock(has_more_pages=False), [first, second]) |
203 | 204 | self.assertEqual(rs[0], first) |
204 | | - |
205 | | - with warnings.catch_warnings(record=True) as ws: |
206 | | - # catch_warnings restores original filter on close |
207 | | - warnings.simplefilter('always') |
208 | | - rs[0] |
209 | | - self.assertEqual(len(ws), 1) |
210 | | - index_warning = ws[0] |
211 | | - self.assertIs(index_warning.category, DeprecationWarning) |
| 205 | + self.assertEqual(len(mocked_warn.mock_calls), 1) |
| 206 | + index_warning_args = tuple(mocked_warn.mock_calls[0])[1] |
212 | 207 | self.assertIn('indexing support will be removed in 4.0', |
213 | | - str(index_warning.message)) |
| 208 | + str(index_warning_args[0])) |
| 209 | + self.assertIs(index_warning_args[1], DeprecationWarning) |
0 commit comments