diff test_pydertron.py @ 12:e4978bd08bfa

Factored out unit test suite
author Atul Varma <varmaa@toolness.com>
date Thu, 10 Sep 2009 13:53:03 -0700
parents
children 6c55f09ff31d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_pydertron.py	Thu Sep 10 13:53:03 2009 -0700
@@ -0,0 +1,63 @@
+import os
+import sys
+
+import pydermonkey
+from pydertron import JsSandbox, SandboxedFileSystem, jsexposed
+
+def run_test(name, libpath):
+    sandbox = JsSandbox(SandboxedFileSystem(libpath))
+
+    stats = [0, 0]
+
+    @jsexposed(name='print')
+    def jsprint(message, label):
+        if label == "pass":
+            stats[0] += 1
+        elif label == "fail":
+            stats[1] += 1
+        print "%s %s" % (message, label)
+
+    sandbox.set_globals(
+        sys = sandbox.new_object(**{'print': jsprint}),
+        environment = sandbox.new_object()
+        )
+
+    retval = sandbox.run_script("require('program')")
+    sandbox.finish()
+    print
+
+    if retval != 0:
+        stats[1] += 1
+    return stats
+
+if __name__ == '__main__':
+    base_libpath = os.path.join("interoperablejs-read-only",
+                                "compliance")
+    if not os.path.exists(base_libpath):
+        print "Please run the following command and then re-run "
+        print "this script:"
+        print
+        print ("svn checkout "
+               "http://interoperablejs.googlecode.com/svn/trunk/ "
+               "interoperablejs-read-only")
+        sys.exit(1)
+
+    dirs = [(os.path.join(base_libpath, name), name)
+            for name in os.listdir(base_libpath)
+            if name not in ['.svn', 'ORACLE']]
+
+    totals = [0, 0]
+
+    for libpath, name in dirs:
+        passed, failed = run_test(name, libpath)
+        totals[0] += passed
+        totals[1] += failed
+
+    print "passed: %d  failed: %d" % tuple(totals)
+
+    import gc
+    gc.collect()
+    if pydermonkey.get_debug_info()['runtime_count']:
+        sys.stderr.write("WARNING: JS runtime was not destroyed.\n")
+
+    sys.exit(totals[1])