Mercurial > pydertron
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 11:665f69f61716 | 12:e4978bd08bfa |
|---|---|
| 1 import os | |
| 2 import sys | |
| 3 | |
| 4 import pydermonkey | |
| 5 from pydertron import JsSandbox, SandboxedFileSystem, jsexposed | |
| 6 | |
| 7 def run_test(name, libpath): | |
| 8 sandbox = JsSandbox(SandboxedFileSystem(libpath)) | |
| 9 | |
| 10 stats = [0, 0] | |
| 11 | |
| 12 @jsexposed(name='print') | |
| 13 def jsprint(message, label): | |
| 14 if label == "pass": | |
| 15 stats[0] += 1 | |
| 16 elif label == "fail": | |
| 17 stats[1] += 1 | |
| 18 print "%s %s" % (message, label) | |
| 19 | |
| 20 sandbox.set_globals( | |
| 21 sys = sandbox.new_object(**{'print': jsprint}), | |
| 22 environment = sandbox.new_object() | |
| 23 ) | |
| 24 | |
| 25 retval = sandbox.run_script("require('program')") | |
| 26 sandbox.finish() | |
| 27 print | |
| 28 | |
| 29 if retval != 0: | |
| 30 stats[1] += 1 | |
| 31 return stats | |
| 32 | |
| 33 if __name__ == '__main__': | |
| 34 base_libpath = os.path.join("interoperablejs-read-only", | |
| 35 "compliance") | |
| 36 if not os.path.exists(base_libpath): | |
| 37 print "Please run the following command and then re-run " | |
| 38 print "this script:" | |
| 39 print | |
| 40 print ("svn checkout " | |
| 41 "http://interoperablejs.googlecode.com/svn/trunk/ " | |
| 42 "interoperablejs-read-only") | |
| 43 sys.exit(1) | |
| 44 | |
| 45 dirs = [(os.path.join(base_libpath, name), name) | |
| 46 for name in os.listdir(base_libpath) | |
| 47 if name not in ['.svn', 'ORACLE']] | |
| 48 | |
| 49 totals = [0, 0] | |
| 50 | |
| 51 for libpath, name in dirs: | |
| 52 passed, failed = run_test(name, libpath) | |
| 53 totals[0] += passed | |
| 54 totals[1] += failed | |
| 55 | |
| 56 print "passed: %d failed: %d" % tuple(totals) | |
| 57 | |
| 58 import gc | |
| 59 gc.collect() | |
| 60 if pydermonkey.get_debug_info()['runtime_count']: | |
| 61 sys.stderr.write("WARNING: JS runtime was not destroyed.\n") | |
| 62 | |
| 63 sys.exit(totals[1]) |
