Repository: cassandra-dtest
Updated Branches:
  refs/heads/master f4eda3a50 -> 49b2dda4e


http://git-wip-us.apache.org/repos/asf/cassandra-dtest/blob/49b2dda4/user_types_test.py
----------------------------------------------------------------------
diff --git a/user_types_test.py b/user_types_test.py
index 7ca06dc..b172a47 100644
--- a/user_types_test.py
+++ b/user_types_test.py
@@ -1,12 +1,19 @@
 import time
 import uuid
+import pytest
+import logging
+
+from flaky import flaky
 
 from cassandra import ConsistencyLevel, Unauthorized
 from cassandra.query import SimpleStatement
 
 from dtest import Tester, create_ks
 from tools.assertions import assert_invalid
-from tools.decorators import since
+from plugins.assert_tools import assert_regexp_matches
+
+since = pytest.mark.since
+logger = logging.getLogger(__name__)
 
 
 def listify(item):
@@ -23,13 +30,13 @@ def listify(item):
 
 class TestUserTypes(Tester):
     def assertUnauthorized(self, session, query, message):
-        with self.assertRaises(Unauthorized) as cm:
+        with pytest.raises(Unauthorized) as cm:
             session.execute(query)
-        self.assertRegexpMatches(cm.exception.message, message)
+            assert_regexp_matches(repr(cm._excinfo[1]), message)
 
     def assertNoTypes(self, session):
-        for keyspace in session.cluster.metadata.keyspaces.values():
-            self.assertEqual(0, len(keyspace.user_types))
+        for keyspace in list(session.cluster.metadata.keyspaces.values()):
+            assert 0 == len(keyspace.user_types)
 
     def test_type_dropping(self):
         """
@@ -190,7 +197,7 @@ class TestUserTypes(Tester):
               SELECT * FROM simple_table;
            """
         rows = list(session.execute(stmt))
-        self.assertEqual(0, len(rows))
+        assert 0 == len(rows)
 
     def test_nested_user_types(self):
         """Tests user types within user types"""
@@ -285,12 +292,12 @@ class TestUserTypes(Tester):
         rows = list(session.execute(stmt))
 
         primary_item, other_items, other_containers = rows[0]
-        self.assertEqual(listify(primary_item), [u'test', u'test2'])
-        self.assertEqual(listify(other_items), [u'stuff', [u'one', u'two']])
-        self.assertEqual(listify(other_containers), [[u'stuff2', 
[u'one_other', u'two_other']], [u'stuff3', [u'one_2_other', u'two_2_other']], 
[u'stuff4', [u'one_3_other', u'two_3_other']]])
+        assert listify(primary_item) == ['test', 'test2']
+        assert listify(other_items) == ['stuff', ['one', 'two']]
+        assert listify(other_containers) == [['stuff2', ['one_other', 
'two_other']], ['stuff3', ['one_2_other', 'two_2_other']], ['stuff4', 
['one_3_other', 'two_3_other']]]
 
         #  Generate some repetitive data and check it for it's contents:
-        for x in xrange(50):
+        for x in range(50):
 
             # Create row:
             _id = uuid.uuid4()
@@ -323,7 +330,7 @@ class TestUserTypes(Tester):
             rows = list(session.execute(stmt))
 
             items = rows[0][0]
-            self.assertEqual(listify(items), [[u'stuff3', [u'one_2_other', 
u'two_2_other']], [u'stuff4', [u'one_3_other', u'two_3_other']]])
+            assert listify(items) == [['stuff3', ['one_2_other', 
'two_2_other']], ['stuff4', ['one_3_other', 'two_3_other']]]
 
     def test_type_as_part_of_pkey(self):
         """Tests user types as part of a composite pkey"""
@@ -382,9 +389,10 @@ class TestUserTypes(Tester):
         rows = session.execute(stmt)
 
         row_uuid, first_name, like = rows[0]
-        self.assertEqual(first_name, u'Nero')
-        self.assertEqual(like, u'arson')
+        assert first_name == 'Nero'
+        assert like == 'arson'
 
+    @flaky
     def test_type_secondary_indexing(self):
         """
         Confirm that user types are secondary-indexable
@@ -426,7 +434,7 @@ class TestUserTypes(Tester):
               SELECT * from person_likes where name = {first:'Nero', middle: 
'Claudius Caesar Augustus', last: 'Germanicus'};
             """
         rows = list(session.execute(stmt))
-        self.assertEqual(0, len(rows))
+        assert 0 == len(rows)
 
         # add a row which doesn't specify data for the indexed column, and 
query again
         _id = uuid.uuid4()
@@ -441,7 +449,7 @@ class TestUserTypes(Tester):
             """
 
         rows = list(session.execute(stmt))
-        self.assertEqual(0, len(rows))
+        assert 0 == len(rows)
 
         # finally let's add a queryable row, and get it back using the index
         _id = uuid.uuid4()
@@ -460,9 +468,9 @@ class TestUserTypes(Tester):
 
         row_uuid, first_name, like = rows[0]
 
-        self.assertEqual(str(row_uuid), str(_id))
-        self.assertEqual(first_name, u'Nero')
-        self.assertEqual(like, u'arson')
+        assert str(row_uuid) == str(_id)
+        assert first_name == 'Nero'
+        assert like == 'arson'
 
         # rename a field in the type and make sure the index still works
         stmt = """
@@ -478,9 +486,9 @@ class TestUserTypes(Tester):
 
         row_uuid, first_name, like = rows[0]
 
-        self.assertEqual(str(row_uuid), str(_id))
-        self.assertEqual(first_name, u'Nero')
-        self.assertEqual(like, u'arson')
+        assert str(row_uuid) == str(_id)
+        assert first_name == 'Nero'
+        assert like == 'arson'
 
         # add another row to be sure the index is still adding new data
         _id = uuid.uuid4()
@@ -499,15 +507,15 @@ class TestUserTypes(Tester):
 
         row_uuid, first_name, like = rows[0]
 
-        self.assertEqual(str(row_uuid), str(_id))
-        self.assertEqual(first_name, u'Abraham')
-        self.assertEqual(like, u'preserving unions')
+        assert str(row_uuid) == str(_id)
+        assert first_name == 'Abraham'
+        assert like == 'preserving unions'
 
     def test_type_keyspace_permission_isolation(self):
         """
         Confirm permissions are respected for types in different keyspaces
         """
-        self.ignore_log_patterns = [
+        self.fixture_dtest_setup.ignore_log_patterns = [
             # I think this happens when permissions change and a node becomes 
temporarily unavailable
             # and it's probably ok to ignore on this test, as I can see the 
schema changes propogating
             # almost immediately after
@@ -609,10 +617,10 @@ class TestUserTypes(Tester):
         session.execute("INSERT INTO bucket (id, my_item) VALUES (1, {sub_one: 
'test'})")
 
         rows = list(session.execute("SELECT my_item FROM bucket WHERE id=0"))
-        self.assertEqual(listify(rows[0]), [[u'test', None]])
+        assert listify(rows[0]) == [['test', None]]
 
         rows = list(session.execute("SELECT my_item FROM bucket WHERE id=1"))
-        self.assertEqual(listify(rows[0]), [[u'test', None]])
+        assert listify(rows[0]) == [['test', None]]
 
     def test_no_counters_in_user_types(self):
         # CASSANDRA-7672
@@ -665,7 +673,7 @@ class TestUserTypes(Tester):
 
         # create a bit of data and expect a natural order based on clustering 
user types
 
-        ids = range(1, 10)
+        ids = list(range(1, 10))
 
         for _id in ids:
             session.execute("INSERT INTO letters (id, letterpair) VALUES ({}, 
{{first:'a', second:'z'}})".format(_id))
@@ -678,10 +686,10 @@ class TestUserTypes(Tester):
         for _id in ids:
             res = list(session.execute("SELECT letterpair FROM letters where 
id = {}".format(_id)))
 
-            self.assertEqual(listify(res), [[[u'a', u'z']], [[u'c', u'a']], 
[[u'c', u'f']], [[u'c', u'z']], [[u'd', u'e']], [[u'z', u'a']]])
+            assert listify(res) == [[['a', 'z']], [['c', 'a']], [['c', 'f']], 
[['c', 'z']], [['d', 'e']], [['z', 'a']]]
 
     @since('3.6')
-    def udt_subfield_test(self):
+    def test_udt_subfield(self):
         """
         @jira_ticket CASSANDRA-7423
         @since 3.6
@@ -701,7 +709,7 @@ class TestUserTypes(Tester):
         session.execute("INSERT INTO t (id, v) VALUES (0, {third: 2, second: 
1})")
         session.execute("UPDATE t set v.first = 'a' WHERE id=0")
         rows = list(session.execute("SELECT * FROM t WHERE id = 0"))
-        self.assertEqual(listify(rows), [[0, ['a', 1, 2]]])
+        assert listify(rows) == [[0, ['a', 1, 2]]]
 
         # Create a full udt
         # Update a subfield on the udt
@@ -709,13 +717,13 @@ class TestUserTypes(Tester):
         session.execute("INSERT INTO t (id, v) VALUES (0, {first: 'c', second: 
3, third: 33})")
         session.execute("UPDATE t set v.second = 5 where id=0")
         rows = list(session.execute("SELECT * FROM t WHERE id=0"))
-        self.assertEqual(listify(rows), [[0, ['c', 5, 33]]])
+        assert listify(rows) == [[0, ['c', 5, 33]]]
 
         # Rewrite the entire udt
         # Read back
         session.execute("INSERT INTO t (id, v) VALUES (0, {first: 'alpha', 
second: 111, third: 100})")
         rows = list(session.execute("SELECT * FROM t WHERE id=0"))
-        self.assertEqual(listify(rows), [[0, ['alpha', 111, 100]]])
+        assert listify(rows) == [[0, ['alpha', 111, 100]]]
 
         # Send three subfield updates to udt
         # Read back
@@ -723,7 +731,7 @@ class TestUserTypes(Tester):
         session.execute("UPDATE t set v.first = 'delta' WHERE id=0")
         session.execute("UPDATE t set v.second = -10 WHERE id=0")
         rows = list(session.execute("SELECT * FROM t WHERE id=0"))
-        self.assertEqual(listify(rows), [[0, ['delta', -10, 100]]])
+        assert listify(rows) == [[0, ['delta', -10, 100]]]
 
         # Send conflicting updates serially to different nodes
         # Read back
@@ -736,7 +744,7 @@ class TestUserTypes(Tester):
         session3.execute("UPDATE user_types.t set v.third = 103 WHERE id=0")
         query = SimpleStatement("SELECT * FROM t WHERE id = 0", 
consistency_level=ConsistencyLevel.ALL)
         rows = list(session.execute(query))
-        self.assertEqual(listify(rows), [[0, ['delta', -10, 103]]])
+        assert listify(rows) == [[0, ['delta', -10, 103]]]
         session1.shutdown()
         session2.shutdown()
         session3.shutdown()
@@ -745,14 +753,14 @@ class TestUserTypes(Tester):
         session.execute("INSERT INTO t (id, v) VALUES (0, {first:'cass', 
second:3, third:0})")
         session.execute("UPDATE t SET v.first = null WHERE id = 0")
         rows = list(session.execute("SELECT * FROM t WHERE id=0"))
-        self.assertEqual(listify(rows), [[0, [None, 3, 0]]])
+        assert listify(rows) == [[0, [None, 3, 0]]]
 
         rows = list(session.execute("SELECT v.first FROM t WHERE id=0"))
-        self.assertEqual(listify(rows), [[None]])
+        assert listify(rows) == [[None]]
         rows = list(session.execute("SELECT v.second FROM t WHERE id=0"))
-        self.assertEqual(listify(rows), [[3]])
+        assert listify(rows) == [[3]]
         rows = list(session.execute("SELECT v.third FROM t WHERE id=0"))
-        self.assertEqual(listify(rows), [[0]])
+        assert listify(rows) == [[0]]
 
     @since('2.2')
     def test_user_type_isolation(self):
@@ -761,7 +769,6 @@ class TestUserTypes(Tester):
         @jira_ticket CASSANDRA-9409
         @since 2.2
         """
-
         cluster = self.cluster
         cluster.populate(1).start()
         node1 = cluster.nodelist()[0]

http://git-wip-us.apache.org/repos/asf/cassandra-dtest/blob/49b2dda4/wide_rows_test.py
----------------------------------------------------------------------
diff --git a/wide_rows_test.py b/wide_rows_test.py
index 63e6fb1..078f0c5 100644
--- a/wide_rows_test.py
+++ b/wide_rows_test.py
@@ -1,7 +1,8 @@
 import datetime
 import random
+import logging
 
-from dtest import Tester, debug, create_ks
+from dtest import Tester, create_ks
 from tools.assertions import assert_length_equal
 
 status_messages = (
@@ -22,6 +23,8 @@ clients = (
     "Emacs"
 )
 
+logger = logging.getLogger(__name__)
+
 
 class TestWideRows(Tester):
     def test_wide_rows(self):
@@ -36,29 +39,29 @@ class TestWideRows(Tester):
         start_time = datetime.datetime.now()
         create_ks(session, 'wide_rows', 1)
         # Simple timeline:  user -> {date: value, ...}
-        debug('Create Table....')
+        logger.debug('Create Table....')
         session.execute('CREATE TABLE user_events (userid text, event 
timestamp, value text, PRIMARY KEY (userid, event));')
         date = datetime.datetime.now()
         # Create a large timeline for each of a group of users:
         for user in ('ryan', 'cathy', 'mallen', 'joaquin', 'erin', 'ham'):
-            debug("Writing values for: %s" % user)
-            for day in xrange(5000):
+            logger.debug("Writing values for: %s" % user)
+            for day in range(5000):
                 date_str = (date + 
datetime.timedelta(day)).strftime("%Y-%m-%d")
                 client = random.choice(clients)
                 msg = random.choice(status_messages)
                 query = "UPDATE user_events SET value = '{msg:%s, client:%s}' 
WHERE userid='%s' and event='%s';" % (msg, client, user, date_str)
-                # debug(query)
+                # logger.debug(query)
                 session.execute(query)
 
-        # debug('Duration of test: %s' % (datetime.datetime.now() - 
start_time))
+        # logger.debug('Duration of test: %s' % (datetime.datetime.now() - 
start_time))
 
         # Pick out an update for a specific date:
         query = "SELECT value FROM user_events WHERE userid='ryan' and 
event='%s'" % \
                 (date + datetime.timedelta(10)).strftime("%Y-%m-%d")
         rows = session.execute(query)
         for value in rows:
-            debug(value)
-            self.assertGreater(len(value[0]), 0)
+            logger.debug(value)
+            assert len(value[0]) > 0
 
     def test_column_index_stress(self):
         """Write a large number of columns to a single row and set

http://git-wip-us.apache.org/repos/asf/cassandra-dtest/blob/49b2dda4/write_failures_test.py
----------------------------------------------------------------------
diff --git a/write_failures_test.py b/write_failures_test.py
index 4a507f4..17ce50e 100644
--- a/write_failures_test.py
+++ b/write_failures_test.py
@@ -1,11 +1,15 @@
 import uuid
+import pytest
+import logging
 
 from cassandra import ConsistencyLevel, WriteFailure, WriteTimeout
 
-from dtest import Tester, supports_v5_protocol
-from thrift_bindings.v22 import ttypes as thrift_types
-from thrift_tests import get_thrift_client
-from tools.decorators import since
+from dtest import Tester
+from thrift_bindings.thrift010 import ttypes as thrift_types
+from thrift_test import get_thrift_client
+
+since = pytest.mark.since
+logger = logging.getLogger(__name__)
 
 KEYSPACE = "foo"
 
@@ -21,26 +25,23 @@ class TestWriteFailures(Tester):
     They require CURRENT_VERSION = VERSION_4 in CassandraDaemon.Server
     otherwise these tests will fail.
     """
-
-    def setUp(self):
-        super(TestWriteFailures, self).setUp()
-
-        self.ignore_log_patterns = [
+    @pytest.fixture(autouse=True)
+    def fixture_add_additional_log_patterns(self, fixture_dtest_setup):
+        fixture_dtest_setup.ignore_log_patterns = (
             "Testing write failures",  # The error to simulate a write failure
             "ERROR WRITE_FAILURE",     # Logged in DEBUG mode for write 
failures
             "MigrationStage"           # This occurs sometimes due to node 
down (because of restart)
-        ]
+        )
 
-        self.supports_v5_protocol = 
supports_v5_protocol(self.cluster.version())
+    @pytest.fixture(scope="function", autouse=True)
+    def fixture_set_test_defauls(self, fixture_dtest_setup):
+        self.supports_v5_protocol = 
fixture_dtest_setup.supports_v5_protocol(fixture_dtest_setup.cluster.version())
         self.expected_expt = WriteFailure
         self.protocol_version = 5 if self.supports_v5_protocol else 4
         self.replication_factor = 3
         self.consistency_level = ConsistencyLevel.ALL
         self.failing_nodes = [1, 2]
 
-    def tearDown(self):
-        super(TestWriteFailures, self).tearDown()
-
     def _prepare_cluster(self, start_rpc=False):
         self.cluster.populate(3)
 
@@ -48,7 +49,7 @@ class TestWriteFailures(Tester):
             self.cluster.set_configuration_options(values={'start_rpc': True})
 
         self.cluster.start(wait_for_binary_proto=True)
-        self.nodes = self.cluster.nodes.values()
+        self.nodes = list(self.cluster.nodes.values())
 
         session = self.patient_exclusive_cql_connection(self.nodes[0], 
protocol_version=self.protocol_version)
 
@@ -81,9 +82,9 @@ class TestWriteFailures(Tester):
         if self.expected_expt is None:
             session.execute(statement)
         else:
-            with self.assertRaises(self.expected_expt) as cm:
+            with pytest.raises(self.expected_expt) as cm:
                 session.execute(statement)
-            return cm.exception
+            return cm._excinfo[1]
 
     def _assert_error_code_map_exists_with_code(self, exception, 
expected_code):
         """
@@ -91,14 +92,14 @@ class TestWriteFailures(Tester):
         where at least one node responded with some expected code.
         This is meant for testing failure exceptions on protocol v5.
         """
-        self.assertIsNotNone(exception)
-        self.assertIsNotNone(exception.error_code_map)
+        assert exception is not None
+        assert exception.error_code_map is not None
         expected_code_found = False
-        for error_code in exception.error_code_map.values():
+        for error_code in list(exception.error_code_map.values()):
             if error_code == expected_code:
                 expected_code_found = True
                 break
-        self.assertTrue(expected_code_found, "The error code map did not 
contain " + str(expected_code))
+        assert expected_code_found, "The error code map did not contain " + 
str(expected_code)
 
     @since('2.2', max_version='2.2.x')
     def test_mutation_v2(self):
@@ -147,8 +148,8 @@ class TestWriteFailures(Tester):
 
     def test_mutation_one(self):
         """
-            A WriteFailure is received at consistency level ONE
-            if all nodes fail
+        A WriteFailure is received at consistency level ONE
+        if all nodes fail
         """
         self.consistency_level = ConsistencyLevel.ONE
         self.failing_nodes = [0, 1, 2]
@@ -220,7 +221,7 @@ class TestWriteFailures(Tester):
         client.transport.open()
         client.set_keyspace(KEYSPACE)
 
-        with self.assertRaises(self.expected_expt):
+        with pytest.raises(self.expected_expt):
             client.insert('key1',
                           thrift_types.ColumnParent('mytable'),
                           thrift_types.Column('value', 'Value 1', 0),


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to