Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions tests/unit/test_resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
except ImportError:
import unittest # noqa

from mock import Mock, PropertyMock
from mock import Mock, PropertyMock, patch

from cassandra.cluster import ResultSet

Expand Down Expand Up @@ -195,19 +195,15 @@ def test_one(self):

self.assertEqual(rs.one(), first)

def test_indexing_deprecation(self):
import warnings

@patch('cassandra.cluster.warn')
def test_indexing_deprecation(self, mocked_warn):
# normally we'd use catch_warnings to test this, but that doesn't work
# pre-Py3.0 for some reason
first, second = Mock(), Mock()
rs = ResultSet(Mock(has_more_pages=False), [first, second])
self.assertEqual(rs[0], first)

with warnings.catch_warnings(record=True) as ws:
# catch_warnings restores original filter on close
warnings.simplefilter('always')
rs[0]
self.assertEqual(len(ws), 1)
index_warning = ws[0]
self.assertIs(index_warning.category, DeprecationWarning)
self.assertEqual(len(mocked_warn.mock_calls), 1)
index_warning_args = tuple(mocked_warn.mock_calls[0])[1]
self.assertIn('indexing support will be removed in 4.0',
str(index_warning.message))
str(index_warning_args[0]))
self.assertIs(index_warning_args[1], DeprecationWarning)