File: test_pycode.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (74 lines) | stat: -rw-r--r-- 2,752 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys, StringIO
from pypy.interpreter.pycode import _code_const_eq

def test_dump(space):
    """test that pycode.dump kind of works with py3 opcodes"""
    compiler = space.createcompiler()
    code = compiler.compile('lambda *, y=7: None', 'filename', 'exec', 0)
    output = None
    stdout = sys.stdout
    try:
        sys.stdout = StringIO.StringIO()
        code.dump()
        output = sys.stdout.getvalue()
        sys.stdout.close()
    finally:
        sys.stdout = stdout
    print '>>>\n' + output + '\n<<<'
    assert ' 0 (7)' in output
    assert ' 3 (None)' in output
    assert ' 14 RETURN_VALUE' in output


def test_strong_const_equal(space):
    # test that the stronger equal that code objects are supposed to use for
    # consts works
    s = 'Python'
    values = [
        space.newint(1),
        space.newfloat(0.0),
        space.newfloat(-0.0),
        space.newfloat(1.0),
        space.newfloat(-1.0),
        space.w_True,
        space.w_False,
        space.w_None,
        space.w_Ellipsis,
        space.newcomplex(0.0, 0.0),
        space.newcomplex(0.0, -0.0),
        space.newcomplex(-0.0, 0.0),
        space.newcomplex(-0.0, -0.0),
        space.newcomplex(1.0, 1.0),
        space.newcomplex(1.0, -1.0),
        space.newcomplex(-1.0, 1.0),
        space.newcomplex(-1.0, -1.0),
        space.newfrozenset(),
        space.newtuple([]),
        space.newutf8(s, len(s)),
        space.newbytes(s),
    ]
    for w_a in values:
        assert _code_const_eq(space, w_a, w_a)
        assert _code_const_eq(space, space.newtuple([w_a]),
                              space.newtuple([w_a]))
        assert _code_const_eq(space, space.newfrozenset([w_a]),
                               space.newfrozenset([w_a]))
    for w_a in values:
        for w_b in values:
            if w_a is w_b:
                continue
            assert not _code_const_eq(space, w_a, w_b)
            assert _code_const_eq(space, space.newtuple([w_a, w_b]),
                                  space.newtuple([w_a, w_b]))
            assert not _code_const_eq(space, space.newtuple([w_a]),
                                      space.newtuple([w_b]))
            assert not _code_const_eq(space, space.newtuple([w_a, w_b]),
                                      space.newtuple([w_b, w_a]))
            assert not _code_const_eq(space, space.newfrozenset([w_a]),
                                      space.newfrozenset([w_b]))
        s1 = 'Python' + str(1) + str(1)
        s2 = 'Python' + str(11)
        assert _code_const_eq(space, space.newutf8(s1, len(s1)),
                              space.newutf8(s2, len(s2)))
        assert _code_const_eq(space, space.newbytes(s1),
                              space.newbytes(s2))