From ce620c399a9e5cf2fd438d0193ba0d83da667a88 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 9 Sep 2014 18:04:40 -0700 Subject: [PATCH] Use oslotest to provide our base test case class The oslotest library has a nice openstack testing integrated base class that can ensure we setup our base test case using the right logging fixtures, test timeouts, and output fixtures that better operate in the openstack ecosystem. This will also allow us to remove some of the functionality that we currently have in our base test case and replace it with the equivalent (or better) functionality that oslotest now provides. Part of blueprint use-oslo-test Change-Id: I1602d5180ec8649a1899185972750ddddf65990f --- taskflow/test.py | 13 ++++++++++--- taskflow/tests/unit/jobs/base.py | 2 +- taskflow/tests/unit/test_duration.py | 3 +-- taskflow/tests/unit/test_engine_helpers.py | 3 +-- taskflow/tests/unit/test_storage.py | 3 +-- taskflow/tests/unit/test_task.py | 3 +-- taskflow/tests/unit/worker_based/test_dispatcher.py | 2 +- taskflow/tests/unit/worker_based/test_engine.py | 3 +-- taskflow/tests/unit/worker_based/test_executor.py | 2 +- .../tests/unit/worker_based/test_message_pump.py | 3 +-- taskflow/tests/unit/worker_based/test_protocol.py | 2 +- taskflow/tests/unit/worker_based/test_proxy.py | 2 +- taskflow/tests/unit/worker_based/test_server.py | 2 +- taskflow/tests/unit/worker_based/test_worker.py | 3 +-- test-requirements.txt | 5 +---- tox.ini | 5 +++++ 16 files changed, 29 insertions(+), 27 deletions(-) diff --git a/taskflow/test.py b/taskflow/test.py index 4de61d3e..3d94df5a 100644 --- a/taskflow/test.py +++ b/taskflow/test.py @@ -15,8 +15,15 @@ # under the License. import fixtures -import mock +from oslotest import base import six +try: + from six.moves import mock +except ImportError: + try: + from unittest import mock + except ImportError: + import mock from testtools import compat from testtools import matchers from testtools import testcase @@ -85,7 +92,7 @@ class ItemsEqual(object): return None -class TestCase(testcase.TestCase): +class TestCase(base.BaseTestCase): """Test case base class for all taskflow unit tests.""" def makeTmpDir(self): @@ -182,7 +189,7 @@ class TestCase(testcase.TestCase): self.assertThat(seq2, matcher) -class MockTestCase(TestCase): +class MockTestCase(base.BaseTestCase): def setUp(self): super(MockTestCase, self).setUp() diff --git a/taskflow/tests/unit/jobs/base.py b/taskflow/tests/unit/jobs/base.py index a178a8af..f8a2687e 100644 --- a/taskflow/tests/unit/jobs/base.py +++ b/taskflow/tests/unit/jobs/base.py @@ -19,12 +19,12 @@ import threading import time from kazoo.recipe import watchers -import mock from taskflow import exceptions as excp from taskflow.openstack.common import uuidutils from taskflow.persistence.backends import impl_dir from taskflow import states +from taskflow.test import mock from taskflow.utils import misc from taskflow.utils import persistence_utils as p_utils diff --git a/taskflow/tests/unit/test_duration.py b/taskflow/tests/unit/test_duration.py index e1588eb2..47389724 100644 --- a/taskflow/tests/unit/test_duration.py +++ b/taskflow/tests/unit/test_duration.py @@ -17,8 +17,6 @@ import contextlib import time -import mock - import taskflow.engines from taskflow import exceptions as exc from taskflow.listeners import timing @@ -26,6 +24,7 @@ from taskflow.patterns import linear_flow as lf from taskflow.persistence.backends import impl_memory from taskflow import task from taskflow import test +from taskflow.test import mock from taskflow.tests import utils as t_utils from taskflow.utils import persistence_utils as p_utils diff --git a/taskflow/tests/unit/test_engine_helpers.py b/taskflow/tests/unit/test_engine_helpers.py index fbf1756c..2353d77d 100644 --- a/taskflow/tests/unit/test_engine_helpers.py +++ b/taskflow/tests/unit/test_engine_helpers.py @@ -14,12 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. -import mock - import taskflow.engines from taskflow import exceptions as exc from taskflow.patterns import linear_flow from taskflow import test +from taskflow.test import mock from taskflow.tests import utils as test_utils from taskflow.utils import persistence_utils as p_utils diff --git a/taskflow/tests/unit/test_storage.py b/taskflow/tests/unit/test_storage.py index 001cba97..94d73012 100644 --- a/taskflow/tests/unit/test_storage.py +++ b/taskflow/tests/unit/test_storage.py @@ -17,8 +17,6 @@ import contextlib import threading -import mock - from taskflow import exceptions from taskflow.openstack.common import uuidutils from taskflow.persistence import backends @@ -26,6 +24,7 @@ from taskflow.persistence import logbook from taskflow import states from taskflow import storage from taskflow import test +from taskflow.test import mock from taskflow.utils import misc from taskflow.utils import persistence_utils as p_utils diff --git a/taskflow/tests/unit/test_task.py b/taskflow/tests/unit/test_task.py index bcb75788..a3854d26 100644 --- a/taskflow/tests/unit/test_task.py +++ b/taskflow/tests/unit/test_task.py @@ -14,10 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. -import mock - from taskflow import task from taskflow import test +from taskflow.test import mock from taskflow.utils import reflection diff --git a/taskflow/tests/unit/worker_based/test_dispatcher.py b/taskflow/tests/unit/worker_based/test_dispatcher.py index 4dae910d..9b121d53 100644 --- a/taskflow/tests/unit/worker_based/test_dispatcher.py +++ b/taskflow/tests/unit/worker_based/test_dispatcher.py @@ -15,10 +15,10 @@ # under the License. from kombu import message -import mock from taskflow.engines.worker_based import dispatcher from taskflow import test +from taskflow.test import mock def mock_acked_message(ack_ok=True, **kwargs): diff --git a/taskflow/tests/unit/worker_based/test_engine.py b/taskflow/tests/unit/worker_based/test_engine.py index 531dfe5a..ea322de1 100644 --- a/taskflow/tests/unit/worker_based/test_engine.py +++ b/taskflow/tests/unit/worker_based/test_engine.py @@ -14,11 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock - from taskflow.engines.worker_based import engine from taskflow.patterns import linear_flow as lf from taskflow import test +from taskflow.test import mock from taskflow.tests import utils from taskflow.utils import persistence_utils as pu diff --git a/taskflow/tests/unit/worker_based/test_executor.py b/taskflow/tests/unit/worker_based/test_executor.py index cc184df2..c55c1c6a 100644 --- a/taskflow/tests/unit/worker_based/test_executor.py +++ b/taskflow/tests/unit/worker_based/test_executor.py @@ -18,12 +18,12 @@ import threading import time from concurrent import futures -import mock from oslo.utils import timeutils from taskflow.engines.worker_based import executor from taskflow.engines.worker_based import protocol as pr from taskflow import test +from taskflow.test import mock from taskflow.tests import utils from taskflow.utils import misc diff --git a/taskflow/tests/unit/worker_based/test_message_pump.py b/taskflow/tests/unit/worker_based/test_message_pump.py index 10116c21..e2102b76 100644 --- a/taskflow/tests/unit/worker_based/test_message_pump.py +++ b/taskflow/tests/unit/worker_based/test_message_pump.py @@ -16,12 +16,11 @@ import threading -import mock - from taskflow.engines.worker_based import protocol as pr from taskflow.engines.worker_based import proxy from taskflow.openstack.common import uuidutils from taskflow import test +from taskflow.test import mock from taskflow.tests import utils as test_utils from taskflow.types import latch diff --git a/taskflow/tests/unit/worker_based/test_protocol.py b/taskflow/tests/unit/worker_based/test_protocol.py index 7d51da31..00a208e2 100644 --- a/taskflow/tests/unit/worker_based/test_protocol.py +++ b/taskflow/tests/unit/worker_based/test_protocol.py @@ -15,12 +15,12 @@ # under the License. from concurrent import futures -import mock from taskflow.engines.worker_based import protocol as pr from taskflow import exceptions as excp from taskflow.openstack.common import uuidutils from taskflow import test +from taskflow.test import mock from taskflow.tests import utils from taskflow.utils import misc diff --git a/taskflow/tests/unit/worker_based/test_proxy.py b/taskflow/tests/unit/worker_based/test_proxy.py index e2dc02e8..3c075969 100644 --- a/taskflow/tests/unit/worker_based/test_proxy.py +++ b/taskflow/tests/unit/worker_based/test_proxy.py @@ -17,7 +17,7 @@ import socket import threading -import mock +from six.moves import mock from taskflow.engines.worker_based import proxy from taskflow import test diff --git a/taskflow/tests/unit/worker_based/test_server.py b/taskflow/tests/unit/worker_based/test_server.py index 2a64c960..2759c49f 100644 --- a/taskflow/tests/unit/worker_based/test_server.py +++ b/taskflow/tests/unit/worker_based/test_server.py @@ -14,13 +14,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock 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 from taskflow import test +from taskflow.test import mock from taskflow.tests import utils from taskflow.utils import misc diff --git a/taskflow/tests/unit/worker_based/test_worker.py b/taskflow/tests/unit/worker_based/test_worker.py index c66255f9..17770986 100644 --- a/taskflow/tests/unit/worker_based/test_worker.py +++ b/taskflow/tests/unit/worker_based/test_worker.py @@ -14,11 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock - from taskflow.engines.worker_based import endpoint from taskflow.engines.worker_based import worker from taskflow import test +from taskflow.test import mock from taskflow.tests import utils from taskflow.utils import reflection diff --git a/test-requirements.txt b/test-requirements.txt index b72ca0b8..d74dd5ee 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,11 +3,8 @@ # process, which may cause wedges in the gate later. hacking>=0.9.2,<0.10 -discover -coverage>=3.6 +oslotest>=1.1.0 # Apache-2.0 mock>=1.0 -python-subunit>=0.0.18 -testrepository>=0.0.18 testtools>=0.9.34 # Used for testing the WBE engine. diff --git a/tox.ini b/tox.ini index bc912778..3a14bd5f 100644 --- a/tox.ini +++ b/tox.ini @@ -54,6 +54,11 @@ ignore = H904 builtins = _ exclude = .venv,.tox,dist,doc,./taskflow/openstack/common,*egg,.git,build,tools +[hacking] +import_exceptions = six.moves.mock + taskflow.test.mock + unittest.mock + # NOTE(imelnikov): pyXY envs are considered to be default, so they must have # richest set of test requirements [testenv:py26]