diff --git a/ospurge/tests/__init__.py b/ospurge/tests/__init__.py index e69de29..a959d58 100644 --- a/ospurge/tests/__init__.py +++ b/ospurge/tests/__init__.py @@ -0,0 +1,9 @@ +try: + from unittest import mock # Python 3.3+ +except ImportError: + import mock # noqa: Python 2.7 + +try: + import unittest2 as unittest # Python 2.7 +except ImportError: + import unittest # noqa diff --git a/ospurge/tests/resources/test_base.py b/ospurge/tests/resources/test_base.py index 8b97268..5299d73 100644 --- a/ospurge/tests/resources/test_base.py +++ b/ospurge/tests/resources/test_base.py @@ -13,11 +13,11 @@ import time from typing import Any from typing import Dict from typing import Iterable -import unittest -from unittest import mock from ospurge import exceptions from ospurge.resources import base +from ospurge.tests import mock +from ospurge.tests import unittest def generate_timeout_series(timeout): diff --git a/ospurge/tests/resources/test_cinder.py b/ospurge/tests/resources/test_cinder.py index 6a4ad0f..1a36495 100644 --- a/ospurge/tests/resources/test_cinder.py +++ b/ospurge/tests/resources/test_cinder.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. import unittest -from unittest import mock import shade from ospurge.resources import cinder +from ospurge.tests import mock class TestBackups(unittest.TestCase): diff --git a/ospurge/tests/resources/test_glance.py b/ospurge/tests/resources/test_glance.py index 6d40570..504fc11 100644 --- a/ospurge/tests/resources/test_glance.py +++ b/ospurge/tests/resources/test_glance.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. import unittest -from unittest import mock import shade from ospurge.resources import glance +from ospurge.tests import mock class TestListImagesMixin(unittest.TestCase): diff --git a/ospurge/tests/resources/test_neutron.py b/ospurge/tests/resources/test_neutron.py index ba600ab..97df11d 100644 --- a/ospurge/tests/resources/test_neutron.py +++ b/ospurge/tests/resources/test_neutron.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. import unittest -from unittest import mock import shade from ospurge.resources import neutron +from ospurge.tests import mock class TestFloatingIPs(unittest.TestCase): diff --git a/ospurge/tests/resources/test_nova.py b/ospurge/tests/resources/test_nova.py index 95f21b8..06019a7 100644 --- a/ospurge/tests/resources/test_nova.py +++ b/ospurge/tests/resources/test_nova.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. import unittest -from unittest import mock import shade from ospurge.resources import nova +from ospurge.tests import mock class TestServers(unittest.TestCase): diff --git a/ospurge/tests/resources/test_swift.py b/ospurge/tests/resources/test_swift.py index e8bfd19..ef7fbb1 100644 --- a/ospurge/tests/resources/test_swift.py +++ b/ospurge/tests/resources/test_swift.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. import unittest -from unittest import mock import shade from ospurge.resources import swift +from ospurge.tests import mock class TestListObjectsMixin(unittest.TestCase): diff --git a/ospurge/tests/test_main.py b/ospurge/tests/test_main.py index 7b082b5..af2010b 100644 --- a/ospurge/tests/test_main.py +++ b/ospurge/tests/test_main.py @@ -13,13 +13,13 @@ import argparse import logging import types import unittest -from unittest import mock import shade.exc from ospurge import exceptions from ospurge import main from ospurge.resources.base import ServiceResource +from ospurge.tests import mock from ospurge import utils diff --git a/ospurge/tests/test_utils.py b/ospurge/tests/test_utils.py index 69d31a8..d0d4932 100644 --- a/ospurge/tests/test_utils.py +++ b/ospurge/tests/test_utils.py @@ -12,11 +12,11 @@ import logging import typing import unittest -from unittest import mock import shade from ospurge.resources.base import ServiceResource +from ospurge.tests import mock from ospurge import utils diff --git a/test-requirements.txt b/test-requirements.txt index a44ac16..07076a2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,3 +5,7 @@ hacking>=0.12.0,<0.13 # Apache-2.0 openstackdocstheme>=1.5.0 # Apache-2.0 sphinx>=1.2.1,!=1.3b1,<1.4 # BSD testrepository>=0.0.18 # Apache-2.0/BSD + +# Python 2.7 dependencies +mock; python_version < '3.0' +unittest2; python_version < '3.0'