Use stub_out and mock to remove mox: part 2
This change replaces the use of stubs in a few files with stub_out, which was introduced in test.py. Also, remove mox usage in some of the files. unit/test_wsgi.py unit/test_versions.py unit/test_utils.py Part of bp:remove-mox Change-Id: I0ba80882e745fdf6a208db2455df0a1b458ce836
This commit is contained in:
parent
816d90f999
commit
c79fec1967
|
@ -141,7 +141,7 @@ class GenericUtilsTestCase(test.NoDBTestCase):
|
|||
raise processutils.ProcessExecutionError()
|
||||
return 'fakecontents', None
|
||||
|
||||
self.stubs.Set(utils, 'execute', fake_execute)
|
||||
self.stub_out('nova.utils.execute', fake_execute)
|
||||
contents = utils.read_file_as_root('good')
|
||||
self.assertEqual(contents, 'fakecontents')
|
||||
self.assertRaises(exception.FileNotFound,
|
||||
|
@ -151,7 +151,7 @@ class GenericUtilsTestCase(test.NoDBTestCase):
|
|||
def fake_execute(*args, **kwargs):
|
||||
if args[0] == 'chown':
|
||||
fake_execute.uid = args[1]
|
||||
self.stubs.Set(utils, 'execute', fake_execute)
|
||||
self.stub_out('nova.utils.execute', fake_execute)
|
||||
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
with utils.temporary_chown(f.name, owner_uid=2):
|
||||
|
@ -743,34 +743,41 @@ class AuditPeriodTest(test.NoDBTestCase):
|
|||
|
||||
class MkfsTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_mkfs(self):
|
||||
self.mox.StubOutWithMock(utils, 'execute')
|
||||
utils.execute('mkfs', '-t', 'ext4', '-F', '/my/block/dev',
|
||||
run_as_root=False)
|
||||
utils.execute('mkfs', '-t', 'msdos', '/my/msdos/block/dev',
|
||||
run_as_root=False)
|
||||
utils.execute('mkswap', '/my/swap/block/dev',
|
||||
run_as_root=False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@mock.patch('nova.utils.execute')
|
||||
def test_mkfs_ext4(self, mock_execute):
|
||||
utils.mkfs('ext4', '/my/block/dev')
|
||||
mock_execute.assert_called_once_with('mkfs', '-t', 'ext4', '-F',
|
||||
'/my/block/dev', run_as_root=False)
|
||||
|
||||
@mock.patch('nova.utils.execute')
|
||||
def test_mkfs_msdos(self, mock_execute):
|
||||
utils.mkfs('msdos', '/my/msdos/block/dev')
|
||||
mock_execute.assert_called_once_with('mkfs', '-t', 'msdos',
|
||||
'/my/msdos/block/dev', run_as_root=False)
|
||||
|
||||
@mock.patch('nova.utils.execute')
|
||||
def test_mkfs_swap(self, mock_execute):
|
||||
utils.mkfs('swap', '/my/swap/block/dev')
|
||||
mock_execute.assert_called_once_with('mkswap', '/my/swap/block/dev',
|
||||
run_as_root=False)
|
||||
|
||||
def test_mkfs_with_label(self):
|
||||
self.mox.StubOutWithMock(utils, 'execute')
|
||||
utils.execute('mkfs', '-t', 'ext4', '-F',
|
||||
'-L', 'ext4-vol', '/my/block/dev', run_as_root=False)
|
||||
utils.execute('mkfs', '-t', 'msdos',
|
||||
'-n', 'msdos-vol', '/my/msdos/block/dev',
|
||||
run_as_root=False)
|
||||
utils.execute('mkswap', '-L', 'swap-vol', '/my/swap/block/dev',
|
||||
run_as_root=False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@mock.patch('nova.utils.execute')
|
||||
def test_mkfs_ext4_withlabel(self, mock_execute):
|
||||
utils.mkfs('ext4', '/my/block/dev', 'ext4-vol')
|
||||
mock_execute.assert_called_once_with('mkfs', '-t', 'ext4', '-F',
|
||||
'-L', 'ext4-vol', '/my/block/dev', run_as_root=False)
|
||||
|
||||
@mock.patch('nova.utils.execute')
|
||||
def test_mkfs_msdos_withlabel(self, mock_execute):
|
||||
utils.mkfs('msdos', '/my/msdos/block/dev', 'msdos-vol')
|
||||
mock_execute.assert_called_once_with('mkfs', '-t', 'msdos',
|
||||
'-n', 'msdos-vol', '/my/msdos/block/dev', run_as_root=False)
|
||||
|
||||
@mock.patch('nova.utils.execute')
|
||||
def test_mkfs_swap_withlabel(self, mock_execute):
|
||||
utils.mkfs('swap', '/my/swap/block/dev', 'swap-vol')
|
||||
mock_execute.assert_called_once_with('mkswap', '-L', 'swap-vol',
|
||||
'/my/swap/block/dev', run_as_root=False)
|
||||
|
||||
|
||||
class LastBytesTestCase(test.NoDBTestCase):
|
||||
|
|
|
@ -26,9 +26,9 @@ class VersionTestCase(test.NoDBTestCase):
|
|||
def test_version_string_with_package_is_good(self):
|
||||
"""Ensure uninstalled code get version string."""
|
||||
|
||||
self.stubs.Set(version.version_info, 'version_string',
|
||||
self.stub_out('nova.version.version_info.version_string',
|
||||
lambda: '5.5.5.5')
|
||||
self.stubs.Set(version, 'NOVA_PACKAGE', 'g9ec3421')
|
||||
self.stub_out('nova.version.NOVA_PACKAGE', 'g9ec3421')
|
||||
self.assertEqual("5.5.5.5-g9ec3421",
|
||||
version.version_string_with_package())
|
||||
|
||||
|
@ -52,8 +52,8 @@ package = 1337"""
|
|||
|
||||
return real_open(path, *args, **kwargs)
|
||||
|
||||
self.stubs.Set(builtins, 'open', fake_open)
|
||||
self.stubs.Set(cfg.ConfigOpts, 'find_file', fake_find_file)
|
||||
self.stub_out('six.moves.builtins.open', fake_open)
|
||||
self.stub_out('oslo_config.cfg.ConfigOpts.find_file', fake_find_file)
|
||||
|
||||
self.assertEqual(version.vendor_string(), "ACME Corporation")
|
||||
self.assertEqual(version.product_string(), "ACME Nova")
|
||||
|
|
|
@ -44,7 +44,7 @@ class TestLoaderNothingExists(test.NoDBTestCase):
|
|||
|
||||
def setUp(self):
|
||||
super(TestLoaderNothingExists, self).setUp()
|
||||
self.stubs.Set(os.path, 'exists', lambda _: False)
|
||||
self.stub_out('os.path.exists', lambda _: False)
|
||||
|
||||
def test_relpath_config_not_found(self):
|
||||
self.flags(api_paste_config='api-paste.ini')
|
||||
|
|
Loading…
Reference in New Issue