From 346b7c468a87b4d539898949a63f025aaf38dd98 Mon Sep 17 00:00:00 2001 From: chen-li Date: Sat, 27 Dec 2014 18:41:21 +0800 Subject: [PATCH] py3: use six.moves.range instead of xrange six is the canonical compatibility library for supporting Python 2 and 3 in a single codebase. The xrange module was removed in Python 3 and we should use 'six.moves.range' instead of 'xrange' to make code compatible with py 2 and 3 as well. Partially-implements blueprint py3-compatibility Change-Id: Id054857f320d9eda02bc0b82e5512c0595342290 --- doc/ext/manila_todo.py | 3 ++- manila/tests/api/v1/test_limits.py | 3 ++- manila/tests/scheduler/test_host_manager.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/ext/manila_todo.py b/doc/ext/manila_todo.py index 280ea926af..bda34ecb88 100644 --- a/doc/ext/manila_todo.py +++ b/doc/ext/manila_todo.py @@ -2,6 +2,7 @@ # This is a hack of the builtin todo extension, to make the todo_list # more user friendly +from six import moves from sphinx.ext.todo import * import re @@ -25,7 +26,7 @@ def process_todo_nodes(app, doctree, fromdocname): # remove the item that was added in the constructor, since I'm tired of # reading through docutils for the proper way to construct an empty list lists = [] - for i in xrange(5): + for i in moves.range(5): lists.append(nodes.bullet_list("", nodes.Text('', ''))) lists[i].remove(lists[i][0]) lists[i]['classes'].append('todo_list') diff --git a/manila/tests/api/v1/test_limits.py b/manila/tests/api/v1/test_limits.py index 51e288f558..042b536237 100644 --- a/manila/tests/api/v1/test_limits.py +++ b/manila/tests/api/v1/test_limits.py @@ -23,6 +23,7 @@ from xml.dom import minidom from lxml import etree from oslo.serialization import jsonutils import six +from six import moves import webob from manila.api.v1 import limits @@ -407,7 +408,7 @@ class LimiterTest(BaseLimitTestSuite): def _check(self, num, verb, url, username=None): """Check and yield results from checks.""" - for x in xrange(num): + for x in moves.range(num): yield self.limiter.check_for_delay(verb, url, username)[0] def _check_sum(self, num, verb, url, username=None): diff --git a/manila/tests/scheduler/test_host_manager.py b/manila/tests/scheduler/test_host_manager.py index d9a4b24bbb..f074f54cd5 100644 --- a/manila/tests/scheduler/test_host_manager.py +++ b/manila/tests/scheduler/test_host_manager.py @@ -20,6 +20,7 @@ import datetime import mock from oslo.config import cfg from oslo.utils import timeutils +from six import moves from manila import db from manila import exception @@ -48,7 +49,7 @@ class HostManagerTestCase(test.TestCase): super(HostManagerTestCase, self).setUp() self.host_manager = host_manager.HostManager() self.fake_hosts = [host_manager.HostState('fake_host%s' % x) - for x in xrange(1, 5)] + for x in moves.range(1, 5)] def test_choose_host_filters_not_found(self): self.flags(scheduler_default_filters='FakeFilterClass3') @@ -148,7 +149,7 @@ class HostManagerTestCase(test.TestCase): self.assertEqual(4, len(host_state_map)) # Check that service is up - for i in xrange(4): + for i in moves.range(4): share_node = fakes.SHARE_SERVICES[i] host = share_node['host'] self.assertEqual(share_node, host_state_map[host].service)