dom/bindings/parser/runtests.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 # This Source Code Form is subject to the terms of the Mozilla Public
     2 # License, v. 2.0. If a copy of the MPL was not distributed with this
     3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     5 import os, sys
     6 import glob
     7 import optparse
     8 import traceback
     9 import WebIDL
    11 class TestHarness(object):
    12     def __init__(self, test, verbose):
    13         self.test = test
    14         self.verbose = verbose
    15         self.printed_intro = False
    17     def start(self):
    18         if self.verbose:
    19             self.maybe_print_intro()
    21     def finish(self):
    22         if self.verbose or self.printed_intro:
    23             print "Finished test %s" % self.test
    25     def maybe_print_intro(self):
    26         if not self.printed_intro:
    27             print "Starting test %s" % self.test
    28             self.printed_intro = True
    30     def test_pass(self, msg):
    31         if self.verbose:
    32             print "TEST-PASS | %s" % msg
    34     def test_fail(self, msg):
    35         self.maybe_print_intro()
    36         print "TEST-UNEXPECTED-FAIL | %s" % msg
    38     def ok(self, condition, msg):
    39         if condition:
    40             self.test_pass(msg)
    41         else:
    42             self.test_fail(msg)
    44     def check(self, a, b, msg):
    45         if a == b:
    46             self.test_pass(msg)
    47         else:
    48             self.test_fail(msg)
    49             print "\tGot %s expected %s" % (a, b)
    51 def run_tests(tests, verbose):
    52     testdir = os.path.join(os.path.dirname(__file__), 'tests')
    53     if not tests:
    54         tests = glob.iglob(os.path.join(testdir, "*.py"))
    55     sys.path.append(testdir)
    57     for test in tests:
    58         (testpath, ext) = os.path.splitext(os.path.basename(test))
    59         _test = __import__(testpath, globals(), locals(), ['WebIDLTest'])
    61         harness = TestHarness(test, verbose)
    62         harness.start()
    63         try:
    64             _test.WebIDLTest.__call__(WebIDL.Parser(), harness)
    65         except Exception, ex:
    66             print "TEST-UNEXPECTED-FAIL | Unhandled exception in test %s: %s" % (testpath, ex)
    67             traceback.print_exc()
    68         finally:
    69             harness.finish()
    71 if __name__ == '__main__':
    72     usage = """%prog [OPTIONS] [TESTS]
    73                Where TESTS are relative to the tests directory."""
    74     parser = optparse.OptionParser(usage=usage)
    75     parser.add_option('-q', '--quiet', action='store_false', dest='verbose', default=True,
    76                       help="Don't print passing tests.")
    77     options, tests = parser.parse_args()
    79     run_tests(tests, verbose=options.verbose)

mercurial