From 432c23dddbc1adc236f38b8c01c85783dee8c189 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 30 Jun 2015 16:47:15 +0200 Subject: [PATCH] Fix Python 3 issues in cmd * Replace filter() with a list-comprehension using if to get a list on Python 3. * Get the mock module from the stdlib unittest module on Python 3.3 and newer, or fallback to the third-party mock module. * Replace __builtin__ with six.moves.builtins. * tox.ini: add the following tests for Python 3.4 - cinder.tests.unit.test_api - cinder.tests.unit.test_cmd Blueprint cinder-python3 Change-Id: Iea516ae598e8eebfc1087663a9b3e0a00d0633d3 --- cinder/cmd/rtstool.py | 2 +- cinder/tests/unit/test_cmd.py | 9 ++++++--- tox.ini | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cinder/cmd/rtstool.py b/cinder/cmd/rtstool.py index a1ae0b1a9..4714f4130 100644 --- a/cinder/cmd/rtstool.py +++ b/cinder/cmd/rtstool.py @@ -229,7 +229,7 @@ def parse_optional_create(argv): for arg in argv: if arg.startswith('-a'): - ips = filter(None, arg[2:].split(',')) + ips = [ip for ip in arg[2:].split(',') if ip] if not ips: usage() optional_args['portals_ips'] = ips diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index 1cd592de5..25c04f9ec 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -14,7 +14,10 @@ import datetime import six import sys -import mock +try: + from unittest import mock +except ImportError: + import mock from oslo_config import cfg try: @@ -533,7 +536,7 @@ class TestCinderManageCmd(test.TestCase): self.assertEqual(expected_out, fake_out.getvalue()) - @mock.patch('__builtin__.open') + @mock.patch('six.moves.builtins.open') @mock.patch('os.listdir') def test_get_log_commands_errors(self, listdir, open): CONF.set_override('log_dir', 'fake-dir') @@ -552,7 +555,7 @@ class TestCinderManageCmd(test.TestCase): open.assert_called_once_with('fake-dir/fake-error.log', 'r') listdir.assert_called_once_with(CONF.log_dir) - @mock.patch('__builtin__.open') + @mock.patch('six.moves.builtins.open') @mock.patch('os.path.exists') def test_get_log_commands_syslog_no_log_file(self, path_exists, open): path_exists.return_value = False diff --git a/tox.ini b/tox.ini index 1ff355b83..faccff1fe 100644 --- a/tox.ini +++ b/tox.ini @@ -35,6 +35,7 @@ commands = cinder.tests.unit.targets.test_lio_driver \ cinder.tests.unit.targets.test_scst_driver \ cinder.tests.unit.targets.test_tgt_driver \ + cinder.tests.unit.test_api \ cinder.tests.unit.test_api_urlmap \ cinder.tests.unit.test_backup \ cinder.tests.unit.test_backup_ceph \ @@ -44,6 +45,7 @@ commands = cinder.tests.unit.test_block_device \ cinder.tests.unit.test_blockbridge \ cinder.tests.unit.test_cloudbyte \ + cinder.tests.unit.test_cmd \ cinder.tests.unit.test_conf \ cinder.tests.unit.test_context \ cinder.tests.unit.test_create_volume_flow \ -- 2.45.2