# HG changeset patch # User Atul Varma # Date 1252619782 25200 # Node ID 42da9c627d2d18227ee2f4cbb4b3b087948652bc # Parent 9426f9fa6dc08b1bbd45c80e668a9507639d67ef Renamed test_pydertron.py to test_compliance.py. diff -r 9426f9fa6dc0 -r 42da9c627d2d test_compliance.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test_compliance.py Thu Sep 10 14:56:22 2009 -0700 @@ -0,0 +1,85 @@ +""" + CommonJS SecurableModule standard compliance tests for Pydertron. +""" + +import os +import sys + +import pydermonkey +from pydertron import JsSandbox, jsexposed +from pydertron import LocalFileSystem, 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 len(sys.argv) == 2 and sys.argv[1] == '--with-http': + with_http = True + else: + with_http = False + + if not os.path.exists(base_libpath) and not with_http: + 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") + print + print "Alternatively, run this script with the '--with-http' " + print "option to run the tests over http." + sys.exit(1) + + BASE_URL = "http://interoperablejs.googlecode.com/svn/trunk/compliance/" + + if with_http: + names = ['absolute', 'cyclic', 'determinism', 'exactExports', + 'hasOwnProperty', 'method', 'missing', 'monkeys', + 'nested', 'reflexive', 'relative', 'transitive'] + dirs = [("%s%s/"% (BASE_URL, name), name) + for name in names] + fsfactory = HttpFileSystem + else: + dirs = [(os.path.join(base_libpath, name), name) + for name in os.listdir(base_libpath) + if name not in ['.svn', 'ORACLE']] + fsfactory = LocalFileSystem + + totals = {'pass': 0, 'fail': 0} + + for libpath, name in dirs: + fs = fsfactory(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']) diff -r 9426f9fa6dc0 -r 42da9c627d2d test_pydertron.py --- a/test_pydertron.py Thu Sep 10 14:55:24 2009 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -""" - CommonJS SecurableModule standard compliance tests for Pydertron. -""" - -import os -import sys - -import pydermonkey -from pydertron import JsSandbox, jsexposed -from pydertron import LocalFileSystem, 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 len(sys.argv) == 2 and sys.argv[1] == '--with-http': - with_http = True - else: - with_http = False - - if not os.path.exists(base_libpath) and not with_http: - 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") - print - print "Alternatively, run this script with the '--with-http' " - print "option to run the tests over http." - sys.exit(1) - - BASE_URL = "http://interoperablejs.googlecode.com/svn/trunk/compliance/" - - if with_http: - names = ['absolute', 'cyclic', 'determinism', 'exactExports', - 'hasOwnProperty', 'method', 'missing', 'monkeys', - 'nested', 'reflexive', 'relative', 'transitive'] - dirs = [("%s%s/"% (BASE_URL, name), name) - for name in names] - fsfactory = HttpFileSystem - else: - dirs = [(os.path.join(base_libpath, name), name) - for name in os.listdir(base_libpath) - if name not in ['.svn', 'ORACLE']] - fsfactory = LocalFileSystem - - totals = {'pass': 0, 'fail': 0} - - for libpath, name in dirs: - fs = fsfactory(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'])