Skip to content

Commit 9627be7

Browse files
committed
Split version detection functionality into a BaseTestCase class.
This seems like a useful functionality so make it more easier to re-use this information.
1 parent f1f329d commit 9627be7

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

tests/integration/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@
2424
os.mkdir(path)
2525

2626

27+
class BaseTestCase(unittest.TestCase):
28+
def _get_cass_and_cql_version(self):
29+
"""
30+
Probe system.local table to determine Cassandra and CQL version.
31+
"""
32+
c = Cluster()
33+
s = c.connect()
34+
s.set_keyspace('system')
35+
row = s.execute('SELECT cql_version, release_version FROM local')[0]
36+
37+
cass_version = self._get_version_as_tuple(row.release_version)
38+
cql_version = self._get_version_as_tuple(row.cql_version)
39+
40+
c.shutdown()
41+
42+
result = {'cass_version': cass_version, 'cql_version': cql_version}
43+
return result
44+
45+
def _get_version_as_tuple(self, version):
46+
version = version.split('.')
47+
version = [int(p) for p in version]
48+
version = tuple(version)
49+
return version
50+
51+
2752
def get_cluster():
2853
return CCM_CLUSTER
2954

tests/integration/test_types.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@
1212
from cassandra import InvalidRequest
1313
from cassandra.cluster import Cluster, NoHostAvailable
1414

15+
from tests.integration import BaseTestCase
1516

16-
class TypeTests(unittest.TestCase):
17+
18+
class TypeTests(BaseTestCase):
1719
def setUp(self):
1820
super(TypeTests, self).setUp()
19-
20-
# Detect CQL and Cassandra version
21-
c = Cluster()
22-
s = c.connect()
23-
s.set_keyspace('system')
24-
row = s.execute('SELECT cql_version, release_version FROM local')[0]
25-
self._cql_version = self._get_version_as_tuple(row.cql_version)
26-
self._cass_version = self._get_version_as_tuple(row.release_version)
21+
self._versions = self._get_cass_and_cql_version()
2722

2823
def test_blob_type_as_string(self):
2924
c = Cluster()
@@ -49,7 +44,7 @@ def test_blob_type_as_string(self):
4944

5045
query = 'INSERT INTO mytable (a, b) VALUES (%s, %s)'
5146

52-
if self._cql_version >= (3, 1, 0):
47+
if self._versions['cql_version'] >= (3, 1, 0):
5348
# Blob values can't be specified using string notation in CQL 3.1.0 and
5449
# above which is used by default in Cassandra 2.0.
5550
msg = r'.*Invalid STRING constant \(.*?\) for b of type blob.*'

0 commit comments

Comments
 (0)