Fix imageutils tests on windows
Some of the imageutils unit tests are currently failing on Windows.
Two of them make assertions on arguments that are platform dependent
while another one fails due to the fact that os.path.join cannot
be used with mock objects on Windows.
This change fixes those issues.
@@ -31,6 +31,7 @@ from cinder.volume import throttling
class TestQemuImgInfo(test.TestCase):
+ @mock.patch('os.name', new='posix')
@mock.patch('oslo_utils.imageutils.QemuImgInfo')
@mock.patch('cinder.utils.execute')
def test_qemu_img_info(self, mock_exec, mock_info):
@@ -45,6 +46,7 @@ class TestQemuImgInfo(test.TestCase):
prlimit=image_utils.QEMU_IMG_LIMITS)
self.assertEqual(mock_info.return_value, output)
+ @mock.patch('os.name', new='posix')
@mock.patch('oslo_utils.imageutils.QemuImgInfo')
@mock.patch('cinder.utils.execute')
def test_qemu_img_info_not_root(self, mock_exec, mock_info):
@@ -1475,6 +1477,9 @@ class TestVhdUtils(test.TestCase):
mock.sentinel.fourth,
mock.sentinel.fifth)
+ # os.path.join does not work with MagicMock objects on Windows.
+ mock_temp.return_value.__enter__.return_value = 'fake_temp_dir'
+
output = image_utils.coalesce_chain(vhd_chain)
self.assertEqual(mock.sentinel.fifth, output)
