File: test_nonconst.py

package info (click to toggle)
pypy 2.4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 86,992 kB
  • ctags: 170,715
  • sloc: python: 1,030,417; ansic: 43,437; cpp: 5,241; asm: 5,169; sh: 458; makefile: 408; xml: 231; lisp: 45
file content (58 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download
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

""" Test of non-constant constant.
"""

from rpython.rlib.nonconst import NonConstant

from rpython.annotator.annrpython import RPythonAnnotator
from rpython.conftest import option
from rpython.annotator.model import SomeInstance

def test_nonconst():
    def nonconst_f():
        a = NonConstant(3)
        return a

    a = RPythonAnnotator()
    s = a.build_types(nonconst_f, [])
    assert s.knowntype is int
    assert not hasattr(s, 'const')


def test_nonconst_list():
    def nonconst_l():
        a = NonConstant([1, 2, 3])
        return a[0]

    a = RPythonAnnotator()
    s = a.build_types(nonconst_l, [])
    assert s.knowntype is int
    assert not hasattr(s, 'const')

def test_nonconst_instance():
    class A:
        pass
    a = A()

    def nonconst_i():
        return NonConstant(a)

    a = RPythonAnnotator()
    s = a.build_types(nonconst_i, [])
    if option.view:
        a.translator.view()
    assert isinstance(s, SomeInstance)

def test_bool_nonconst():
    def fn():
        return bool(NonConstant(False))

    assert not fn()

    a = RPythonAnnotator()
    s = a.build_types(fn, [])
    assert s.knowntype is bool
    assert not hasattr(s, 'const')

    if option.view:
        a.translator.view()