[pypy-svn] r9513 - pypy/dist/pypy/translator/test

pedronis at codespeak.net pedronis at codespeak.net
Fri Feb 25 19:21:07 CET 2005


Author: pedronis
Date: Fri Feb 25 19:21:07 2005
New Revision: 9513

Added:
   pypy/dist/pypy/translator/test/test_annmm.py   (contents, props changed)
Log:
simple tests about annotating std objspace mms (notice that without the changes on how we deal
with functions only raising exceptions and not returning), these would fail.



Added: pypy/dist/pypy/translator/test/test_annmm.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/test/test_annmm.py	Fri Feb 25 19:21:07 2005
@@ -0,0 +1,58 @@
+import autopath
+
+from pypy.objspace.std.multimethod import *
+from pypy.translator.annrpython import RPythonAnnotator
+
+class W_Root(object):
+    pass
+
+class W_Int(W_Root):
+    pass
+
+class W_Str(W_Root):
+    pass
+
+
+str_w = MultiMethodTable(1, root_class=W_Root, argnames_before=['space'])
+int_w = MultiMethodTable(1, root_class=W_Root, argnames_before=['space'])
+
+
+def int_w__Int(space, w_x):
+    assert space == 'space'
+    assert isinstance(w_x, W_Int)
+    return 1
+
+def str_w__Str(space, w_x):
+    assert space == 'space'
+    assert isinstance(w_x, W_Str)
+    return "string"
+
+int_w.register(int_w__Int, W_Int)
+str_w.register(str_w__Str, W_Str)
+
+
+def setup_module(mod):
+    typeorder = {
+        W_Int: [(W_Int, None)],
+        W_Str: [(W_Str, None)],
+        }
+    mod.typeorder = typeorder
+    mod.str_w1 = str_w.install('__str_w', [typeorder])
+    mod.int_w1 = int_w.install('__int_w', [typeorder])
+
+
+def test_str_w_ann():
+    a = RPythonAnnotator()
+    s1 = a.build_types(str_w1,[str, W_Str])
+    s2 = a.build_types(str_w1,[str, W_Root])
+    assert s1.knowntype == str
+    assert s2.knowntype == str
+    
+def test_int_w_ann():
+    a = RPythonAnnotator()
+    s1 = a.build_types(int_w1,[str, W_Int])
+    s2 = a.build_types(int_w1,[str, W_Str])
+    assert s1.knowntype == int
+    assert s2.knowntype == int
+    
+    



More information about the Pypy-commit mailing list