Skip to content

Commit c00ccf7

Browse files
ShaharNavehyouknowone
authored andcommitted
Update test_sort.py from 3.14.3
1 parent ae260c1 commit c00ccf7

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Lib/test/test_sort.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ def bad_key(x):
128128
x = [e for e, i in augmented] # a stable sort of s
129129
check("stability", x, s)
130130

131+
def test_small_stability(self):
132+
from itertools import product
133+
from operator import itemgetter
134+
135+
# Exhaustively test stability across all lists of small lengths
136+
# and only a few distinct elements.
137+
# This can provoke edge cases that randomization is unlikely to find.
138+
# But it can grow very expensive quickly, so don't overdo it.
139+
NELTS = 3
140+
MAXSIZE = 9
141+
142+
pick0 = itemgetter(0)
143+
for length in range(MAXSIZE + 1):
144+
# There are NELTS ** length distinct lists.
145+
for t in product(range(NELTS), repeat=length):
146+
xs = list(zip(t, range(length)))
147+
# Stability forced by index in each element.
148+
forced = sorted(xs)
149+
# Use key= to hide the index from compares.
150+
native = sorted(xs, key=pick0)
151+
self.assertEqual(forced, native)
131152
#==============================================================================
132153

133154
class TestBugs(unittest.TestCase):
@@ -149,7 +170,7 @@ def __lt__(self, other):
149170
L = [C() for i in range(50)]
150171
self.assertRaises(ValueError, L.sort)
151172

152-
@unittest.expectedFailure # TODO: RUSTPYTHON; figure out how to detect sort mutation that doesn't change list length
173+
@unittest.expectedFailure # TODO: RUSTPYTHON; figure out how to detect sort mutation that doesn't change list length
153174
def test_undetected_mutation(self):
154175
# Python 2.4a1 did not always detect mutation
155176
memorywaster = []
@@ -307,8 +328,7 @@ def test_safe_object_compare(self):
307328
for L in float_int_lists:
308329
check_against_PyObject_RichCompareBool(self, L)
309330

310-
# XXX RUSTPYTHON: added by us but it seems like an implementation detail
311-
@support.cpython_only
331+
@support.cpython_only # XXX RUSTPYTHON: added by us but it seems like an implementation detail
312332
def test_unsafe_object_compare(self):
313333

314334
# This test is by ppperry. It ensures that unsafe_object_compare is

0 commit comments

Comments
 (0)