Mercurial > pydertron
comparison test_compliance.py @ 17:42da9c627d2d
Renamed test_pydertron.py to test_compliance.py.
| author | Atul Varma <varmaa@toolness.com> |
|---|---|
| date | Thu, 10 Sep 2009 14:56:22 -0700 |
| parents | test_pydertron.py@9426f9fa6dc0 |
| children | 9fe3f115f951 |
comparison
equal
deleted
inserted
replaced
| 16:9426f9fa6dc0 | 17:42da9c627d2d |
|---|---|
| 1 """ | |
| 2 CommonJS SecurableModule standard compliance tests for Pydertron. | |
| 3 """ | |
| 4 | |
| 5 import os | |
| 6 import sys | |
| 7 | |
| 8 import pydermonkey | |
| 9 from pydertron import JsSandbox, jsexposed | |
| 10 from pydertron import LocalFileSystem, HttpFileSystem | |
| 11 | |
| 12 def run_test(name, fs): | |
| 13 sandbox = JsSandbox(fs) | |
| 14 stats = {'pass': 0, 'fail': 0, 'info': 0} | |
| 15 | |
| 16 @jsexposed(name='print') | |
| 17 def jsprint(message, label): | |
| 18 stats[label] += 1 | |
| 19 print "%s %s" % (message, label) | |
| 20 | |
| 21 sandbox.set_globals( | |
| 22 sys = sandbox.new_object(**{'print': jsprint}), | |
| 23 environment = sandbox.new_object() | |
| 24 ) | |
| 25 | |
| 26 retval = sandbox.run_script("require('program')") | |
| 27 sandbox.finish() | |
| 28 print | |
| 29 | |
| 30 if retval != 0: | |
| 31 stats['fail'] += 1 | |
| 32 return stats | |
| 33 | |
| 34 if __name__ == '__main__': | |
| 35 base_libpath = os.path.join("interoperablejs-read-only", | |
| 36 "compliance") | |
| 37 | |
| 38 if len(sys.argv) == 2 and sys.argv[1] == '--with-http': | |
| 39 with_http = True | |
| 40 else: | |
| 41 with_http = False | |
| 42 | |
| 43 if not os.path.exists(base_libpath) and not with_http: | |
| 44 print "Please run the following command and then re-run " | |
| 45 print "this script:" | |
| 46 print | |
| 47 print ("svn checkout " | |
| 48 "http://interoperablejs.googlecode.com/svn/trunk/ " | |
| 49 "interoperablejs-read-only") | |
| 50 print | |
| 51 print "Alternatively, run this script with the '--with-http' " | |
| 52 print "option to run the tests over http." | |
| 53 sys.exit(1) | |
| 54 | |
| 55 BASE_URL = "http://interoperablejs.googlecode.com/svn/trunk/compliance/" | |
| 56 | |
| 57 if with_http: | |
| 58 names = ['absolute', 'cyclic', 'determinism', 'exactExports', | |
| 59 'hasOwnProperty', 'method', 'missing', 'monkeys', | |
| 60 'nested', 'reflexive', 'relative', 'transitive'] | |
| 61 dirs = [("%s%s/"% (BASE_URL, name), name) | |
| 62 for name in names] | |
| 63 fsfactory = HttpFileSystem | |
| 64 else: | |
| 65 dirs = [(os.path.join(base_libpath, name), name) | |
| 66 for name in os.listdir(base_libpath) | |
| 67 if name not in ['.svn', 'ORACLE']] | |
| 68 fsfactory = LocalFileSystem | |
| 69 | |
| 70 totals = {'pass': 0, 'fail': 0} | |
| 71 | |
| 72 for libpath, name in dirs: | |
| 73 fs = fsfactory(libpath) | |
| 74 stats = run_test(name, fs) | |
| 75 totals['pass'] += stats['pass'] | |
| 76 totals['fail'] += stats['fail'] | |
| 77 | |
| 78 print "passed: %(pass)d failed: %(fail)d" % totals | |
| 79 | |
| 80 import gc | |
| 81 gc.collect() | |
| 82 if pydermonkey.get_debug_info()['runtime_count']: | |
| 83 sys.stderr.write("WARNING: JS runtime was not destroyed.\n") | |
| 84 | |
| 85 sys.exit(totals['fail']) |
