Merge "Get rid of testtools and fixtures"

This commit is contained in:
Zuul 2020-05-06 16:21:56 +00:00 committed by Gerrit Code Review
commit 9aeaa29f5d
7 changed files with 44 additions and 48 deletions

View File

@ -16,11 +16,9 @@
import io import io
import json import json
import tempfile import tempfile
import unittest
from unittest import mock from unittest import mock
import fixtures
import testtools
from metalsmith import _cmd from metalsmith import _cmd
from metalsmith import _instance from metalsmith import _instance
from metalsmith import _provisioner from metalsmith import _provisioner
@ -28,17 +26,26 @@ from metalsmith import instance_config
from metalsmith import sources from metalsmith import sources
class Base(unittest.TestCase):
def setUp(self):
super(Base, self).setUp()
print_fixture = mock.patch(
'metalsmith._format._print', autospec=True)
self.mock_print = print_fixture.start()
self.addCleanup(print_fixture.stop)
@mock.patch.object(_provisioner, 'Provisioner', autospec=True) @mock.patch.object(_provisioner, 'Provisioner', autospec=True)
class TestDeploy(testtools.TestCase): class TestDeploy(Base):
def setUp(self): def setUp(self):
super(TestDeploy, self).setUp() super(TestDeploy, self).setUp()
self.print_fixture = self.useFixture(fixtures.MockPatch(
'metalsmith._format._print', autospec=True))
self.mock_print = self.print_fixture.mock
self.os_conf_fixture = self.useFixture(fixtures.MockPatchObject( os_conf_fixture = mock.patch.object(
_cmd.os_config, 'OpenStackConfig', autospec=True)) _cmd.os_config, 'OpenStackConfig', autospec=True)
self.mock_os_conf = self.os_conf_fixture.mock self.mock_os_conf = os_conf_fixture.start()
self.addCleanup(os_conf_fixture.stop)
self._init = False self._init = False
def _check(self, mock_pr, args, reserve_args, provision_args, def _check(self, mock_pr, args, reserve_args, provision_args,
@ -530,13 +537,7 @@ class TestDeploy(testtools.TestCase):
@mock.patch.object(_provisioner, 'Provisioner', autospec=True) @mock.patch.object(_provisioner, 'Provisioner', autospec=True)
@mock.patch.object(_cmd.os_config, 'OpenStackConfig', autospec=True) @mock.patch.object(_cmd.os_config, 'OpenStackConfig', autospec=True)
class TestUndeploy(testtools.TestCase): class TestUndeploy(Base):
def setUp(self):
super(TestUndeploy, self).setUp()
self.print_fixture = self.useFixture(fixtures.MockPatch(
'metalsmith._format._print', autospec=True))
self.mock_print = self.print_fixture.mock
def test_ok(self, mock_os_conf, mock_pr): def test_ok(self, mock_os_conf, mock_pr):
node = mock_pr.return_value.unprovision_node.return_value node = mock_pr.return_value.unprovision_node.return_value
node.id = '123' node.id = '123'
@ -617,12 +618,9 @@ class TestUndeploy(testtools.TestCase):
@mock.patch.object(_provisioner, 'Provisioner', autospec=True) @mock.patch.object(_provisioner, 'Provisioner', autospec=True)
@mock.patch.object(_cmd.os_config, 'OpenStackConfig', autospec=True) @mock.patch.object(_cmd.os_config, 'OpenStackConfig', autospec=True)
class TestShowWait(testtools.TestCase): class TestShowWait(Base):
def setUp(self): def setUp(self):
super(TestShowWait, self).setUp() super(TestShowWait, self).setUp()
self.print_fixture = self.useFixture(fixtures.MockPatch(
'metalsmith._format._print', autospec=True))
self.mock_print = self.print_fixture.mock
self.instances = [ self.instances = [
mock.Mock( mock.Mock(
spec=_instance.Instance, spec=_instance.Instance,

View File

@ -14,14 +14,13 @@
# limitations under the License. # limitations under the License.
import json import json
import unittest
from unittest import mock from unittest import mock
import testtools
from metalsmith import instance_config from metalsmith import instance_config
class TestGenericConfig(testtools.TestCase): class TestGenericConfig(unittest.TestCase):
CLASS = instance_config.GenericConfig CLASS = instance_config.GenericConfig
def setUp(self): def setUp(self):

View File

@ -13,12 +13,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import unittest
from unittest import mock from unittest import mock
import fixtures
from openstack import exceptions as os_exc from openstack import exceptions as os_exc
import requests import requests
import testtools
from metalsmith import _instance from metalsmith import _instance
from metalsmith import _provisioner from metalsmith import _provisioner
@ -34,7 +33,7 @@ NODE_FIELDS = ['name', 'id', 'instance_info', 'instance_id', 'is_maintenance',
'allocation_id'] 'allocation_id']
class TestInit(testtools.TestCase): class TestInit(unittest.TestCase):
def test_missing_auth(self): def test_missing_auth(self):
self.assertRaisesRegex(TypeError, 'must be provided', self.assertRaisesRegex(TypeError, 'must be provided',
_provisioner.Provisioner) _provisioner.Provisioner)
@ -58,7 +57,7 @@ class TestInit(testtools.TestCase):
mock_conn.assert_called_once_with(config=region) mock_conn.assert_called_once_with(config=region)
class Base(testtools.TestCase): class Base(unittest.TestCase):
def setUp(self): def setUp(self):
super(Base, self).setUp() super(Base, self).setUp()
@ -73,9 +72,11 @@ class Base(testtools.TestCase):
self.node.name = 'control-0' self.node.name = 'control-0'
def _reset_api_mock(self): def _reset_api_mock(self):
self.mock_get_node = self.useFixture( get_node_patcher = mock.patch.object(
fixtures.MockPatchObject(_provisioner.Provisioner, '_get_node', _provisioner.Provisioner, '_get_node', autospec=True)
autospec=True)).mock self.mock_get_node = get_node_patcher.start()
self.addCleanup(get_node_patcher.stop)
self.mock_get_node.side_effect = ( self.mock_get_node.side_effect = (
lambda self, n, refresh=False: n lambda self, n, refresh=False: n
) )
@ -92,7 +93,7 @@ class Base(testtools.TestCase):
self.pr.connection = self.api self.pr.connection = self.api
class TestGetFindNode(testtools.TestCase): class TestGetFindNode(unittest.TestCase):
def setUp(self): def setUp(self):
super(TestGetFindNode, self).setUp() super(TestGetFindNode, self).setUp()
@ -503,10 +504,12 @@ class TestProvisionNode(Base):
self.api.network.create_port.return_value.id self.api.network.create_port.return_value.id
], ],
} }
self.configdrive_mock = self.useFixture(
fixtures.MockPatchObject(instance_config.GenericConfig, configdrive_patcher = mock.patch.object(
'generate', autospec=True) instance_config.GenericConfig, 'generate', autospec=True)
).mock self.configdrive_mock = configdrive_patcher.start()
self.addCleanup(configdrive_patcher.stop)
self.api.baremetal.get_node.side_effect = lambda _n: self.node self.api.baremetal.get_node.side_effect = lambda _n: self.node
self.api.baremetal.get_allocation.side_effect = ( self.api.baremetal.get_allocation.side_effect = (
lambda _a: self.allocation) lambda _a: self.allocation)
@ -1934,7 +1937,7 @@ class TestUnprovisionNode(Base):
self.assertFalse(self.api.baremetal.update_node.called) self.assertFalse(self.api.baremetal.update_node.called)
class TestShowInstance(testtools.TestCase): class TestShowInstance(unittest.TestCase):
def setUp(self): def setUp(self):
super(TestShowInstance, self).setUp() super(TestShowInstance, self).setUp()
self.pr = _provisioner.Provisioner(mock.Mock()) self.pr = _provisioner.Provisioner(mock.Mock())

View File

@ -13,15 +13,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import unittest
from unittest import mock from unittest import mock
import testtools
from metalsmith import _scheduler from metalsmith import _scheduler
from metalsmith import exceptions from metalsmith import exceptions
class TestRunFilters(testtools.TestCase): class TestRunFilters(unittest.TestCase):
def setUp(self): def setUp(self):
super(TestRunFilters, self).setUp() super(TestRunFilters, self).setUp()
@ -74,7 +73,7 @@ class TestRunFilters(testtools.TestCase):
filters[2].fail.assert_called_once_with() filters[2].fail.assert_called_once_with()
class TestCapabilitiesFilter(testtools.TestCase): class TestCapabilitiesFilter(unittest.TestCase):
def test_fail_no_capabilities(self): def test_fail_no_capabilities(self):
fltr = _scheduler.CapabilitiesFilter({'profile': 'compute'}) fltr = _scheduler.CapabilitiesFilter({'profile': 'compute'})

View File

@ -13,15 +13,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import unittest
from unittest import mock from unittest import mock
import testtools
from metalsmith import exceptions from metalsmith import exceptions
from metalsmith import sources from metalsmith import sources
class TestDetect(testtools.TestCase): class TestDetect(unittest.TestCase):
def test_glance_whole_disk(self): def test_glance_whole_disk(self):
source = sources.detect('foobar') source = sources.detect('foobar')

View File

@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import testtools import unittest
from metalsmith import _utils from metalsmith import _utils
class TestIsHostnameSafe(testtools.TestCase): class TestIsHostnameSafe(unittest.TestCase):
def test_valid(self): def test_valid(self):
self.assertTrue(_utils.is_hostname_safe('spam')) self.assertTrue(_utils.is_hostname_safe('spam'))

View File

@ -4,8 +4,6 @@
coverage!=4.4,>=4.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0
doc8>=0.6.0 # Apache-2.0 doc8>=0.6.0 # Apache-2.0
flake8-import-order>=0.13 # LGPLv3 flake8-import-order>=0.13 # LGPLv3
fixtures>=3.0.0 # Apache-2.0/BSD
hacking>=3.0.0,<3.1.0 # Apache-2.0 hacking>=3.0.0,<3.1.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0 stestr>=1.0.0 # Apache-2.0
testtools>=2.2.0 # MIT
Pygments>=2.2.0 # BSD Pygments>=2.2.0 # BSD