Skip to content

Commit c56da45

Browse files
authored
Merge pull request #4805 from Masorubka1/test_context
Update test_context from Cpython v3.11.2
2 parents cae29ab + 2a41320 commit c56da45

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

Lib/test/test_context.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
import unittest
88
import weakref
9+
from test.support import threading_helper
910

1011
try:
1112
from _testcapi import hamt
@@ -379,6 +380,7 @@ def ctx2_fun():
379380
# TODO: RUSTPYTHON
380381
@unittest.expectedFailure
381382
@isolated_context
383+
@threading_helper.requires_working_threading()
382384
def test_context_threads_1(self):
383385
cvar = contextvars.ContextVar('cvar')
384386

@@ -396,12 +398,6 @@ def sub(num):
396398
tp.shutdown()
397399
self.assertEqual(results, list(range(10)))
398400

399-
# TODO: RUSTPYTHON
400-
@unittest.expectedFailure
401-
def test_contextvar_getitem(self):
402-
clss = contextvars.ContextVar
403-
self.assertEqual(clss[str], clss)
404-
405401

406402
# HAMT Tests
407403

@@ -577,6 +573,41 @@ def test_hamt_collision_1(self):
577573
self.assertEqual(len(h4), 2)
578574
self.assertEqual(len(h5), 3)
579575

576+
def test_hamt_collision_3(self):
577+
# Test that iteration works with the deepest tree possible.
578+
# https://github.com/python/cpython/issues/93065
579+
580+
C = HashKey(0b10000000_00000000_00000000_00000000, 'C')
581+
D = HashKey(0b10000000_00000000_00000000_00000000, 'D')
582+
583+
E = HashKey(0b00000000_00000000_00000000_00000000, 'E')
584+
585+
h = hamt()
586+
h = h.set(C, 'C')
587+
h = h.set(D, 'D')
588+
h = h.set(E, 'E')
589+
590+
# BitmapNode(size=2 count=1 bitmap=0b1):
591+
# NULL:
592+
# BitmapNode(size=2 count=1 bitmap=0b1):
593+
# NULL:
594+
# BitmapNode(size=2 count=1 bitmap=0b1):
595+
# NULL:
596+
# BitmapNode(size=2 count=1 bitmap=0b1):
597+
# NULL:
598+
# BitmapNode(size=2 count=1 bitmap=0b1):
599+
# NULL:
600+
# BitmapNode(size=2 count=1 bitmap=0b1):
601+
# NULL:
602+
# BitmapNode(size=4 count=2 bitmap=0b101):
603+
# <Key name:E hash:0>: 'E'
604+
# NULL:
605+
# CollisionNode(size=4 id=0x107a24520):
606+
# <Key name:C hash:2147483648>: 'C'
607+
# <Key name:D hash:2147483648>: 'D'
608+
609+
self.assertEqual({k.name for k in h.keys()}, {'C', 'D', 'E'})
610+
580611
def test_hamt_stress(self):
581612
COLLECTION_SIZE = 7000
582613
TEST_ITERS_EVERY = 647

0 commit comments

Comments
 (0)