File: test_objspace.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 (102 lines) | stat: -rw-r--r-- 3,177 bytes parent folder | download | duplicates (5)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pytest
from rpython.rlib.nonconst import NonConstant
from pypy.objspace.fake.objspace import FakeObjSpace, W_Root
from pypy.interpreter.argument import Arguments
from pypy.interpreter.typedef import TypeDef
from rpython.rlib.unroll import unrolling_iterable


def test_create():
    FakeObjSpace()


class TestTranslate:
    def setup_method(self, meth):
        self.space = FakeObjSpace()

    def test_simple(self):
        space = self.space
        space.translates(lambda w_x, w_y: space.add(w_x, w_y))

    def test_methodtable(self):
        space = self.space
        for fixed_arity in [1, 2, 3, 4]:
            #
            methodtable = [name for (name, _, arity, _) in space.MethodTable
                                if arity == fixed_arity]
            methodtable = unrolling_iterable(methodtable)
            args_w = (W_Root(),) * fixed_arity
            #
            def f():
                for name in methodtable:
                    getattr(space, name)(*args_w)
            #
            space.translates(f)

    def test_newdict(self):
        space = self.space
        space.translates(lambda: (space.newdict(),
                                  space.newdict(strdict=True)))

    def test_constants(self):
        space = self.space
        space.translates(lambda: (space.w_None, space.w_True, space.w_False,
                                  space.w_int, space.w_bytes, space.w_object,
                                  space.w_TypeError))

    def test_wrap(self):
        space = self.space
        space.translates(lambda: (space.newint(42), space.newfloat(42.5),
                                  space.newtext("foo")))

    def test_call_args(self):
        space = self.space
        args = Arguments(space, [W_Root()])
        space.translates(lambda: space.call_args(W_Root(), args))

    def test_gettypefor(self):
        space = self.space

        class W_Foo(W_Root):
            typedef = TypeDef("foo")
        space.translates(lambda: space.gettypefor(W_Foo))

    def test_is_true(self):
        space = self.space
        space.translates(lambda: space.is_true(W_Root()))
        with pytest.raises(AssertionError):
            space.translates(lambda: space.is_true(42))

    def test_unpackiterable(self):
        space = self.space
        space.translates(lambda: (space.unpackiterable(W_Root()),
                                  space.unpackiterable(W_Root(), 42)))

    def test_newlist(self):
        self.space.newlist([W_Root(), W_Root()])

    def test_default_values(self):
        # the __get__ method takes either 2 or 3 arguments
        space = self.space
        space.translates(lambda: (space.get(W_Root(), W_Root()),
                                  space.get(W_Root(), W_Root(), W_Root())))

    def test_bug_utf8_len_w(self):
        space = self.space

        class A(object):
            pass

        def f():
            s = NonConstant('a')
            w_s = space.newutf8(s, 1)
            t, l = space.utf8_len_w(w_s)
            a = A()
            if l == 1:
                a.x = 1
            else:
                raise Exception
            return a.x
        space.translates(f)