From ff0fbf5810b69e0659f1314da418387d59606660 Mon Sep 17 00:00:00 2001 From: Maciej Kwiek Date: Wed, 15 Jul 2015 15:24:54 +0200 Subject: [PATCH] All tests in fuel_agent use unittest2 now unittest2 backports some nice features from newer versions of unittest for python 2.7 (like assertRaises context manager). Moreover tests now are using either oslotest or testtools directly, switching to one test framework is going to simplify tests. Change-Id: Ibce9403b20958f9db2a59db9c6b7479a4fc57857 Implements blueprint: volume-manager-refactoring --- .testr.conf | 5 ----- fuel_agent/tests/test_artifact_utils.py | 14 +++++++------- fuel_agent/tests/test_build_utils.py | 4 ++-- fuel_agent/tests/test_configdrive.py | 4 ++-- fuel_agent/tests/test_fs_utils.py | 4 ++-- fuel_agent/tests/test_grub_utils.py | 15 ++++++++------- fuel_agent/tests/test_hardware_utils.py | 4 ++-- fuel_agent/tests/test_image.py | 4 ++-- fuel_agent/tests/test_ks_spaces_validator.py | 4 ++-- fuel_agent/tests/test_lvm_utils.py | 4 ++-- fuel_agent/tests/test_manager.py | 8 ++++---- fuel_agent/tests/test_md_utils.py | 4 ++-- fuel_agent/tests/test_nailgun.py | 6 +++--- fuel_agent/tests/test_partition.py | 4 ---- fuel_agent/tests/test_partition_utils.py | 7 ++++--- fuel_agent/tests/test_utils.py | 6 +++--- test-requirements.txt | 5 +---- 17 files changed, 46 insertions(+), 56 deletions(-) delete mode 100644 .testr.conf diff --git a/.testr.conf b/.testr.conf deleted file mode 100644 index 6e344ea..0000000 --- a/.testr.conf +++ /dev/null @@ -1,5 +0,0 @@ -[DEFAULT] -test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -s fuel_agent/tests -p "*.py" $LISTOPT $IDOPTION -test_id_option=--load-list $IDFILE -test_list_option=--list -test_run_concurrency=echo 1 \ No newline at end of file diff --git a/fuel_agent/tests/test_artifact_utils.py b/fuel_agent/tests/test_artifact_utils.py index d3dc07f..a25d0f8 100644 --- a/fuel_agent/tests/test_artifact_utils.py +++ b/fuel_agent/tests/test_artifact_utils.py @@ -13,10 +13,10 @@ # limitations under the License. import mock -from oslotest import base as test_base +from oslo.config import cfg +import unittest2 import zlib -from oslo.config import cfg from fuel_agent import errors from fuel_agent.utils import artifact as au @@ -26,7 +26,7 @@ from fuel_agent.utils import utils CONF = cfg.CONF -class TestTarget(test_base.BaseTestCase): +class TestTarget(unittest2.TestCase): def setUp(self): super(TestTarget, self).setUp() self.tgt = au.Target() @@ -50,7 +50,7 @@ class TestTarget(test_base.BaseTestCase): file_handle.flush.assert_called_once_with() -class TestLocalFile(test_base.BaseTestCase): +class TestLocalFile(unittest2.TestCase): def setUp(self): super(TestLocalFile, self).setUp() self.lf = au.LocalFile('/dev/null') @@ -63,7 +63,7 @@ class TestLocalFile(test_base.BaseTestCase): self.assertRaises(StopIteration, self.lf.next) -class TestHttpUrl(test_base.BaseTestCase): +class TestHttpUrl(unittest2.TestCase): @mock.patch.object(utils, 'init_http_request') def test_httpurl_init_ok(self, mock_req): mock_req.return_value = mock.Mock(headers={'content-length': 123}) @@ -89,7 +89,7 @@ class TestHttpUrl(test_base.BaseTestCase): self.assertEqual(content[data[0]], data[1]) -class TestGunzipStream(test_base.BaseTestCase): +class TestGunzipStream(unittest2.TestCase): def test_gunzip_stream_next(self): content = ['fake content #1'] compressed_stream = [zlib.compress(data) for data in content] @@ -98,7 +98,7 @@ class TestGunzipStream(test_base.BaseTestCase): self.assertEqual(content[data[0]], data[1]) -class TestChain(test_base.BaseTestCase): +class TestChain(unittest2.TestCase): def setUp(self): super(TestChain, self).setUp() self.chain = au.Chain() diff --git a/fuel_agent/tests/test_build_utils.py b/fuel_agent/tests/test_build_utils.py index 28972b6..7b2b2a9 100644 --- a/fuel_agent/tests/test_build_utils.py +++ b/fuel_agent/tests/test_build_utils.py @@ -15,10 +15,10 @@ import os import shutil import signal -import testtools import mock from oslo.config import cfg +import unittest2 from fuel_agent import errors from fuel_agent.utils import build as bu @@ -29,7 +29,7 @@ from fuel_agent.utils import utils CONF = cfg.CONF -class BuildUtilsTestCase(testtools.TestCase): +class BuildUtilsTestCase(unittest2.TestCase): _fake_ubuntu_release = ''' Origin: TestOrigin diff --git a/fuel_agent/tests/test_configdrive.py b/fuel_agent/tests/test_configdrive.py index 445b68a..be4cadc 100644 --- a/fuel_agent/tests/test_configdrive.py +++ b/fuel_agent/tests/test_configdrive.py @@ -13,13 +13,13 @@ # limitations under the License. -from oslotest import base as test_base +import unittest2 from fuel_agent import errors from fuel_agent.objects import configdrive -class TestConfigDriveScheme(test_base.BaseTestCase): +class TestConfigDriveScheme(unittest2.TestCase): def setUp(self): super(TestConfigDriveScheme, self).setUp() diff --git a/fuel_agent/tests/test_fs_utils.py b/fuel_agent/tests/test_fs_utils.py index bdc0779..f955185 100644 --- a/fuel_agent/tests/test_fs_utils.py +++ b/fuel_agent/tests/test_fs_utils.py @@ -13,14 +13,14 @@ # limitations under the License. import mock -from oslotest import base as test_base +import unittest2 from fuel_agent import errors from fuel_agent.utils import fs as fu from fuel_agent.utils import utils -class TestFSUtils(test_base.BaseTestCase): +class TestFSUtils(unittest2.TestCase): @mock.patch.object(utils, 'execute') def test_make_fs(self, mock_exec): diff --git a/fuel_agent/tests/test_grub_utils.py b/fuel_agent/tests/test_grub_utils.py index 89f68fc..67ea812 100644 --- a/fuel_agent/tests/test_grub_utils.py +++ b/fuel_agent/tests/test_grub_utils.py @@ -12,21 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock -from oslotest import base as test_base -import six import StringIO +import mock +import six +import unittest2 + +from fuel_agent import errors +from fuel_agent.utils import grub as gu + if six.PY2: OPEN_FUNCTION_NAME = '__builtin__.open' else: OPEN_FUNCTION_NAME = 'builtins.open' -from fuel_agent import errors -from fuel_agent.utils import grub as gu - -class TestGrubUtils(test_base.BaseTestCase): +class TestGrubUtils(unittest2.TestCase): @mock.patch('fuel_agent.utils.grub.os.path.isdir') def test_guess_grub2_conf(self, mock_isdir): diff --git a/fuel_agent/tests/test_hardware_utils.py b/fuel_agent/tests/test_hardware_utils.py index eeb47e6..1d1d0c3 100644 --- a/fuel_agent/tests/test_hardware_utils.py +++ b/fuel_agent/tests/test_hardware_utils.py @@ -13,13 +13,13 @@ # limitations under the License. import mock -from oslotest import base as test_base +import unittest2 from fuel_agent.utils import hardware as hu from fuel_agent.utils import utils -class TestHardwareUtils(test_base.BaseTestCase): +class TestHardwareUtils(unittest2.TestCase): @mock.patch.object(utils, 'execute') def test_parse_dmidecode(self, exec_mock): diff --git a/fuel_agent/tests/test_image.py b/fuel_agent/tests/test_image.py index a0ea9dc..fc1a454 100644 --- a/fuel_agent/tests/test_image.py +++ b/fuel_agent/tests/test_image.py @@ -13,13 +13,13 @@ # limitations under the License. -from oslotest import base as test_base +import unittest2 from fuel_agent import errors from fuel_agent.objects import image -class TestImage(test_base.BaseTestCase): +class TestImage(unittest2.TestCase): def test_unsupported_container(self): self.assertRaises(errors.WrongImageDataError, image.Image, 'uri', diff --git a/fuel_agent/tests/test_ks_spaces_validator.py b/fuel_agent/tests/test_ks_spaces_validator.py index 23d3001..460e067 100644 --- a/fuel_agent/tests/test_ks_spaces_validator.py +++ b/fuel_agent/tests/test_ks_spaces_validator.py @@ -14,7 +14,7 @@ import copy -from oslotest import base as test_base +import unittest2 from fuel_agent.drivers import ks_spaces_validator as kssv from fuel_agent import errors @@ -182,7 +182,7 @@ SAMPLE_SCHEME = [ ] -class TestKSSpacesValidator(test_base.BaseTestCase): +class TestKSSpacesValidator(unittest2.TestCase): def setUp(self): super(TestKSSpacesValidator, self).setUp() self.fake_scheme = copy.deepcopy(SAMPLE_SCHEME) diff --git a/fuel_agent/tests/test_lvm_utils.py b/fuel_agent/tests/test_lvm_utils.py index d4e7048..aeaba8f 100644 --- a/fuel_agent/tests/test_lvm_utils.py +++ b/fuel_agent/tests/test_lvm_utils.py @@ -13,14 +13,14 @@ # limitations under the License. import mock -from oslotest import base as test_base +import unittest2 from fuel_agent import errors from fuel_agent.utils import lvm as lu from fuel_agent.utils import utils -class TestLvmUtils(test_base.BaseTestCase): +class TestLvmUtils(unittest2.TestCase): @mock.patch.object(utils, 'execute') def test_pvdisplay(self, mock_exec): diff --git a/fuel_agent/tests/test_manager.py b/fuel_agent/tests/test_manager.py index f1d20f3..cc469bc 100644 --- a/fuel_agent/tests/test_manager.py +++ b/fuel_agent/tests/test_manager.py @@ -13,12 +13,12 @@ # limitations under the License. import copy -import mock import os import signal +import mock from oslo.config import cfg -from oslotest import base as test_base +import unittest2 from fuel_agent.drivers import nailgun from fuel_agent import errors @@ -37,7 +37,7 @@ from fuel_agent.utils import utils CONF = cfg.CONF -class TestManager(test_base.BaseTestCase): +class TestManager(unittest2.TestCase): @mock.patch('yaml.load') @mock.patch.object(utils, 'init_http_request') @@ -547,7 +547,7 @@ none /run/shm tmpfs rw,nosuid,nodev 0 0""" mock_fu.umount_fs.call_args_list) -class TestImageBuild(test_base.BaseTestCase): +class TestImageBuild(unittest2.TestCase): @mock.patch('yaml.load') @mock.patch.object(utils, 'init_http_request') diff --git a/fuel_agent/tests/test_md_utils.py b/fuel_agent/tests/test_md_utils.py index 4be957f..62742cb 100644 --- a/fuel_agent/tests/test_md_utils.py +++ b/fuel_agent/tests/test_md_utils.py @@ -13,8 +13,8 @@ # limitations under the License. import mock -from oslotest import base as test_base import six +import unittest2 from fuel_agent import errors from fuel_agent.utils import hardware as hu @@ -28,7 +28,7 @@ else: OPEN_FUNCTION_NAME = 'builtins.open' -class TestMdUtils(test_base.BaseTestCase): +class TestMdUtils(unittest2.TestCase): @mock.patch('fuel_agent.utils.md.utils.execute') def test_mddisplay_nostate_detail(self, mock_exec): diff --git a/fuel_agent/tests/test_nailgun.py b/fuel_agent/tests/test_nailgun.py index c067bc6..9569fd0 100644 --- a/fuel_agent/tests/test_nailgun.py +++ b/fuel_agent/tests/test_nailgun.py @@ -13,9 +13,9 @@ # limitations under the License. import copy -import mock -from oslotest import base as test_base +import mock +import unittest2 import yaml from fuel_agent.drivers import nailgun @@ -579,7 +579,7 @@ MANY_HUGE_DISKS_KS_SPACES = [ ] -class TestNailgun(test_base.BaseTestCase): +class TestNailgun(unittest2.TestCase): def test_match_device_by_id_matches(self): # matches by 'by-id' links diff --git a/fuel_agent/tests/test_partition.py b/fuel_agent/tests/test_partition.py index cbc140d..9472226 100644 --- a/fuel_agent/tests/test_partition.py +++ b/fuel_agent/tests/test_partition.py @@ -13,7 +13,6 @@ # limitations under the License. import mock - import unittest2 from fuel_agent import errors @@ -21,7 +20,6 @@ from fuel_agent.objects import partition class TestMultipleDevice(unittest2.TestCase): - def setUp(self): super(self.__class__, self).setUp() self.md = partition.MD(name='name', level='level') @@ -76,7 +74,6 @@ class TestMultipleDevice(unittest2.TestCase): class TestPartition(unittest2.TestCase): - def setUp(self): super(TestPartition, self).setUp() self.pt = partition.Partition('name', 'count', 'device', 'begin', @@ -109,7 +106,6 @@ class TestPartition(unittest2.TestCase): class TestPartitionScheme(unittest2.TestCase): - def setUp(self): super(TestPartitionScheme, self).setUp() self.p_scheme = partition.PartitionScheme() diff --git a/fuel_agent/tests/test_partition_utils.py b/fuel_agent/tests/test_partition_utils.py index 563dbf6..3f41b59 100644 --- a/fuel_agent/tests/test_partition_utils.py +++ b/fuel_agent/tests/test_partition_utils.py @@ -12,16 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock -from oslotest import base as test_base import time +import mock +import unittest2 + from fuel_agent import errors from fuel_agent.utils import partition as pu from fuel_agent.utils import utils -class TestPartitionUtils(test_base.BaseTestCase): +class TestPartitionUtils(unittest2.TestCase): @mock.patch.object(pu, 'make_label') def test_wipe(self, mock_label): # should run call make_label method diff --git a/fuel_agent/tests/test_utils.py b/fuel_agent/tests/test_utils.py index 42f9925..8e085b0 100644 --- a/fuel_agent/tests/test_utils.py +++ b/fuel_agent/tests/test_utils.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools +import socket import mock from oslo.config import cfg import requests -import socket import stevedore +import unittest2 import urllib3 from fuel_agent import errors @@ -29,7 +29,7 @@ from fuel_agent.utils import utils CONF = cfg.CONF -class ExecuteTestCase(testtools.TestCase): +class ExecuteTestCase(unittest2.TestCase): """This class is partly based on the same class in openstack/ironic.""" def setUp(self): diff --git a/test-requirements.txt b/test-requirements.txt index 2659664..ecf5ce8 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,9 +1,6 @@ hacking>=0.8.0,<0.9 mock==1.0.1 -# TODO(prmtl): remove oslotest and (probably) testools in favor of unittest2 -oslotest==1.0 -testtools>=0.9.34 -unittest2==1.0.1 pytest>=2.7.2 pytest-cov>=1.8.1 requests-mock>=0.6 +unittest2==1.1.0