Mercurial > pydertron
changeset 12:e4978bd08bfa
Factored out unit test suite
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 10 Sep 2009 13:53:03 -0700 |
parents | 665f69f61716 |
children | 6c55f09ff31d |
files | pydertron.py test_pydertron.py |
diffstat | 2 files changed, 63 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/pydertron.py Thu Sep 10 13:51:04 2009 -0700 +++ b/pydertron.py Thu Sep 10 13:53:03 2009 -0700 @@ -474,7 +474,6 @@ filename = self.fs.find_module(self.get_calling_script(), path) if not filename: raise pydermonkey.error('Module not found: %s' % path) - if not filename in self.__modules: cx = self.cx module = cx.new_object(None, self.__root_proto) @@ -535,61 +534,3 @@ def open(self, filename): return open(filename, 'r') - -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])
--- /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])