diff options
| author | Moshe Levi <moshele@mellanox.com> | 2016-02-17 14:08:42 +0200 |
|---|---|---|
| committer | Moshe Levi <moshele@mellanox.com> | 2016-02-17 14:08:52 +0200 |
| commit | 52fc4f891f59838ed5655f596ba9df1a4f2404ec (patch) | |
| tree | bd3d4547e5ca58c8a6dd8fdd8552f390aa48cc1e /ironic_python_agent | |
| parent | 559b25f56ea6667250a20c8fc2780773a3e373c7 (diff) | |
| download | ironic-python-agent-52fc4f891f59838ed5655f596ba9df1a4f2404ec.tar.gz | |
Update unit tests to use six.moves.builtins.open
Change-Id: I724a42d22d4c9011feb8aa09726e5186686f3729
Diffstat (limited to 'ironic_python_agent')
| -rw-r--r-- | ironic_python_agent/tests/unit/extensions/test_standby.py | 24 | ||||
| -rw-r--r-- | ironic_python_agent/tests/unit/test_hardware.py | 11 | ||||
| -rw-r--r-- | ironic_python_agent/tests/unit/test_utils.py | 13 |
3 files changed, 15 insertions, 33 deletions
diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py index 2c0149fd..75d2ce96 100644 --- a/ironic_python_agent/tests/unit/extensions/test_standby.py +++ b/ironic_python_agent/tests/unit/extensions/test_standby.py @@ -17,16 +17,10 @@ import os import mock from oslo_concurrency import processutils from oslotest import base as test_base -import six from ironic_python_agent import errors from ironic_python_agent.extensions import standby -if six.PY2: - OPEN_FUNCTION_NAME = '__builtin__.open' -else: - OPEN_FUNCTION_NAME = 'builtins.open' - def _build_fake_image_info(): return { @@ -97,7 +91,7 @@ class TestStandbyExtension(test_base.BaseTestCase): location = standby._image_location(image_info) self.assertEqual('/tmp/fake_id', location) - @mock.patch(OPEN_FUNCTION_NAME, autospec=True) + @mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True) def test_write_image(self, execute_mock, open_mock): image_info = _build_fake_image_info() @@ -137,7 +131,7 @@ class TestStandbyExtension(test_base.BaseTestCase): write_mock.assert_called_once_with('data', 'filename') @mock.patch('gzip.GzipFile', autospec=True) - @mock.patch(OPEN_FUNCTION_NAME, autospec=True) + @mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('base64.b64decode', autospec=True) def test_write_configdrive_to_file(self, b64_mock, open_mock, gzip_mock): open_mock.return_value.__enter__ = lambda s: s @@ -157,7 +151,7 @@ class TestStandbyExtension(test_base.BaseTestCase): @mock.patch(('ironic_python_agent.extensions.standby.' '_write_configdrive_to_file'), autospec=True) - @mock.patch(OPEN_FUNCTION_NAME, autospec=True) + @mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True) def test_write_configdrive_to_partition(self, execute_mock, open_mock, configdrive_mock, stat_mock): @@ -186,7 +180,7 @@ class TestStandbyExtension(test_base.BaseTestCase): @mock.patch(('ironic_python_agent.extensions.standby.' '_write_configdrive_to_file'), autospec=True) - @mock.patch(OPEN_FUNCTION_NAME, autospec=True) + @mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True) def test_write_configdrive_too_large(self, execute_mock, open_mock, configdrive_mock, stat_mock): @@ -200,7 +194,7 @@ class TestStandbyExtension(test_base.BaseTestCase): device) @mock.patch('hashlib.md5') - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') @mock.patch('requests.get') def test_download_image(self, requests_mock, open_mock, md5_mock): image_info = _build_fake_image_info() @@ -222,7 +216,7 @@ class TestStandbyExtension(test_base.BaseTestCase): self.assertEqual(2, write.call_count) @mock.patch('hashlib.md5') - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') @mock.patch('requests.get') @mock.patch.dict(os.environ, {}) def test_download_image_proxy( @@ -261,7 +255,7 @@ class TestStandbyExtension(test_base.BaseTestCase): image_info) @mock.patch('hashlib.md5', autospec=True) - @mock.patch(OPEN_FUNCTION_NAME, autospec=True) + @mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('requests.get', autospec=True) def test_download_image_verify_fails(self, requests_mock, open_mock, md5_mock): @@ -573,7 +567,7 @@ class TestStandbyExtension(test_base.BaseTestCase): write_mock.assert_called_once_with(image_info, device) @mock.patch('hashlib.md5') - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') @mock.patch('requests.get') def test_stream_raw_image_onto_device(self, requests_mock, open_mock, md5_mock): @@ -595,7 +589,7 @@ class TestStandbyExtension(test_base.BaseTestCase): file_mock.write.assert_has_calls(expected_calls) @mock.patch('hashlib.md5') - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') @mock.patch('requests.get') def test_stream_raw_image_onto_device_write_error(self, requests_mock, open_mock, md5_mock): diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index add20715..f3523da6 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -19,18 +19,12 @@ from oslo_concurrency import processutils from oslo_utils import units from oslotest import base as test_base import pyudev -import six from stevedore import extension from ironic_python_agent import errors from ironic_python_agent import hardware from ironic_python_agent import utils -if six.PY2: - OPEN_FUNCTION_NAME = '__builtin__.open' -else: - OPEN_FUNCTION_NAME = 'builtins.open' - HDPARM_INFO_TEMPLATE = ( '/dev/sda:\n' '\n' @@ -262,7 +256,7 @@ class TestGenericHardwareManager(test_base.BaseTestCase): @mock.patch('netifaces.ifaddresses') @mock.patch('os.listdir') @mock.patch('os.path.exists') - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') def test_list_network_interfaces(self, mocked_open, mocked_exists, @@ -392,7 +386,8 @@ class TestGenericHardwareManager(test_base.BaseTestCase): def test__get_device_vendor(self): fileobj = mock.mock_open(read_data='fake-vendor') - with mock.patch(OPEN_FUNCTION_NAME, fileobj, create=True) as mock_open: + with mock.patch( + 'six.moves.builtins.open', fileobj, create=True) as mock_open: vendor = hardware._get_device_vendor('/dev/sdfake') mock_open.assert_called_once_with( '/sys/class/block/sdfake/device/vendor', 'r') diff --git a/ironic_python_agent/tests/unit/test_utils.py b/ironic_python_agent/tests/unit/test_utils.py index 694fbb93..fd1cd5d6 100644 --- a/ironic_python_agent/tests/unit/test_utils.py +++ b/ironic_python_agent/tests/unit/test_utils.py @@ -23,18 +23,11 @@ import testtools import mock from oslo_concurrency import processutils from oslotest import base as test_base -import six from ironic_python_agent import errors from ironic_python_agent import utils -if six.PY2: - OPEN_FUNCTION_NAME = '__builtin__.open' -else: - OPEN_FUNCTION_NAME = 'builtins.open' - - class ExecuteTestCase(testtools.TestCase): """This class is a copy of the same class in openstack/ironic.""" @@ -135,13 +128,13 @@ grep foo class GetAgentParamsTestCase(test_base.BaseTestCase): @mock.patch('oslo_log.log.getLogger') - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') def test__read_params_from_file_fail(self, logger_mock, open_mock): open_mock.side_effect = Exception params = utils._read_params_from_file('file-path') self.assertEqual({}, params) - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') def test__read_params_from_file(self, open_mock): kernel_line = 'api-url=http://localhost:9999 baz foo=bar\n' open_mock.return_value.__enter__ = lambda s: s @@ -201,7 +194,7 @@ class GetAgentParamsTestCase(test_base.BaseTestCase): self.assertEqual(expected_params, returned_params) self.assertEqual(0, set_cache_mock.call_count) - @mock.patch(OPEN_FUNCTION_NAME) + @mock.patch('six.moves.builtins.open') @mock.patch.object(glob, 'glob') def test__get_vmedia_device(self, glob_mock, open_mock): |
