| 1 |
import os |
| 2 |
import sys |
| 3 |
import textwrap |
| 4 |
import subprocess |
| 5 |
|
| 6 |
def test_WeakValueDictionary_len(tmpdir): |
| 7 |
src = textwrap.dedent(""" |
| 8 |
from weakref import WeakValueDictionary |
| 9 |
class Foo: |
| 10 |
pass |
| 11 |
N = 1000 |
| 12 |
D = WeakValueDictionary() |
| 13 |
for i in range(N): |
| 14 |
D[i] = Foo() |
| 15 |
|
| 16 |
for i in range(10): |
| 17 |
x = len(D) |
| 18 |
print('OK') |
| 19 |
""") |
| 20 |
testfile = tmpdir.join('testfile.py') |
| 21 |
testfile.write(src) |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
env = {'PYPY_GC_NURSERY': '1k'} |
| 28 |
env['PATH'] = os.environ.get("PATH") |
| 29 |
subprocess.run([sys.executable, str(testfile)], env=env, check=True) |
| 30 |
|
| 31 |
|
| 32 |
def test_WeakKeyDictionary_len(tmpdir): |
| 33 |
src = textwrap.dedent(""" |
| 34 |
from weakref import WeakKeyDictionary |
| 35 |
class Foo: |
| 36 |
pass |
| 37 |
N = 1000 |
| 38 |
D = WeakKeyDictionary() |
| 39 |
for i in range(N): |
| 40 |
D[Foo()] = i |
| 41 |
|
| 42 |
for i in range(10): |
| 43 |
x = len(D) |
| 44 |
print('OK') |
| 45 |
""") |
| 46 |
testfile = tmpdir.join('testfile.py') |
| 47 |
testfile.write(src) |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
env = {'PYPY_GC_NURSERY': '1k'} |
| 54 |
env['PATH'] = os.environ.get("PATH") |
| 55 |
subprocess.run([sys.executable, str(testfile)], env=env, check=True) |