view test_pydertron.py @ 14:16fe9c63aedb

Added HttpFileSystem
author Atul Varma <varmaa@toolness.com>
date Thu, 10 Sep 2009 14:27:28 -0700
parents 6c55f09ff31d
children f30bd92e2216
line wrap: on
line source

import os
import sys

import pydermonkey
from pydertron import JsSandbox, jsexposed
from pydertron import SandboxedFileSystem, HttpFileSystem

def run_test(name, fs):
    sandbox = JsSandbox(fs)
    stats = {'pass': 0, 'fail': 0, 'info': 0}

    @jsexposed(name='print')
    def jsprint(message, label):
        stats[label] += 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['fail'] += 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 = {'pass': 0, 'fail': 0}

    BASE_URL = "http://interoperablejs.googlecode.com/svn/trunk/compliance/"

    for libpath, name in dirs:
        #fs = HttpFileSystem("%s%s/"% (BASE_URL, name))
        fs = SandboxedFileSystem(libpath)
        stats = run_test(name, fs)
        totals['pass'] += stats['pass']
        totals['fail'] += stats['fail']

    print "passed: %(pass)d  failed: %(fail)d" % 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['fail'])