File: test_interpreter.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; 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