Skip to content

Commit

Permalink
test/py: Use range() rather than xrange()
Browse files Browse the repository at this point in the history
In python 3.x the xrange() function has been removed, and range()
returns an iterator much like Python 2.x's xrange(). Simply use range()
in place of xrange() in order to work on both python 2.x & 3.x. This
will mean a small cost on python 2.x since range() will return a list
there rather than an iterator, but the cost should be negligible.

Signed-off-by: Paul Burton <[email protected]>
Reviewed-by: Stephen Warren <[email protected]>
  • Loading branch information
paulburton authored and sjg20 committed Jul 10, 2018
1 parent dffd56d commit b8c4555
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/py/u_boot_console_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def validate_exited(self):

p = self.p
self.p = None
for i in xrange(100):
for i in range(100):
ret = not p.isalive()
if ret:
break
Expand Down
6 changes: 3 additions & 3 deletions test/py/u_boot_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def expect(self, patterns):
the expected time.
"""

for pi in xrange(len(patterns)):
for pi in range(len(patterns)):
if type(patterns[pi]) == type(''):
patterns[pi] = re.compile(patterns[pi])

Expand All @@ -143,7 +143,7 @@ def expect(self, patterns):
while True:
earliest_m = None
earliest_pi = None
for pi in xrange(len(patterns)):
for pi in range(len(patterns)):
pattern = patterns[pi]
m = pattern.search(self.buf)
if not m:
Expand Down Expand Up @@ -198,7 +198,7 @@ def close(self):
"""

os.close(self.fd)
for i in xrange(100):
for i in range(100):
if not self.isalive():
break
time.sleep(0.1)
Expand Down
4 changes: 2 additions & 2 deletions test/py/u_boot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def wait_until_open_succeeds(fn):
An open file handle to the file.
"""

for i in xrange(100):
for i in range(100):
fh = attempt_to_open_file(fn)
if fh:
return fh
Expand All @@ -143,7 +143,7 @@ def wait_until_file_open_fails(fn, ignore_errors):
Nothing.
"""

for i in xrange(100):
for i in range(100):
fh = attempt_to_open_file(fn)
if not fh:
return
Expand Down

0 comments on commit b8c4555

Please sign in to comment.