Author: Ronan Lamy <[email protected]>
Branch: raises(Exception)-must-die
Changeset: r80184:d968eea777cb
Date: 2015-10-14 00:07 +0100
http://bitbucket.org/pypy/pypy/changeset/d968eea777cb/
Log: make test and exception more precise in extfunc
diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py
--- a/rpython/rtyper/extfunc.py
+++ b/rpython/rtyper/extfunc.py
@@ -1,8 +1,8 @@
from rpython.rtyper import extregistry
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr
-from rpython.annotator import model as annmodel
-from rpython.annotator.signature import annotation
+from rpython.annotator.model import unionof
+from rpython.annotator.signature import annotation, SignatureError
import py, sys
@@ -130,7 +130,7 @@
"Argument number mismatch"
for i, expected in enumerate(signature_args):
- arg = annmodel.unionof(args_s[i], expected)
+ arg = unionof(args_s[i], expected)
if not expected.contains(arg):
name = getattr(self, 'name', None)
if not name:
@@ -138,7 +138,7 @@
name = self.instance.__name__
except AttributeError:
name = '?'
- raise Exception("In call to external function %r:\n"
+ raise SignatureError("In call to external function %r:\n"
"arg %d must be %s,\n"
" got %s" % (
name, i+1, expected, args_s[i]))
diff --git a/rpython/rtyper/test/test_extfunc.py
b/rpython/rtyper/test/test_extfunc.py
--- a/rpython/rtyper/test/test_extfunc.py
+++ b/rpython/rtyper/test/test_extfunc.py
@@ -2,9 +2,10 @@
from rpython.rtyper.extfunc import ExtFuncEntry, register_external,\
is_external, lazy_register
-from rpython.annotator import model as annmodel
+from rpython.annotator.model import SomeInteger, SomeString, AnnotatorError
from rpython.annotator.annrpython import RPythonAnnotator
from rpython.annotator.policy import AnnotatorPolicy
+from rpython.annotator.signature import SignatureError
from rpython.rtyper.test.test_llinterp import interpret
class TestExtFuncEntry:
@@ -21,8 +22,8 @@
class BTestFuncEntry(ExtFuncEntry):
_about_ = b
name = 'b'
- signature_args = [annmodel.SomeInteger()]
- signature_result = annmodel.SomeInteger()
+ signature_args = [SomeInteger()]
+ signature_result = SomeInteger()
def f():
return b(2)
@@ -30,7 +31,7 @@
policy = AnnotatorPolicy()
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
- assert isinstance(s, annmodel.SomeInteger)
+ assert isinstance(s, SomeInteger)
res = interpret(f, [])
assert res == 42
@@ -45,8 +46,8 @@
class CTestFuncEntry(ExtFuncEntry):
_about_ = c
name = 'ccc'
- signature_args = [annmodel.SomeInteger()] * 2
- signature_result = annmodel.SomeInteger()
+ signature_args = [SomeInteger()] * 2
+ signature_result = SomeInteger()
def lltypeimpl(y, x):
return y + x
@@ -72,7 +73,7 @@
policy = AnnotatorPolicy()
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
- assert isinstance(s, annmodel.SomeInteger)
+ assert isinstance(s, SomeInteger)
def test_register_external_tuple_args(self):
"""
@@ -96,7 +97,7 @@
s = a.build_types(f, [])
# Not a very good assertion, but at least it means _something_
happened.
- assert isinstance(s, annmodel.SomeInteger)
+ assert isinstance(s, SomeInteger)
def test_register_external_return_goes_back(self):
"""
@@ -118,7 +119,7 @@
policy = AnnotatorPolicy()
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
- assert isinstance(s, annmodel.SomeInteger)
+ assert isinstance(s, SomeInteger)
def test_register_external_specialcase(self):
"""
@@ -135,10 +136,10 @@
policy = AnnotatorPolicy()
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
- assert isinstance(s, annmodel.SomeString)
+ assert isinstance(s, SomeString)
def test_str0(self):
- str0 = annmodel.SomeString(no_nul=True)
+ str0 = SomeString(no_nul=True)
def os_open(s):
pass
register_external(os_open, [str0], None)
@@ -152,27 +153,32 @@
a.translator.config.translation.check_str_without_nul=True
def g(s):
return os_open(s)
- with py.test.raises(Exception):
+ with py.test.raises(SignatureError):
a.build_types(g, [str])
a.build_types(g, [str0]) # Does not raise
- def test_list_of_str0(self):
- str0 = annmodel.SomeString(no_nul=True)
+ def test_list_of_str0_unchecked(self):
+ str0 = SomeString(no_nul=True)
+
def os_execve(l):
pass
+
register_external(os_execve, [[str0]], None)
+
def f(l):
return os_execve(l)
+
policy = AnnotatorPolicy()
a = RPythonAnnotator(policy=policy)
+ assert a.translator.config.translation.check_str_without_nul == False
a.build_types(f, [[str]]) # Does not raise
- assert a.translator.config.translation.check_str_without_nul == False
# Now enable the str0 check, and try again with a similar function
a.translator.config.translation.check_str_without_nul=True
+
def g(l):
return os_execve(l)
- with py.test.raises(Exception):
+
+ with py.test.raises(AnnotatorError):
+ # fails with TooLateForChange
a.build_types(g, [[str]])
a.build_types(g, [[str0]]) # Does not raise
-
-
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit