Mercurial > pydertron
annotate test_compliance.py @ 18:9fe3f115f951
Added license blocks.
| author | Atul Varma <varmaa@toolness.com> |
|---|---|
| date | Thu, 10 Sep 2009 14:58:00 -0700 |
| parents | 42da9c627d2d |
| children |
| rev | line source |
|---|---|
| 18 | 1 # ***** BEGIN LICENSE BLOCK ***** |
| 2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
| 3 # | |
| 4 # The contents of this file are subject to the Mozilla Public License Version | |
| 5 # 1.1 (the "License"); you may not use this file except in compliance with | |
| 6 # the License. You may obtain a copy of the License at | |
| 7 # http://www.mozilla.org/MPL/ | |
| 8 # | |
| 9 # Software distributed under the License is distributed on an "AS IS" basis, | |
| 10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
| 11 # for the specific language governing rights and limitations under the | |
| 12 # License. | |
| 13 # | |
| 14 # The Original Code is Pydertron. | |
| 15 # | |
| 16 # The Initial Developer of the Original Code is Mozilla. | |
| 17 # Portions created by the Initial Developer are Copyright (C) 2007 | |
| 18 # the Initial Developer. All Rights Reserved. | |
| 19 # | |
| 20 # Contributor(s): | |
| 21 # Atul Varma <atul@mozilla.com> | |
| 22 # | |
| 23 # Alternatively, the contents of this file may be used under the terms of | |
| 24 # either the GNU General Public License Version 2 or later (the "GPL"), or | |
| 25 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
| 26 # in which case the provisions of the GPL or the LGPL are applicable instead | |
| 27 # of those above. If you wish to allow use of your version of this file only | |
| 28 # under the terms of either the GPL or the LGPL, and not to allow others to | |
| 29 # use your version of this file under the terms of the MPL, indicate your | |
| 30 # decision by deleting the provisions above and replace them with the notice | |
| 31 # and other provisions required by the GPL or the LGPL. If you do not delete | |
| 32 # the provisions above, a recipient may use your version of this file under | |
| 33 # the terms of any one of the MPL, the GPL or the LGPL. | |
| 34 # | |
| 35 # ***** END LICENSE BLOCK ***** | |
| 36 | |
| 16 | 37 """ |
| 38 CommonJS SecurableModule standard compliance tests for Pydertron. | |
| 39 """ | |
| 40 | |
| 12 | 41 import os |
| 42 import sys | |
| 43 | |
| 44 import pydermonkey | |
| 14 | 45 from pydertron import JsSandbox, jsexposed |
| 16 | 46 from pydertron import LocalFileSystem, HttpFileSystem |
| 12 | 47 |
| 14 | 48 def run_test(name, fs): |
| 49 sandbox = JsSandbox(fs) | |
|
13
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
50 stats = {'pass': 0, 'fail': 0, 'info': 0} |
| 12 | 51 |
| 52 @jsexposed(name='print') | |
| 53 def jsprint(message, label): | |
|
13
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
54 stats[label] += 1 |
| 12 | 55 print "%s %s" % (message, label) |
| 56 | |
| 57 sandbox.set_globals( | |
| 58 sys = sandbox.new_object(**{'print': jsprint}), | |
| 59 environment = sandbox.new_object() | |
| 60 ) | |
| 61 | |
| 62 retval = sandbox.run_script("require('program')") | |
| 63 sandbox.finish() | |
| 64 print | |
| 65 | |
| 66 if retval != 0: | |
|
13
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
67 stats['fail'] += 1 |
| 12 | 68 return stats |
| 69 | |
| 70 if __name__ == '__main__': | |
| 71 base_libpath = os.path.join("interoperablejs-read-only", | |
| 72 "compliance") | |
|
15
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
73 |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
74 if len(sys.argv) == 2 and sys.argv[1] == '--with-http': |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
75 with_http = True |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
76 else: |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
77 with_http = False |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
78 |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
79 if not os.path.exists(base_libpath) and not with_http: |
| 12 | 80 print "Please run the following command and then re-run " |
| 81 print "this script:" | |
| 82 print | |
| 83 print ("svn checkout " | |
| 84 "http://interoperablejs.googlecode.com/svn/trunk/ " | |
| 85 "interoperablejs-read-only") | |
|
15
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
86 print |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
87 print "Alternatively, run this script with the '--with-http' " |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
88 print "option to run the tests over http." |
| 12 | 89 sys.exit(1) |
| 90 | |
|
15
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
91 BASE_URL = "http://interoperablejs.googlecode.com/svn/trunk/compliance/" |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
92 |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
93 if with_http: |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
94 names = ['absolute', 'cyclic', 'determinism', 'exactExports', |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
95 'hasOwnProperty', 'method', 'missing', 'monkeys', |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
96 'nested', 'reflexive', 'relative', 'transitive'] |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
97 dirs = [("%s%s/"% (BASE_URL, name), name) |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
98 for name in names] |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
99 fsfactory = HttpFileSystem |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
100 else: |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
101 dirs = [(os.path.join(base_libpath, name), name) |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
102 for name in os.listdir(base_libpath) |
|
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
103 if name not in ['.svn', 'ORACLE']] |
| 16 | 104 fsfactory = LocalFileSystem |
| 12 | 105 |
|
13
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
106 totals = {'pass': 0, 'fail': 0} |
| 12 | 107 |
| 108 for libpath, name in dirs: | |
|
15
f30bd92e2216
Added support for running test suite over http.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
109 fs = fsfactory(libpath) |
| 14 | 110 stats = run_test(name, fs) |
|
13
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
111 totals['pass'] += stats['pass'] |
|
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
112 totals['fail'] += stats['fail'] |
| 12 | 113 |
|
13
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
114 print "passed: %(pass)d failed: %(fail)d" % totals |
| 12 | 115 |
| 116 import gc | |
| 117 gc.collect() | |
| 118 if pydermonkey.get_debug_info()['runtime_count']: | |
| 119 sys.stderr.write("WARNING: JS runtime was not destroyed.\n") | |
| 120 | |
|
13
6c55f09ff31d
Minor refactorings to improve readability
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
121 sys.exit(totals['fail']) |
