From 55410888de5d477274d395fd2a976ad5a54fbb7a Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Mon, 29 Aug 2016 10:40:36 +0100 Subject: [PATCH] Fix pep8 on Python3.5 This patch is fixing the pep8 warning messages when running "tox -epep8" with the python3.5 interpreter (the default on some distros, e.g Arch Linux). The method file_open() from common/utils.py was removed because it wasn't being used anywhere and was violating pep8 by using file() which is only present in python2. Change-Id: Ie9356a870ea7b271aa44db57accba02f52b3e948 Closes-Bug: #1617947 --- devstack/tools/ironic/scripts/configure-vm.py | 2 +- ironic/common/exception.py | 4 ++-- ironic/common/utils.py | 12 ------------ ironic/tests/unit/api/v1/test_types.py | 5 ++--- ironic/tests/unit/common/test_exception.py | 4 +--- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/devstack/tools/ironic/scripts/configure-vm.py b/devstack/tools/ironic/scripts/configure-vm.py index 26feadd736..cc466629de 100755 --- a/devstack/tools/ironic/scripts/configure-vm.py +++ b/devstack/tools/ironic/scripts/configure-vm.py @@ -80,7 +80,7 @@ def main(): parser.add_argument('--disk-format', default='qcow2', help='Disk format to use.') args = parser.parse_args() - with file(templatedir + '/vm.xml', 'rb') as f: + with open(templatedir + '/vm.xml', 'rb') as f: source_template = f.read() params = { 'name': args.name, diff --git a/ironic/common/exception.py b/ironic/common/exception.py index 4a3aae49e7..df9f738e6f 100644 --- a/ironic/common/exception.py +++ b/ironic/common/exception.py @@ -78,13 +78,13 @@ class IronicException(Exception): def __str__(self): """Encode to utf-8 then wsme api can consume it as well.""" if not six.PY3: - return unicode(self.args[0]).encode('utf-8') + return six.text_type(self.args[0]).encode('utf-8') return self.args[0] def __unicode__(self): """Return a unicode representation of the exception message.""" - return unicode(self.args[0]) + return six.text_type(self.args[0]) class NotAuthorized(IronicException): diff --git a/ironic/common/utils.py b/ironic/common/utils.py index e2226c896e..5b87863181 100644 --- a/ironic/common/utils.py +++ b/ironic/common/utils.py @@ -372,18 +372,6 @@ def read_cached_file(filename, cache_info, reload_func=None): return cache_info['data'] -def file_open(*args, **kwargs): - """Open file - - see built-in file() documentation for more details - - Note: The reason this is kept in a separate module is to easily - be able to provide a stub module that doesn't alter system - state at all (for unit tests) - """ - return file(*args, **kwargs) - - def _get_hash_object(hash_algo_name): """Create a hash object based on given algorithm. diff --git a/ironic/tests/unit/api/v1/test_types.py b/ironic/tests/unit/api/v1/test_types.py index 0c7e5ce450..34f4679fdc 100644 --- a/ironic/tests/unit/api/v1/test_types.py +++ b/ironic/tests/unit/api/v1/test_types.py @@ -285,9 +285,8 @@ class TestJsonType(base.TestCase): def test_apimultitype_tostring(self): vts = str(types.jsontype) self.assertIn(str(wtypes.text), vts) - self.assertIn(str(int), vts) - if six.PY2: - self.assertIn(str(long), vts) + for int_type in six.integer_types: + self.assertIn(str(int_type), vts) self.assertIn(str(float), vts) self.assertIn(str(types.BooleanType), vts) self.assertIn(str(list), vts) diff --git a/ironic/tests/unit/common/test_exception.py b/ironic/tests/unit/common/test_exception.py index c4dee60458..443b36ae36 100644 --- a/ironic/tests/unit/common/test_exception.py +++ b/ironic/tests/unit/common/test_exception.py @@ -23,8 +23,6 @@ class TestIronicException(base.TestCase): expected = b'\xc3\xa9\xe0\xaf\xb2\xe0\xbe\x84' if six.PY3: expected = expected.decode('utf-8') - message = chr(233) + chr(0x0bf2) + chr(3972) - else: - message = unichr(233) + unichr(0x0bf2) + unichr(3972) + message = six.unichr(233) + six.unichr(0x0bf2) + six.unichr(3972) exc = exception.IronicException(message) self.assertEqual(expected, exc.__str__())