From: Patrick Steinhardt Date: Wed, 22 May 2019 19:21:34 +0000 (+0200) Subject: test: avoid use of xrange for compatibility X-Git-Tag: v0.13.72~57^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f1da0b0fdcf96223d5d29bdd025c215ab8ca600;p=zziplib test: avoid use of xrange for compatibility Back in Python 2 days, there were two functions `range` and `xrange`. While `range` returned a list, `xrange` would return a generator and thus be the more efficient variant if a big range needs to be handled. With Python 3, the `xrange` function was removed in favor of always returning a generator for `range`. Convert all uses of `xrange` to `range`. While this may be less efficient in some places for old Python versions, their support is going to be dropped in 2020 anyway. Also, `xrange` is only ever used in the test suite. --- diff --git a/test/zziptests.py b/test/zziptests.py index e605c6a..3443c9b 100644 --- a/test/zziptests.py +++ b/test/zziptests.py @@ -208,7 +208,7 @@ class ZZipTest(unittest.TestCase): result = StringIO() old1 = '' old2 = '' - for i in xrange(size): + for i in range(size): while True: x = random.choice(" abcdefghijklmnopqrstuvwxyz\n") if x == old1 or x == old2: continue @@ -290,7 +290,7 @@ class ZZipTest(unittest.TestCase): zipfile="test2.zip" tmpdir="test2.tmp" exe=self.bins("mkzip") - for i in xrange(100): + for i in range(100): filename = os.path.join(tmpdir,"file.%02i" % i) filetext = "file-%02i\n" % i self.mkfile(filename, filetext) @@ -306,7 +306,7 @@ class ZZipTest(unittest.TestCase): zipfile="test3.zip" tmpdir="test3.tmp" exe=self.bins("mkzip") - for i in xrange(1000): + for i in range(1000): filename = os.path.join(tmpdir,"file.%03i" % i) filetext = "file-%03i\n" % i self.mkfile(filename, filetext) @@ -323,7 +323,7 @@ class ZZipTest(unittest.TestCase): zipfile="test4.zip" tmpdir="test4.tmp" exe=self.bins("mkzip") - for i in xrange(10000): + for i in range(10000): filename = os.path.join(tmpdir,"file%04i.txt" % i) filetext = "file-%04i\n" % i self.mkfile(filename, filetext) @@ -340,12 +340,12 @@ class ZZipTest(unittest.TestCase): zipfile="test5.zip" tmpdir="test5.tmp" exe=self.bins("mkzip") - for depth in xrange(20): + for depth in range(20): dirpath = "" - for i in xrange(depth): + for i in range(depth): if i: dirpath += "subdir%i/" % i - for size in xrange(18): + for size in range(18): size = 2 ** size filetext = self.gentext(size) filepart = "file%i-%i.txt" % (depth, size)