File: regression_test.py

package info (click to toggle)
pyrsistent 0.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 688 kB
  • sloc: python: 5,289; ansic: 1,213; makefile: 8
file content (30 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pyrsistent import pmap
import random

import gc


def test_segfault_issue_52():
    threshold = None
    if hasattr(gc, 'get_threshold'):
        # PyPy is lacking these functions
        threshold = gc.get_threshold()
        gc.set_threshold(1, 1, 1)  # fail fast

    v = [pmap()]

    def step():
        depth = random.randint(1, 10)
        path = random.sample(range(100000), depth)
        v[0] = v[0].transform(path, "foo")

    for i in range(1000):  # usually crashes after 10-20 steps
        while True:
            try:
                step()
                break
            except AttributeError:  # evolver on string
                continue

    if threshold:
        gc.set_threshold(*threshold)