summaryrefslogtreecommitdiff
path: root/taskflow/tests
diff options
context:
space:
mode:
authorTakashi Kajinami <tkajinam@redhat.com>2022-05-17 22:56:45 +0900
committerTakashi Kajinami <tkajinam@redhat.com>2022-05-18 16:12:37 +0900
commit44f17d005ff53008144ca7c509bcb1307d66b23f (patch)
treeb03024443b92a78f3cdacfca29f4010d24c8b685 /taskflow/tests
parentb5b69e8110da44a88b2260cd24ada3439f29938e (diff)
downloadtaskflow-44f17d005ff53008144ca7c509bcb1307d66b23f.tar.gz
Remove six
This library no longer supports Python 2, thus usage of six can be removed. This also removes workaround about pickle library used in Python 2 only. Change-Id: I19d298cf0f402d65f0b142dea0bf35cf992332a9
Diffstat (limited to 'taskflow/tests')
-rw-r--r--taskflow/tests/test_examples.py5
-rw-r--r--taskflow/tests/unit/action_engine/test_builder.py15
-rw-r--r--taskflow/tests/unit/jobs/test_redis_job.py3
-rw-r--r--taskflow/tests/unit/jobs/test_zk_job.py11
-rw-r--r--taskflow/tests/unit/persistence/test_sql_persistence.py5
-rw-r--r--taskflow/tests/unit/test_engines.py5
-rw-r--r--taskflow/tests/unit/test_exceptions.py4
-rw-r--r--taskflow/tests/unit/test_failure.py24
-rw-r--r--taskflow/tests/unit/test_listeners.py5
-rw-r--r--taskflow/tests/unit/test_types.py2
-rw-r--r--taskflow/tests/unit/test_utils.py3
-rw-r--r--taskflow/tests/unit/test_utils_binary.py17
-rw-r--r--taskflow/tests/unit/test_utils_iter_utils.py39
-rw-r--r--taskflow/tests/unit/worker_based/test_server.py4
-rw-r--r--taskflow/tests/unit/worker_based/test_worker.py4
-rw-r--r--taskflow/tests/utils.py15
16 files changed, 61 insertions, 100 deletions
diff --git a/taskflow/tests/test_examples.py b/taskflow/tests/test_examples.py
index 6214290..bcb09e1 100644
--- a/taskflow/tests/test_examples.py
+++ b/taskflow/tests/test_examples.py
@@ -34,8 +34,6 @@ import re
import subprocess
import sys
-import six
-
from taskflow import test
ROOT_DIR = os.path.abspath(
@@ -118,8 +116,7 @@ class ExampleAdderMeta(type):
return type.__new__(cls, name, parents, dct)
-@six.add_metaclass(ExampleAdderMeta)
-class ExamplesTestCase(test.TestCase):
+class ExamplesTestCase(test.TestCase, metaclass=ExampleAdderMeta):
"""Runs the examples, and checks the outputs against expected outputs."""
def _check_example(self, name):
diff --git a/taskflow/tests/unit/action_engine/test_builder.py b/taskflow/tests/unit/action_engine/test_builder.py
index 1bb79b8..72b83ec 100644
--- a/taskflow/tests/unit/action_engine/test_builder.py
+++ b/taskflow/tests/unit/action_engine/test_builder.py
@@ -16,7 +16,6 @@
from automaton import exceptions as excp
from automaton import runners
-import six
from taskflow.engines.action_engine import builder
from taskflow.engines.action_engine import compiler
@@ -70,30 +69,30 @@ class BuildersTest(test.TestCase):
flow, initial_state=st.RUNNING)
it = machine_runner.run_iter(builder.START)
- prior_state, new_state = six.next(it)
+ prior_state, new_state = next(it)
self.assertEqual(st.RESUMING, new_state)
self.assertEqual(0, len(memory.failures))
- prior_state, new_state = six.next(it)
+ prior_state, new_state = next(it)
self.assertEqual(st.SCHEDULING, new_state)
self.assertEqual(0, len(memory.failures))
- prior_state, new_state = six.next(it)
+ prior_state, new_state = next(it)
self.assertEqual(st.WAITING, new_state)
self.assertEqual(0, len(memory.failures))
- prior_state, new_state = six.next(it)
+ prior_state, new_state = next(it)
self.assertEqual(st.ANALYZING, new_state)
self.assertEqual(0, len(memory.failures))
- prior_state, new_state = six.next(it)
+ prior_state, new_state = next(it)
self.assertEqual(builder.GAME_OVER, new_state)
self.assertEqual(0, len(memory.failures))
- prior_state, new_state = six.next(it)
+ prior_state, new_state = next(it)
self.assertEqual(st.SUCCESS, new_state)
self.assertEqual(0, len(memory.failures))
- self.assertRaises(StopIteration, six.next, it)
+ self.assertRaises(StopIteration, next, it)
def test_run_iterations_reverted(self):
flow = lf.Flow("root")
diff --git a/taskflow/tests/unit/jobs/test_redis_job.py b/taskflow/tests/unit/jobs/test_redis_job.py
index 9e6bdc7..320827c 100644
--- a/taskflow/tests/unit/jobs/test_redis_job.py
+++ b/taskflow/tests/unit/jobs/test_redis_job.py
@@ -18,7 +18,6 @@ import time
from unittest import mock
from oslo_utils import uuidutils
-import six
import testtools
from taskflow import exceptions as excp
@@ -44,7 +43,7 @@ class RedisJobboardTest(test.TestCase, base.BoardTestMixin):
namespace = uuidutils.generate_uuid()
client = ru.RedisClient()
config = {
- 'namespace': six.b("taskflow-%s" % namespace),
+ 'namespace': ("taskflow-%s" % namespace).encode('latin-1'),
}
kwargs = {
'client': client,
diff --git a/taskflow/tests/unit/jobs/test_zk_job.py b/taskflow/tests/unit/jobs/test_zk_job.py
index 527f253..d93f148 100644
--- a/taskflow/tests/unit/jobs/test_zk_job.py
+++ b/taskflow/tests/unit/jobs/test_zk_job.py
@@ -21,7 +21,6 @@ from kazoo.protocol import paths as k_paths
from kazoo.recipe import watchers
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
-import six
import testtools
from zake import fake_client
from zake import utils as zake_utils
@@ -171,7 +170,7 @@ class ZakeJobboardTest(test.TestCase, ZookeeperBoardTestMixin):
# Forcefully delete the owner from the backend storage to make
# sure the job becomes unclaimed (this may happen if some admin
# manually deletes the lock).
- paths = list(six.iteritems(self.client.storage.paths))
+ paths = list(self.client.storage.paths.items())
for (path, value) in paths:
if path in self.bad_paths:
continue
@@ -192,7 +191,7 @@ class ZakeJobboardTest(test.TestCase, ZookeeperBoardTestMixin):
# Forcefully delete the lock from the backend storage to make
# sure the job becomes unclaimed (this may happen if some admin
# manually deletes the lock).
- paths = list(six.iteritems(self.client.storage.paths))
+ paths = list(self.client.storage.paths.items())
for (path, value) in paths:
if path in self.bad_paths:
continue
@@ -215,7 +214,7 @@ class ZakeJobboardTest(test.TestCase, ZookeeperBoardTestMixin):
trashed = []
jobs = []
- paths = list(six.iteritems(self.client.storage.paths))
+ paths = list(self.client.storage.paths.items())
for (path, value) in paths:
if path in self.bad_paths:
continue
@@ -244,14 +243,14 @@ class ZakeJobboardTest(test.TestCase, ZookeeperBoardTestMixin):
# Remove paths that got created due to the running process that we are
# not interested in...
paths = {}
- for (path, data) in six.iteritems(self.client.storage.paths):
+ for (path, data) in self.client.storage.paths.items():
if path in self.bad_paths:
continue
paths[path] = data
# Check the actual data that was posted.
self.assertEqual(1, len(paths))
- path_key = list(six.iterkeys(paths))[0]
+ path_key = list(paths.keys())[0]
self.assertTrue(len(paths[path_key]['data']) > 0)
self.assertDictEqual({
'uuid': posted_job.uuid,
diff --git a/taskflow/tests/unit/persistence/test_sql_persistence.py b/taskflow/tests/unit/persistence/test_sql_persistence.py
index 973bf9f..5a1917c 100644
--- a/taskflow/tests/unit/persistence/test_sql_persistence.py
+++ b/taskflow/tests/unit/persistence/test_sql_persistence.py
@@ -20,7 +20,6 @@ import os
import random
import tempfile
-import six
import testtools
@@ -123,8 +122,8 @@ class SqlitePersistenceTest(test.TestCase, base.PersistenceTestMixin):
self.db_location = None
-@six.add_metaclass(abc.ABCMeta)
-class BackendPersistenceTestMixin(base.PersistenceTestMixin):
+class BackendPersistenceTestMixin(base.PersistenceTestMixin,
+ metaclass=abc.ABCMeta):
"""Specifies a backend type and does required setup and teardown."""
def _get_connection(self):
diff --git a/taskflow/tests/unit/test_engines.py b/taskflow/tests/unit/test_engines.py
index 81f0e08..4454429 100644
--- a/taskflow/tests/unit/test_engines.py
+++ b/taskflow/tests/unit/test_engines.py
@@ -20,7 +20,6 @@ import functools
import threading
import futurist
-import six
import testtools
import taskflow.engines
@@ -350,7 +349,7 @@ class EngineLinearFlowTest(utils.EngineTestBase):
engine_it = engine.run_iter()
while True:
try:
- engine_state = six.next(engine_it)
+ engine_state = next(engine_it)
if engine_state not in engine_states:
engine_states[engine_state] = 1
else:
@@ -1318,7 +1317,7 @@ class EngineGraphConditionalFlowTest(utils.EngineTestBase):
def test_graph_flow_conditional_history(self):
def even_odd_decider(history, allowed):
- total = sum(six.itervalues(history))
+ total = sum(history.values())
if total == allowed:
return True
return False
diff --git a/taskflow/tests/unit/test_exceptions.py b/taskflow/tests/unit/test_exceptions.py
index c542ae8..4c20f7c 100644
--- a/taskflow/tests/unit/test_exceptions.py
+++ b/taskflow/tests/unit/test_exceptions.py
@@ -16,9 +16,6 @@
import string
-import six
-import testtools
-
from taskflow import exceptions as exc
from taskflow import test
@@ -109,7 +106,6 @@ class TestExceptions(test.TestCase):
ex = exc.TaskFlowException("Broken")
self.assertRaises(ValueError, ex.pformat, indent=-100)
- @testtools.skipIf(not six.PY3, 'py3.x is not available')
def test_raise_with_cause(self):
capture = None
try:
diff --git a/taskflow/tests/unit/test_failure.py b/taskflow/tests/unit/test_failure.py
index 217f1b3..1c25ac7 100644
--- a/taskflow/tests/unit/test_failure.py
+++ b/taskflow/tests/unit/test_failure.py
@@ -14,12 +14,10 @@
# License for the specific language governing permissions and limitations
# under the License.
+import pickle
import sys
from oslo_utils import encodeutils
-import six
-from six.moves import cPickle as pickle
-import testtools
from taskflow import exceptions
from taskflow import test
@@ -338,23 +336,16 @@ class NonAsciiExceptionsTestCase(test.TestCase):
fail = failure.Failure.from_exception(excp)
self.assertEqual(encodeutils.exception_to_unicode(excp),
fail.exception_str)
- # This is slightly different on py2 vs py3... due to how
- # __str__ or __unicode__ is called and what is expected from
- # both...
- if six.PY2:
- msg = encodeutils.exception_to_unicode(excp)
- expected = 'Failure: ValueError: %s' % msg.encode('utf-8')
- else:
- expected = u'Failure: ValueError: \xc8'
+ expected = u'Failure: ValueError: \xc8'
self.assertEqual(expected, str(fail))
def test_exception_non_ascii_unicode(self):
hi_ru = u'привет'
fail = failure.Failure.from_exception(ValueError(hi_ru))
self.assertEqual(hi_ru, fail.exception_str)
- self.assertIsInstance(fail.exception_str, six.text_type)
+ self.assertIsInstance(fail.exception_str, str)
self.assertEqual(u'Failure: ValueError: %s' % hi_ru,
- six.text_type(fail))
+ str(fail))
def test_wrapped_failure_non_ascii_unicode(self):
hi_cn = u'嗨'
@@ -364,7 +355,7 @@ class NonAsciiExceptionsTestCase(test.TestCase):
wrapped_fail = exceptions.WrappedFailure([fail])
expected_result = (u"WrappedFailure: "
"[Failure: ValueError: %s]" % (hi_cn))
- self.assertEqual(expected_result, six.text_type(wrapped_fail))
+ self.assertEqual(expected_result, str(wrapped_fail))
def test_failure_equality_with_non_ascii_str(self):
bad_string = chr(200)
@@ -379,7 +370,6 @@ class NonAsciiExceptionsTestCase(test.TestCase):
self.assertEqual(fail, copied)
-@testtools.skipIf(not six.PY3, 'this test only works on python 3.x')
class FailureCausesTest(test.TestCase):
@classmethod
@@ -392,7 +382,7 @@ class FailureCausesTest(test.TestCase):
cls._raise_many(messages)
raise e
except RuntimeError as e1:
- six.raise_from(e, e1)
+ raise e from e1
def test_causes(self):
f = None
@@ -467,7 +457,7 @@ class FailureCausesTest(test.TestCase):
self._raise_many(["Still still not working",
"Still not working", "Not working"])
except RuntimeError as e:
- six.raise_from(e, None)
+ raise e from None
except RuntimeError:
f = failure.Failure()
diff --git a/taskflow/tests/unit/test_listeners.py b/taskflow/tests/unit/test_listeners.py
index 3e2f880..b14f7f2 100644
--- a/taskflow/tests/unit/test_listeners.py
+++ b/taskflow/tests/unit/test_listeners.py
@@ -21,7 +21,6 @@ import time
from oslo_serialization import jsonutils
from oslo_utils import reflection
-import six
from zake import fake_client
import taskflow.engines
@@ -111,7 +110,7 @@ class TestClaimListener(test.TestCase, EngineMakerMixin):
children = self.client.storage.get_children("/taskflow",
only_direct=False)
removed = 0
- for p, data in six.iteritems(children):
+ for p, data in children.items():
if p.endswith(".lock"):
self.client.storage.pop(p)
removed += 1
@@ -121,7 +120,7 @@ class TestClaimListener(test.TestCase, EngineMakerMixin):
children = self.client.storage.get_children("/taskflow",
only_direct=False)
altered = 0
- for p, data in six.iteritems(children):
+ for p, data in children.items():
if p.endswith(".lock"):
self.client.set(p, misc.binary_encode(
jsonutils.dumps({'owner': new_owner})))
diff --git a/taskflow/tests/unit/test_types.py b/taskflow/tests/unit/test_types.py
index fd97cd6..eca26cd 100644
--- a/taskflow/tests/unit/test_types.py
+++ b/taskflow/tests/unit/test_types.py
@@ -15,7 +15,7 @@
# under the License.
import networkx as nx
-from six.moves import cPickle as pickle
+import pickle
from taskflow import test
from taskflow.types import graph
diff --git a/taskflow/tests/unit/test_utils.py b/taskflow/tests/unit/test_utils.py
index 72bddd2..168e517 100644
--- a/taskflow/tests/unit/test_utils.py
+++ b/taskflow/tests/unit/test_utils.py
@@ -20,7 +20,6 @@ import random
import string
import time
-import six
import testscenarios
from taskflow import test
@@ -241,7 +240,7 @@ class TestCountdownIter(test.TestCase):
def test_invalid_decr(self):
it = misc.countdown_iter(10, -1)
- self.assertRaises(ValueError, six.next, it)
+ self.assertRaises(ValueError, next, it)
class TestMergeUri(test.TestCase):
diff --git a/taskflow/tests/unit/test_utils_binary.py b/taskflow/tests/unit/test_utils_binary.py
index 773f389..0ba930f 100644
--- a/taskflow/tests/unit/test_utils_binary.py
+++ b/taskflow/tests/unit/test_utils_binary.py
@@ -14,24 +14,19 @@
# License for the specific language governing permissions and limitations
# under the License.
-import six
-
from taskflow import test
from taskflow.utils import misc
def _bytes(data):
- if six.PY3:
- return data.encode(encoding='utf-8')
- else:
- return data
+ return data.encode(encoding='utf-8')
class BinaryEncodeTest(test.TestCase):
def _check(self, data, expected_result):
result = misc.binary_encode(data)
- self.assertIsInstance(result, six.binary_type)
+ self.assertIsInstance(result, bytes)
self.assertEqual(expected_result, result)
def test_simple_binary(self):
@@ -50,7 +45,7 @@ class BinaryEncodeTest(test.TestCase):
def test_unicode_other_encoding(self):
result = misc.binary_encode(u'mañana', 'latin-1')
- self.assertIsInstance(result, six.binary_type)
+ self.assertIsInstance(result, bytes)
self.assertEqual(u'mañana'.encode('latin-1'), result)
@@ -58,7 +53,7 @@ class BinaryDecodeTest(test.TestCase):
def _check(self, data, expected_result):
result = misc.binary_decode(data)
- self.assertIsInstance(result, six.text_type)
+ self.assertIsInstance(result, str)
self.assertEqual(expected_result, result)
def test_simple_text(self):
@@ -78,7 +73,7 @@ class BinaryDecodeTest(test.TestCase):
def test_unicode_other_encoding(self):
data = u'mañana'.encode('latin-1')
result = misc.binary_decode(data, 'latin-1')
- self.assertIsInstance(result, six.text_type)
+ self.assertIsInstance(result, str)
self.assertEqual(u'mañana', result)
@@ -94,7 +89,7 @@ class DecodeJsonTest(test.TestCase):
def test_handles_invalid_unicode(self):
self.assertRaises(ValueError, misc.decode_json,
- six.b('{"\xf1": 1}'))
+ '{"\xf1": 1}'.encode('latin-1'))
def test_handles_bad_json(self):
self.assertRaises(ValueError, misc.decode_json,
diff --git a/taskflow/tests/unit/test_utils_iter_utils.py b/taskflow/tests/unit/test_utils_iter_utils.py
index 4a5ff4b..c4109d8 100644
--- a/taskflow/tests/unit/test_utils_iter_utils.py
+++ b/taskflow/tests/unit/test_utils_iter_utils.py
@@ -16,9 +16,6 @@
import string
-import six
-from six.moves import range as compat_range
-
from taskflow import test
from taskflow.utils import iter_utils
@@ -46,22 +43,22 @@ class IterUtilsTest(test.TestCase):
def test_generate_delays(self):
it = iter_utils.generate_delays(1, 60)
- self.assertEqual(1, six.next(it))
- self.assertEqual(2, six.next(it))
- self.assertEqual(4, six.next(it))
- self.assertEqual(8, six.next(it))
- self.assertEqual(16, six.next(it))
- self.assertEqual(32, six.next(it))
- self.assertEqual(60, six.next(it))
- self.assertEqual(60, six.next(it))
+ self.assertEqual(1, next(it))
+ self.assertEqual(2, next(it))
+ self.assertEqual(4, next(it))
+ self.assertEqual(8, next(it))
+ self.assertEqual(16, next(it))
+ self.assertEqual(32, next(it))
+ self.assertEqual(60, next(it))
+ self.assertEqual(60, next(it))
def test_generate_delays_custom_multiplier(self):
it = iter_utils.generate_delays(1, 60, multiplier=4)
- self.assertEqual(1, six.next(it))
- self.assertEqual(4, six.next(it))
- self.assertEqual(16, six.next(it))
- self.assertEqual(60, six.next(it))
- self.assertEqual(60, six.next(it))
+ self.assertEqual(1, next(it))
+ self.assertEqual(4, next(it))
+ self.assertEqual(16, next(it))
+ self.assertEqual(60, next(it))
+ self.assertEqual(60, next(it))
def test_generate_delays_bad(self):
self.assertRaises(ValueError, iter_utils.generate_delays, -1, -1)
@@ -99,7 +96,7 @@ class IterUtilsTest(test.TestCase):
self.assertRaises(ValueError, iter_utils.fill, 2, 2)
def test_fill_many_empty(self):
- result = list(iter_utils.fill(compat_range(0, 50), 500))
+ result = list(iter_utils.fill(range(0, 50), 500))
self.assertEqual(450, sum(1 for x in result if x is None))
self.assertEqual(50, sum(1 for x in result if x is not None))
@@ -134,10 +131,10 @@ class IterUtilsTest(test.TestCase):
def test_count(self):
self.assertEqual(0, iter_utils.count([]))
self.assertEqual(1, iter_utils.count(['a']))
- self.assertEqual(10, iter_utils.count(compat_range(0, 10)))
- self.assertEqual(1000, iter_utils.count(compat_range(0, 1000)))
- self.assertEqual(0, iter_utils.count(compat_range(0)))
- self.assertEqual(0, iter_utils.count(compat_range(-1)))
+ self.assertEqual(10, iter_utils.count(range(0, 10)))
+ self.assertEqual(1000, iter_utils.count(range(0, 1000)))
+ self.assertEqual(0, iter_utils.count(range(0)))
+ self.assertEqual(0, iter_utils.count(range(-1)))
def test_bad_while_is_not(self):
self.assertRaises(ValueError, iter_utils.while_is_not, 2, 'a')
diff --git a/taskflow/tests/unit/worker_based/test_server.py b/taskflow/tests/unit/worker_based/test_server.py
index 5380204..2261628 100644
--- a/taskflow/tests/unit/worker_based/test_server.py
+++ b/taskflow/tests/unit/worker_based/test_server.py
@@ -14,8 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import six
-
from taskflow.engines.worker_based import endpoint as ep
from taskflow.engines.worker_based import protocol as pr
from taskflow.engines.worker_based import server
@@ -143,7 +141,7 @@ class TestServer(test.MockTestCase):
(self.task.name, self.task.name, 'revert',
dict(arguments=self.task_args,
failures=dict((i, utils.FailureMatcher(f))
- for i, f in six.iteritems(failures)))),
+ for i, f in failures.items()))),
(task_cls, task_name, action, task_args))
@mock.patch("taskflow.engines.worker_based.server.LOG.critical")
diff --git a/taskflow/tests/unit/worker_based/test_worker.py b/taskflow/tests/unit/worker_based/test_worker.py
index 0e49a56..3b068a0 100644
--- a/taskflow/tests/unit/worker_based/test_worker.py
+++ b/taskflow/tests/unit/worker_based/test_worker.py
@@ -14,8 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import io
from oslo_utils import reflection
-import six
from taskflow.engines.worker_based import endpoint
from taskflow.engines.worker_based import worker
@@ -66,7 +66,7 @@ class TestWorker(test.MockTestCase):
self.assertEqual(master_mock_calls, self.master_mock.mock_calls)
def test_banner_writing(self):
- buf = six.StringIO()
+ buf = io.StringIO()
w = self.worker()
w.run(banner_writer=buf.write)
w.wait()
diff --git a/taskflow/tests/utils.py b/taskflow/tests/utils.py
index 58cd9ab..6c2f13a 100644
--- a/taskflow/tests/utils.py
+++ b/taskflow/tests/utils.py
@@ -21,7 +21,6 @@ import time
from oslo_utils import timeutils
import redis
-import six
from taskflow import exceptions
from taskflow.listeners import capturing
@@ -137,7 +136,7 @@ class GiveBackRevert(task.Task):
result = kwargs.get('result')
# If this somehow fails, timeout, or other don't send back a
# valid result...
- if isinstance(result, six.integer_types):
+ if isinstance(result, int):
return result + 1
@@ -153,12 +152,8 @@ class LongArgNameTask(task.Task):
return long_arg_name
-if six.PY3:
- RUNTIME_ERROR_CLASSES = ['RuntimeError', 'Exception',
- 'BaseException', 'object']
-else:
- RUNTIME_ERROR_CLASSES = ['RuntimeError', 'StandardError', 'Exception',
- 'BaseException', 'object']
+RUNTIME_ERROR_CLASSES = ['RuntimeError', 'Exception', 'BaseException',
+ 'object']
class ProvidesRequiresTask(task.Task):
@@ -410,11 +405,11 @@ class WaitForOneFromTask(ProgressingTask):
def __init__(self, name, wait_for, wait_states, **kwargs):
super(WaitForOneFromTask, self).__init__(name, **kwargs)
- if isinstance(wait_for, six.string_types):
+ if isinstance(wait_for, str):
self.wait_for = [wait_for]
else:
self.wait_for = wait_for
- if isinstance(wait_states, six.string_types):
+ if isinstance(wait_states, str):
self.wait_states = [wait_states]
else:
self.wait_states = wait_states