[pypy-svn] r35157 - in pypy/dist/pypy/translator/js: . modules/test test

fijal at codespeak.net fijal at codespeak.net
Thu Nov 30 14:42:33 CET 2006


Author: fijal
Date: Thu Nov 30 14:42:28 2006
New Revision: 35157

Added:
   pypy/dist/pypy/translator/js/tester.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/js/modules/test/test_dom.py
   pypy/dist/pypy/translator/js/test/test_basicexternal.py
Log:
Added new testing possibilities.


Modified: pypy/dist/pypy/translator/js/modules/test/test_dom.py
==============================================================================
--- pypy/dist/pypy/translator/js/modules/test/test_dom.py	(original)
+++ pypy/dist/pypy/translator/js/modules/test/test_dom.py	Thu Nov 30 14:42:28 2006
@@ -1,6 +1,7 @@
 import py
 from pypy.translator.js.modules import dom
 from pypy.translator.js.main import rpython2javascript
+from pypy.rpython.ootypesystem.bltregistry import BasicExternal, described
 from xml.dom.minidom import parseString
 import sys
 

Modified: pypy/dist/pypy/translator/js/test/test_basicexternal.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_basicexternal.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_basicexternal.py	Thu Nov 30 14:42:28 2006
@@ -6,6 +6,7 @@
 
 from pypy.rpython.ootypesystem.bltregistry import MethodDesc, BasicExternal, described
 from pypy.translator.js.test.runtest import compile_function, check_source_contains
+from pypy.translator.js.tester import schedule_callbacks
 
 class A(BasicExternal):
     @described(retval=3)
@@ -94,7 +95,6 @@
     fun1 = compile_function(return_dict, [])
 
 def test_method_call():
-    py.test.skip("Fails")
     class Meth(BasicExternal):
         @described(retval=3)
         def meth(self):
@@ -107,4 +107,5 @@
     
     meth = Meth()
     meth.meth(callback)
+    schedule_callbacks(meth)
     assert l[0] == 8

Added: pypy/dist/pypy/translator/js/tester.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/tester.py	Thu Nov 30 14:42:28 2006
@@ -0,0 +1,31 @@
+
+""" tester - support module for testing js code inside python
+
+Needs to be imported in case one wants tests involving calling BasicExternal
+methods
+"""
+
+from pypy.rpython.ootypesystem.bltregistry import BasicExternal
+
+def __getattr__(self, attr):
+    val = super(BasicExternal, self).__getattribute__(attr)
+    if not callable(val) or attr not in self._methods:
+        return val # we don't do anything special
+    # otherwise....
+    def wrapper(*args, **kwargs):
+        args = list(args)
+        callback = args.pop()
+        res = val(*args, **kwargs)
+        if not hasattr(self, '__callbacks'):
+            self.__callbacks = []
+        self.__callbacks.append((callback, res))
+    wrapper.func_name = attr
+    return wrapper
+
+BasicExternal.__getattribute__ = __getattr__
+
+def schedule_callbacks(*args):
+    for arg in args:
+        if hasattr(arg, '__callbacks'):
+            for callback, res in arg.__callbacks:
+                callback(res)



More information about the Pypy-commit mailing list