Debian Codegraph @

rpython/rlib/test/test_rstackovf.py

raw symbols SCIP
1 import sys
2 import pytest
3 from rpython.rlib import rstackovf
4
5 IS_PYPY = 'pypyjit' in sys.builtin_module_names
6
7 def recurse(n):
8 if n > 0:
9 return recurse(n-1) + n
10 return 0
11
12 def f(n):
13 try:
14 recurse(n)
15 except rstackovf.StackOverflow:
16 return 1
17 else:
18 return 0
19
20
21 def test_direct():
22 assert f(sys.maxint) == 1
23
24 class RecurseGetAttr(object):
25
26 def __getattr__(self, attr):
27 return getattr(self, attr)
28
29 def test_raises_AttributeError():
30 pytest.skip("not RPython code...")
31 rga = RecurseGetAttr()
32 try:
33 rga.y
34 except AttributeError:
35 pass
36 else:
37 pytest.skip("interpreter is not badly behaved")
38 pytest.raises(rstackovf.StackOverflow, getattr, rga, "y")
39
40 @pytest.mark.skipif(IS_PYPY, reason="can fail to overflow on PyPy")
41 def test_llinterp():
42 from rpython.rtyper.test.test_llinterp import interpret
43 res = interpret(f, [sys.maxint])
44 assert res == 1
45
46 def test_c_translation():
47 from rpython.translator.c.test.test_genc import compile
48 fn = compile(f, [int])
49 res = fn(sys.maxint)
50 assert res == 1