[pypy-svn] r33779 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Oct 26 17:57:48 CEST 2006


Author: antocuni
Date: Thu Oct 26 17:57:48 2006
New Revision: 33779

Modified:
   pypy/dist/pypy/translator/cli/query.py
   pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
Group non-overloaded methods into a fake "overload" object with only
one element to force signature checking.



Modified: pypy/dist/pypy/translator/cli/query.py
==============================================================================
--- pypy/dist/pypy/translator/cli/query.py	(original)
+++ pypy/dist/pypy/translator/cli/query.py	Thu Oct 26 17:57:48 2006
@@ -127,27 +127,22 @@
 
         # add both static and instance methods
         static_meths = self.group_methods(self.StaticMethods, _overloaded_static_meth,
-                                          _static_meth, ootype.StaticMethod, always_group=True)
+                                          _static_meth, ootype.StaticMethod)
         meths = self.group_methods(self.Methods, ootype.overload, ootype.meth, ootype.Meth)
         Class._add_methods(static_meths)
         TYPE._add_methods(meths)
         return Class
 
-    def group_methods(self, methods, overload, meth, Meth, always_group=False):
+    def group_methods(self, methods, overload, meth, Meth):
         groups = {}
         for name, args, result in methods:
             groups.setdefault(name, []).append((args, result))
 
         res = {}
         for name, methlist in groups.iteritems():
-            if len(methlist) == 1 and not always_group:
-                args, result = methlist[0]
-                TYPE = self.get_method_type(Meth, args, result)
-                res[name] = meth(TYPE)
-            else:
-                TYPES = [self.get_method_type(Meth, args, result) for (args, result) in methlist]
-                meths = [meth(TYPE) for TYPE in TYPES]
-                res[name] = overload(*meths)
+            TYPES = [self.get_method_type(Meth, args, result) for (args, result) in methlist]
+            meths = [meth(TYPE) for TYPE in TYPES]
+            res[name] = overload(*meths)
         return res
 
     def get_method_type(self, Meth, args, result):

Modified: pypy/dist/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_dotnet.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_dotnet.py	Thu Oct 26 17:57:48 2006
@@ -91,7 +91,7 @@
         assert s.ootype._name == '[mscorlib]System.Object'
 
 class TestDotnetRtyping(CliTest):
-    def _skip_pythonnet(self):
+    def _skip_pythonnet(self, msg):
         pass
 
     def test_staticmeth_call(self):
@@ -100,7 +100,7 @@
         assert self.interpret(fn, [-42]) == 42
 
     def test_staticmeth_overload(self):
-        self._skip_pythonnet()
+        self._skip_pythonnet('Pythonnet bug!')
         def fn(x, y):
             return Math.Abs(x), Math.Abs(y)
         res = self.interpret(fn, [-42, -42.5])
@@ -108,19 +108,11 @@
         assert item0 == 42
         assert item1 == 42.5
 
-    def test_method_call(self):
-        def fn():
-            x = ArrayList()
-            x.Add("foo")
-            x.Add("bar")
-            return x.get_Count()
-        assert self.interpret(fn, []) == 2
-
     def test_tostring(self):
         StringBuilder = CLR.System.Text.StringBuilder
         def fn():
             x = StringBuilder()
-            x.Append("foo").Append("bar")
+            x.Append(box("foo")).Append(box("bar"))
             return x.ToString()
         res = self.ll_to_string(self.interpret(fn, []))
         assert res == 'foobar'
@@ -133,6 +125,12 @@
             return x.get_Count()
         assert self.interpret(fn, []) == 2
 
+    def test_whitout_box(self):
+        def fn():
+            x = ArrayList()
+            x.Add(42) # note we have forgot box()
+        py.test.raises(TypeError, self.interpret, fn, [])
+
     def test_unbox(self):
         def fn():
             x = ArrayList()
@@ -173,6 +171,9 @@
     def interpret(self, f, args):
         return f(*args)
 
-    def _skip_pythonnet(self):
-        py.test.skip('Pythonnet bug!')
+    def _skip_pythonnet(self, msg):
+        py.test.skip(msg)
 
+    def test_whitout_box(self):
+        pass # it makes sense only during translation
+    



More information about the Pypy-commit mailing list