Python2: Add mock and unittest2 test dependencies

* unittest.mock was added in Python 3.3 standard library: use
  external 'mock' module, backport for Python 2.7
* assertRaisesRegex() method was added to Python 3.2 unittest module:
  use external 'unitttest2' backport for Python 2.7 to not have to
  rewrite unit tests just because of Python 2.7

Both added dependencies are specific to Python 2.7 and have no impact
on Python 3.

Related-Bug: 1726399
Change-Id: Ieb32e85d6f40f9b7bed5ba99900be2432d18da9e
This commit is contained in:
Victor Stinner 2017-10-23 15:26:27 +02:00
parent 90642dd2ec
commit 17162e6506
10 changed files with 22 additions and 9 deletions

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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'