Pārlūkot izejas kodu

Use range instead of xrange, and list(range()).

Only do this for tests, as there a potential performance hit.
Gary van der Merwe 11 gadi atpakaļ
vecāks
revīzija
770937f082

+ 1 - 1
dulwich/tests/compat/utils.py

@@ -187,7 +187,7 @@ def check_for_daemon(limit=10, delay=0.1, timeout=0.1, port=TCP_GIT_PORT):
     :returns: A boolean, true if a daemon is running on the specified port,
         false if not.
     """
-    for _ in xrange(limit):
+    for _ in range(limit):
         time.sleep(delay)
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.settimeout(delay)

+ 2 - 2
dulwich/tests/test_diff_tree.py

@@ -392,7 +392,7 @@ class TreeChangesTest(DiffTestCase):
         self.assertChangesForMergeEqual([], [has, doesnt_have], doesnt_have)
 
     def test_tree_changes_for_merge_octopus_no_conflict(self):
-        r = range(5)
+        r = list(range(5))
         blobs = [make_object(Blob, data=str(i)) for i in r]
         parents = [self.commit_tree([('a', blobs[i])]) for i in r]
         for i in r:
@@ -403,7 +403,7 @@ class TreeChangesTest(DiffTestCase):
         # Because the octopus merge strategy is limited, I doubt it's possible
         # to create this with the git command line. But the output is well-
         # defined, so test it anyway.
-        r = range(5)
+        r = list(range(5))
         parent_blobs = [make_object(Blob, data=str(i)) for i in r]
         merge_blob = make_object(Blob, data='merge')
         parents = [self.commit_tree([('a', parent_blobs[i])]) for i in r]

+ 2 - 2
dulwich/tests/test_objects.py

@@ -508,7 +508,7 @@ class CommitParseTests(ShaFileCheckTests):
 
     def test_check_duplicates(self):
         # duplicate each of the header fields
-        for i in xrange(5):
+        for i in range(5):
             lines = self.make_commit_lines(parents=[a_sha], encoding='UTF-8')
             lines.insert(i, lines[i])
             text = '\n'.join(lines)
@@ -785,7 +785,7 @@ class TagParseTests(ShaFileCheckTests):
 
     def test_check_duplicates(self):
         # duplicate each of the header fields
-        for i in xrange(4):
+        for i in range(4):
             lines = self.make_tag_lines()
             lines.insert(i, lines[i])
             self.assertCheckFails(Tag, '\n'.join(lines))

+ 4 - 4
dulwich/tests/test_pack.py

@@ -921,20 +921,20 @@ class DeltaChainIteratorTests(TestCase):
     def test_long_chain(self):
         n = 100
         objects_spec = [(Blob.type_num, 'blob')]
-        for i in xrange(n):
+        for i in range(n):
             objects_spec.append((OFS_DELTA, (i, 'blob%i' % i)))
         f = StringIO()
         entries = build_pack(f, objects_spec)
-        self.assertEntriesMatch(xrange(n + 1), entries, self.make_pack_iter(f))
+        self.assertEntriesMatch(range(n + 1), entries, self.make_pack_iter(f))
 
     def test_branchy_chain(self):
         n = 100
         objects_spec = [(Blob.type_num, 'blob')]
-        for i in xrange(n):
+        for i in range(n):
             objects_spec.append((OFS_DELTA, (0, 'blob%i' % i)))
         f = StringIO()
         entries = build_pack(f, objects_spec)
-        self.assertEntriesMatch(xrange(n + 1), entries, self.make_pack_iter(f))
+        self.assertEntriesMatch(range(n + 1), entries, self.make_pack_iter(f))
 
     def test_ext_ref(self):
         blob, = self.store_blobs(['blob'])

+ 3 - 3
dulwich/tests/test_protocol.py

@@ -151,7 +151,7 @@ class ReceivableProtocolTests(BaseProtocolTests, TestCase):
         data = ''
         # We ask for 8 bytes each time and actually read 7, so it should take
         # exactly 10 iterations.
-        for _ in xrange(10):
+        for _ in range(10):
             data += self.proto.recv(10)
         # any more reads would block
         self.assertRaises(AssertionError, self.proto.recv, 10)
@@ -176,12 +176,12 @@ class ReceivableProtocolTests(BaseProtocolTests, TestCase):
 
     def test_mixed(self):
         # arbitrary non-repeating string
-        all_data = ','.join(str(i) for i in xrange(100))
+        all_data = ','.join(str(i) for i in range(100))
         self.rin.write(all_data)
         self.rin.seek(0)
         data = ''
 
-        for i in xrange(1, 100):
+        for i in range(1, 100):
             data += self.proto.recv(i)
             # if we get to the end, do a non-blocking read instead of blocking
             if len(data) + i > len(all_data):

+ 1 - 1
dulwich/tests/test_server.py

@@ -225,7 +225,7 @@ class FindShallowTests(TestCase):
     def make_linear_commits(self, n, message=''):
         commits = []
         parents = []
-        for _ in xrange(n):
+        for _ in range(n):
             commits.append(self.make_commit(parents=parents, message=message))
             parents = [commits[-1].id]
         return commits

+ 2 - 2
dulwich/tests/test_walk.py

@@ -88,7 +88,7 @@ class WalkerTest(TestCase):
 
     def make_linear_commits(self, num_commits, **kwargs):
         commit_spec = []
-        for i in xrange(1, num_commits + 1):
+        for i in range(1, num_commits + 1):
             c = [i]
             if i > 1:
                 c.append(i - 1)
@@ -122,7 +122,7 @@ class WalkerTest(TestCase):
         # implementation (in particular the choice of _MAX_EXTRA_COMMITS), but
         # we should at least be able to walk some history in a broken repo.
         del self.store[cs[-1].id]
-        for i in xrange(1, 11):
+        for i in range(1, 11):
             self.assertWalkYields(cs[:i], [cs[0].id], max_entries=i)
         self.assertRaises(MissingCommitError, Walker, self.store, [cs[-1].id])
 

+ 1 - 1
dulwich/tests/test_web.py

@@ -263,7 +263,7 @@ class DumbHandlersTestCase(WebTestCase):
             def __init__(self, sha):
                 self.data = TestPackData(sha)
 
-        packs = [TestPack(str(i) * 40) for i in xrange(1, 4)]
+        packs = [TestPack(str(i) * 40) for i in range(1, 4)]
 
         class TestObjectStore(MemoryObjectStore):
             # property must be overridden, can't be assigned

+ 1 - 1
dulwich/tests/utils.py

@@ -229,7 +229,7 @@ def build_pack(f, objects_spec, store=None):
         crc32s[i] = crc32
 
     expected = []
-    for i in xrange(num_objects):
+    for i in range(num_objects):
         type_num, data, sha = full_objects[i]
         assert len(sha) == 20
         expected.append((offsets[i], type_num, data, sha, crc32s[i]))