Change instances of x.next() to next(x)

partial blueprint heat-python34-support

Change-Id: Idf74dd430782ee3df90c6bb88432084187e0c089
This commit is contained in:
Sirushti Murugesan 2015-04-22 19:49:26 +05:30
parent 8a3aac038b
commit 8d3f96929a
5 changed files with 35 additions and 32 deletions

View File

@ -64,7 +64,7 @@ class FakeAutoScale(object):
def create(self, **kwargs): def create(self, **kwargs):
"""Create a scaling group.""" """Create a scaling group."""
new_id = str(self.group_counter.next()) new_id = str(next(self.group_counter))
fsg = FakeScalingGroup(new_id, **kwargs) fsg = FakeScalingGroup(new_id, **kwargs)
self.groups[new_id] = fsg self.groups[new_id] = fsg
return fsg return fsg
@ -119,7 +119,7 @@ class FakeAutoScale(object):
'scaling_group', 'name', 'policy_type', 'cooldown', 'change', 'scaling_group', 'name', 'policy_type', 'cooldown', 'change',
'is_percent', 'desired_capacity', 'args'] 'is_percent', 'desired_capacity', 'args']
self._check_args(kwargs, allowed) self._check_args(kwargs, allowed)
policy_id = str(self.policy_counter.next()) policy_id = str(next(self.policy_counter))
policy = FakeScalePolicy(policy_id, **kwargs) policy = FakeScalePolicy(policy_id, **kwargs)
self.policies[policy_id] = policy self.policies[policy_id] = policy
return policy return policy
@ -138,7 +138,7 @@ class FakeAutoScale(object):
"""Create and store a FakeWebHook.""" """Create and store a FakeWebHook."""
allowed = ['scaling_group', 'policy', 'name', 'metadata'] allowed = ['scaling_group', 'policy', 'name', 'metadata']
self._check_args(kwargs, allowed) self._check_args(kwargs, allowed)
webhook_id = str(self.webhook_counter.next()) webhook_id = str(next(self.webhook_counter))
webhook = FakeWebHook(webhook_id, **kwargs) webhook = FakeWebHook(webhook_id, **kwargs)
self.webhooks[webhook_id] = webhook self.webhooks[webhook_id] = webhook
return webhook return webhook
@ -399,7 +399,7 @@ Resources:
delete_counter = itertools.count() delete_counter = itertools.count()
def delete(group_id): def delete(group_id):
count = delete_counter.next() count = next(delete_counter)
if count < 3: if count < 3:
raise auto_scale.Forbidden("Not empty!") raise auto_scale.Forbidden("Not empty!")
@ -407,7 +407,7 @@ Resources:
resource = self.stack['my_group'] resource = self.stack['my_group']
scheduler.TaskRunner(resource.delete)() scheduler.TaskRunner(resource.delete)()
# It really called delete until it succeeded: # It really called delete until it succeeded:
self.assertEqual(4, delete_counter.next()) self.assertEqual(4, next(delete_counter))
def test_delete_blows_up_on_other_errors(self): def test_delete_blows_up_on_other_errors(self):
""" """

View File

@ -61,7 +61,7 @@ def upgrade(migrate_engine):
sqlalchemy.sql.expression.asc( sqlalchemy.sql.expression.asc(
event_table.c.created_at)).execute().fetchall() event_table.c.created_at)).execute().fetchall()
for event in event_list: for event in event_list:
values = {'tmp_id': fake_autoincrement.next(), 'uuid': event.id} values = {'tmp_id': next(fake_autoincrement), 'uuid': event.id}
update = event_table.update().where( update = event_table.update().where(
event_table.c.id == event.id).values(values) event_table.c.id == event.id).values(values)
migrate_engine.execute(update) migrate_engine.execute(update)

View File

@ -134,7 +134,7 @@ def upgrade_resource(migrate_engine):
sqlalchemy.sql.expression.asc( sqlalchemy.sql.expression.asc(
res_table.c.created_at)).execute().fetchall() res_table.c.created_at)).execute().fetchall()
for res in res_list: for res in res_list:
values = {'tmp_id': fake_autoincrement.next(), 'uuid': res.id} values = {'tmp_id': next(fake_autoincrement), 'uuid': res.id}
update = res_table.update().where( update = res_table.update().where(
res_table.c.id == res.id).values(values) res_table.c.id == res.id).values(values)
migrate_engine.execute(update) migrate_engine.execute(update)

View File

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import functools
import itertools import itertools
from heat.common import short_id from heat.common import short_id
@ -23,7 +24,9 @@ class ResourceTemplatesTest(common.HeatTestCase):
def setUp(self): def setUp(self):
super(ResourceTemplatesTest, self).setUp() super(ResourceTemplatesTest, self).setUp()
ids = ('stubbed-id-%s' % (i,) for i in itertools.count()) ids = ('stubbed-id-%s' % (i,) for i in itertools.count())
self.patchobject(short_id, 'generate_id').side_effect = ids.next self.patchobject(
short_id, 'generate_id').side_effect = functools.partial(next,
ids)
def test_create_template(self): def test_create_template(self):
""" """

View File

@ -1002,8 +1002,8 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('No exception raised in parent_task') self.fail('No exception raised in parent_task')
task = parent_task() task = parent_task()
task.next() next(task)
self.assertRaises(MyException, task.next) self.assertRaises(MyException, next, task)
def test_child_exception_exit(self): def test_child_exception_exit(self):
class MyException(Exception): class MyException(Exception):
@ -1024,8 +1024,8 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('No exception raised in parent_task') self.fail('No exception raised in parent_task')
task = parent_task() task = parent_task()
task.next() next(task)
self.assertRaises(StopIteration, task.next) self.assertRaises(StopIteration, next, task)
def test_child_exception_swallow(self): def test_child_exception_swallow(self):
class MyException(Exception): class MyException(Exception):
@ -1048,8 +1048,8 @@ class WrapperTaskTest(common.HeatTestCase):
yield yield
task = parent_task() task = parent_task()
task.next() next(task)
task.next() next(task)
def test_child_exception_swallow_next(self): def test_child_exception_swallow_next(self):
class MyException(Exception): class MyException(Exception):
@ -1074,7 +1074,7 @@ class WrapperTaskTest(common.HeatTestCase):
yield dummy() yield dummy()
task = parent_task() task = parent_task()
task.next() next(task)
self.m.StubOutWithMock(dummy, 'do_step') self.m.StubOutWithMock(dummy, 'do_step')
for i in range(1, dummy.num_steps + 1): for i in range(1, dummy.num_steps + 1):
@ -1082,8 +1082,8 @@ class WrapperTaskTest(common.HeatTestCase):
self.m.ReplayAll() self.m.ReplayAll()
for i in range(1, dummy.num_steps + 1): for i in range(1, dummy.num_steps + 1):
task.next() next(task)
self.assertRaises(StopIteration, task.next) self.assertRaises(StopIteration, next, task)
def test_thrown_exception_swallow_next(self): def test_thrown_exception_swallow_next(self):
class MyException(Exception): class MyException(Exception):
@ -1115,8 +1115,8 @@ class WrapperTaskTest(common.HeatTestCase):
task.throw(MyException) task.throw(MyException)
for i in range(2, dummy.num_steps + 1): for i in range(2, dummy.num_steps + 1):
task.next() next(task)
self.assertRaises(StopIteration, task.next) self.assertRaises(StopIteration, next, task)
def test_thrown_exception_raise(self): def test_thrown_exception_raise(self):
class MyException(Exception): class MyException(Exception):
@ -1151,8 +1151,8 @@ class WrapperTaskTest(common.HeatTestCase):
task.throw(MyException) task.throw(MyException)
for i in range(2, dummy.num_steps + 1): for i in range(2, dummy.num_steps + 1):
task.next() next(task)
self.assertRaises(StopIteration, task.next) self.assertRaises(StopIteration, next, task)
def test_thrown_exception_exit(self): def test_thrown_exception_exit(self):
class MyException(Exception): class MyException(Exception):
@ -1185,8 +1185,8 @@ class WrapperTaskTest(common.HeatTestCase):
task.throw(MyException) task.throw(MyException)
for i in range(2, dummy.num_steps + 1): for i in range(2, dummy.num_steps + 1):
task.next() next(task)
self.assertRaises(StopIteration, task.next) self.assertRaises(StopIteration, next, task)
def test_parent_exception(self): def test_parent_exception(self):
class MyException(Exception): class MyException(Exception):
@ -1201,8 +1201,8 @@ class WrapperTaskTest(common.HeatTestCase):
raise MyException() raise MyException()
task = parent_task() task = parent_task()
task.next() next(task)
self.assertRaises(MyException, task.next) self.assertRaises(MyException, next, task)
def test_parent_throw(self): def test_parent_throw(self):
class MyException(Exception): class MyException(Exception):
@ -1218,7 +1218,7 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('No exception raised in parent_task') self.fail('No exception raised in parent_task')
task = parent_task() task = parent_task()
task.next() next(task)
self.assertRaises(MyException, task.throw, MyException()) self.assertRaises(MyException, task.throw, MyException())
def test_parent_throw_exit(self): def test_parent_throw_exit(self):
@ -1235,7 +1235,7 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('No exception raised in parent_task') self.fail('No exception raised in parent_task')
task = parent_task() task = parent_task()
task.next() next(task)
self.assertRaises(StopIteration, task.throw, MyException()) self.assertRaises(StopIteration, task.throw, MyException())
def test_parent_cancel(self): def test_parent_cancel(self):
@ -1249,7 +1249,7 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('parent_task not closed') self.fail('parent_task not closed')
task = parent_task() task = parent_task()
task.next() next(task)
task.close() task.close()
def test_parent_cancel_exit(self): def test_parent_cancel_exit(self):
@ -1263,7 +1263,7 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('parent_task not closed') self.fail('parent_task not closed')
task = parent_task() task = parent_task()
task.next() next(task)
task.close() task.close()
def test_cancel(self): def test_cancel(self):
@ -1285,7 +1285,7 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('parent_task not closed') self.fail('parent_task not closed')
task = parent_task() task = parent_task()
task.next() next(task)
task.close() task.close()
def test_cancel_exit(self): def test_cancel_exit(self):
@ -1307,7 +1307,7 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('parent_task not closed') self.fail('parent_task not closed')
task = parent_task() task = parent_task()
task.next() next(task)
task.close() task.close()
def test_cancel_parent_exit(self): def test_cancel_parent_exit(self):
@ -1329,5 +1329,5 @@ class WrapperTaskTest(common.HeatTestCase):
self.fail('parent_task not closed') self.fail('parent_task not closed')
task = parent_task() task = parent_task()
task.next() next(task)
task.close() task.close()