From 4bffb73331a82254bd692bb69fdcbf6d6e0d0a56 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Wed, 21 Jan 2015 02:37:15 +0200 Subject: [PATCH] Fix all py3 related issues This patch makes output of `tox -epy34` to finish with following message: > py34: commands succeeded > congratulations :) Issues: * module "__builtin__" was renamed to "builtins" in Python 3 Related modules: - rally.api - tests.unit.benchmark.scenarios.vm.test_utils * function "map"/"filter" returns "builtins.map"/"builtins.filter" object in Python 3 instead of list in Python 2. "builtins.map" and "builtins.filter" object is not subscriptable and has no len(), so list comprehension is preferable to use and py2/py3 compatible way. Related modules: - rally.benchmark.context.sahara.sahara_edp - rally.benchmark.processing.plot - rally.benchmark.sla.base - rally.benchmark.types - rally.cmd.commands.task - rally.cmd.commands.verify - tests.unit.benchmark.scenarios.test_base - tests.unit.benchmark.wrappers.test_keystone - tests.unit.cmd.commands.test_task - tests.unit.cmd.commands.test_verify * dict.keys()/dict.values() returns "dict_keys"/"dict_values" object in Python 3 instead of list in Python 2. so list(dict) and list(dict.values()) should be used instead. Related modules: - rally.benchmark.scenarios.utils - rally.benchmark.scenarios.vm.vmtasks - tests.unit.cmd.commands.test_show - tests.unit.common.test_broker - tests.unit.deploy.engines.test_fuel - tests.unit.fakes * Some changes was made in Python 3 related to data model, so we should change our inspect code. See code changes for more details Related modules: - rally.cmd.cliutils - rally.common.utils * ConfigParser is more strict for duplicate items in Python 3, so duplicates are removed Related files: - rally/verification/tempest/config.ini * Exception object doesn't have "message" attribute in Python 3, so if we want to get it, the most proper way is using "getattr" Related modules: - rally.verification.tempest.config * "mock.MagicMock" is not sortable in Python 3, so we should add required attributes to fix that. Related modules: - tests.unit.benchmark.context.test_base * assertSequenceEqual assertation method was added in tests.unit.test to compare sequence objects Related modules: - tests.unit.benchmark.context.cleanup.test_resources - tests.unit.benchmark.scenarios.nova.test_utils * function "range" returns "range" object in Python 3 instead of list in Python 2. Related modules: - tests.unit.benchmark.processing.test_utils * keyword arguments should be transmitted to self.assertRaises as kwargs, not like a dict Related modules: - tests.unit.benchmark.scenarios.dummy.test_dummy Additional changes: * Python 2.6 was added to setup.cfg, since Rally supports it. * py33, py34 environments were added to tox.ini * wrong ignore path was removed from tox.ini * made items of bash complition sorted Several tests are skipped in Python 3 env. For more details see notes in code: - tests.unit.benchmark.processing.test_plot.PlotTestCase.test__process_main_time - tests.unit.benchmark.processing.test_plot.PlotTestCase.test__process_atomic_time - tests.unit.common.test_utils.MethodClassTestCase.test_method_class_for_class_level_method During porting Rally to Python3, several issues found and fixed in TempestContext and its unit tests: - If process of cleanup is failed, exception is handled and cleanup is marked as successfull. This issue was fixed and CleanUpException was added to rally.exception module - Cleanup was called with wrong path. Change-Id: If04e873790dcb4c9c882d4be4bf40479deedd36d --- setup.cfg | 1 + tests/unit/fakes.py | 4 ++-- tests/unit/test.py | 3 +++ tox.ini | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7640396f..013722b4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,7 @@ classifier = Operating System :: POSIX :: Linux Programming Language :: Python Programming Language :: Python :: 2 + Programming Language :: Python :: 2.6 Programming Language :: Python :: 2.7 [files] diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index 2a033d8c..3a3254a9 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -70,11 +70,11 @@ def setup_dict(data, required=None, defaults=None): :raises: IndexError, ValueError """ required = required or [] - for i in set(required) - set(data.keys()): + for i in set(required) - set(data): raise IndexError("Missed: %s" % i) defaults = defaults or {} - for i in set(data.keys()) - set(required + defaults.keys()): + for i in set(data) - set(required) - set(defaults): raise ValueError("Unexpected: %s" % i) defaults.update(data) diff --git a/tests/unit/test.py b/tests/unit/test.py index 4e3d64b5..d32bbc33 100644 --- a/tests/unit/test.py +++ b/tests/unit/test.py @@ -45,6 +45,9 @@ class TestCase(base.BaseTestCase): self.assertIsNotNone(action_duration) self.assertIsInstance(action_duration, float) + def assertSequenceEqual(self, iterable_1, iterable_2): + self.assertEqual(tuple(iterable_1), tuple(iterable_2)) + class DBTestCase(TestCase): """Base class for tests which use DB.""" diff --git a/tox.ini b/tox.ini index 35f52d04..1f93b9fa 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] minversion = 1.6 skipsdist = True -envlist = py26,py27,pep8 +envlist = py26,py27,py33,py34,pep8 [testenv] setenv = VIRTUAL_ENV={envdir} @@ -41,7 +41,7 @@ downloadcache = ~/cache/pip ignore = E126,H703 show-source = true builtins = _ -exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,*rally/verification/verifiers/tempest/openstack-tempest*,build,*rally/openstack* +exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build,*rally/openstack* [hacking] import_exceptions = rally.common.i18n