summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sort.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_sort.py')
-rw-r--r--Lib/test/test_sort.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/Lib/test/test_sort.py b/Lib/test/test_sort.py
index ad3a817..738ffe1 100644
--- a/Lib/test/test_sort.py
+++ b/Lib/test/test_sort.py
@@ -75,7 +75,7 @@ class TestBase(unittest.TestCase):
return "Stable(%d, %d)" % (self.key, self.index)
for n in sizes:
- x = range(n)
+ x = list(range(n))
if verbose:
print("Testing size", n)
@@ -115,7 +115,7 @@ class TestBase(unittest.TestCase):
Complains.maybe_complain = False
check("exception during sort left some permutation", x, s)
- s = [Stable(random.randrange(10), i) for i in xrange(n)]
+ s = [Stable(random.randrange(10), i) for i in range(n)]
augmented = [(e, e.index) for e in s]
augmented.sort() # forced stable because ties broken by index
x = [e for e, i in augmented] # a stable sort of s
@@ -144,10 +144,10 @@ class TestBugs(unittest.TestCase):
def test_cmpNone(self):
# Testing None as a comparison function.
- L = range(50)
+ L = list(range(50))
random.shuffle(L)
L.sort(None)
- self.assertEqual(L, range(50))
+ self.assertEqual(L, list(range(50)))
def test_undetected_mutation(self):
# Python 2.4a1 did not always detect mutation
@@ -182,7 +182,7 @@ class TestDecorateSortUndecorate(unittest.TestCase):
self.assertRaises(TypeError, data.sort, None, lambda x,y: 0)
def test_stability(self):
- data = [(random.randrange(100), i) for i in xrange(200)]
+ data = [(random.randrange(100), i) for i in range(200)]
copy = data[:]
data.sort(key=lambda (x,y): x) # sort on the random first field
copy.sort() # sort using both fields
@@ -204,13 +204,13 @@ class TestDecorateSortUndecorate(unittest.TestCase):
def test_key_with_exception(self):
# Verify that the wrapper has been removed
- data = range(-2,2)
+ data = list(range(-2, 2))
dup = data[:]
self.assertRaises(ZeroDivisionError, data.sort, None, lambda x: 1/x)
self.assertEqual(data, dup)
def test_key_with_mutation(self):
- data = range(10)
+ data = list(range(10))
def k(x):
del data[:]
data[:] = range(20)
@@ -218,7 +218,7 @@ class TestDecorateSortUndecorate(unittest.TestCase):
self.assertRaises(ValueError, data.sort, key=k)
def test_key_with_mutating_del(self):
- data = range(10)
+ data = list(range(10))
class SortKiller(object):
def __init__(self, x):
pass
@@ -230,7 +230,7 @@ class TestDecorateSortUndecorate(unittest.TestCase):
self.assertRaises(ValueError, data.sort, key=SortKiller)
def test_key_with_mutating_del_and_exception(self):
- data = range(10)
+ data = list(range(10))
## dup = data[:]
class SortKiller(object):
def __init__(self, x):
@@ -238,7 +238,7 @@ class TestDecorateSortUndecorate(unittest.TestCase):
raise RuntimeError
def __del__(self):
del data[:]
- data[:] = range(20)
+ data[:] = list(range(20))
self.assertRaises(RuntimeError, data.sort, key=SortKiller)
## major honking subtlety: we *can't* do:
##
@@ -250,14 +250,14 @@ class TestDecorateSortUndecorate(unittest.TestCase):
## date (this cost some brain cells to figure out...).
def test_reverse(self):
- data = range(100)
+ data = list(range(100))
random.shuffle(data)
data.sort(reverse=True)
- self.assertEqual(data, range(99,-1,-1))
+ self.assertEqual(data, list(range(99,-1,-1)))
self.assertRaises(TypeError, data.sort, "wrong type")
def test_reverse_stability(self):
- data = [(random.randrange(100), i) for i in xrange(200)]
+ data = [(random.randrange(100), i) for i in range(200)]
copy1 = data[:]
copy2 = data[:]
data.sort(cmp=lambda x,y: cmp(x[0],y[0]), reverse=True)
@@ -281,7 +281,7 @@ def test_main(verbose=None):
if verbose and hasattr(sys, "gettotalrefcount"):
import gc
counts = [None] * 5
- for i in xrange(len(counts)):
+ for i in range(len(counts)):
test_support.run_unittest(*test_classes)
gc.collect()
counts[i] = sys.gettotalrefcount()