File: test_interpreter.py

package info (click to toggle)
pypy 7.3.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 113,660 kB
  • sloc: python: 1,419,707; ansic: 64,313; cpp: 3,290; sh: 2,763; makefile: 540; xml: 256; asm: 213; lisp: 45; awk: 4
file content (36 lines) | stat: -rw-r--r-- 824 bytes parent folder | download | duplicates (7)
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
31
32
33
34
35
36
from __future__ import print_function
import pytest

@pytest.fixture
def testfile(tmpdir):
    tmpfile = tmpdir.join('test_execution_context')
    tmpfile.write("""
from __future__ import print_function
import gc
class X(object):
    def __del__(self):
        print("Called", self.num)
def f():
    x1 = X(); x1.num = 1
    x2 = X(); x2.num = 2
    x1.next = x2
f()
gc.collect()
gc.collect()
""")
    return tmpfile


def test_del_not_blocked(testfile):
    # test the behavior fixed in r71420: before, only one __del__
    # would be called
    import os, sys
    if sys.platform == "win32":
        cmdformat = '"%s" "%s"'
    else:
        cmdformat = "'%s' '%s'"
    g = os.popen(cmdformat % (sys.executable, testfile), 'r')
    data = g.read()
    g.close()
    assert 'Called 1' in data
    assert 'Called 2' in data