eeejay / specular

A XML-RPC service used for examining web pages accessibility

This URL has Read+Write access

specular / run_tests.py
100755 95 lines (86 sloc) 3.703 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
#
# Speclenium Test harness
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
#
# The Initial Developer of the Original Code is Eitan Isaacson.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Original Author: Eitan Isaacson (eitan@ascender.com)
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
 
import os, os.path, sys
import unittest, new
import tests
from ConfigParser import ConfigParser
 
test_dir = os.path.join(os.path.dirname(__file__), 'tests')
 
sys.path.insert(0, test_dir)
 
def list_tests():
    print 'Available tests:'
    for tname, tclass in tests.base_tests.iteritems():
        try:
            short_desc = tclass.__doc__.split('\n')[0]
        except:
            short_desc = ''
        print ' %s%s%s' % (tname, ' '*(25-len(tname)), short_desc)
 
def main(cfg_file, matrix_args, gui):
    global test_suite
    test_suite = tests.build_test_suite(cfg_file, **matrix_args)
    if gui:
        import unittestgui
        unittestgui.main('__main__.test_suite')
    else:
        unittest.TextTestRunner().run(test_suite)
 
if __name__ == '__main__':
    from optparse import OptionParser
 
    usage = "Usage: %prog [options] tests"
    parser = OptionParser(usage)
    parser.add_option("--list-tests", dest="list_tests",
                      action="store_true", help="list available tests")
    parser.add_option("--list-agents", dest="list_agents",
                      action="store_true", help="list available user agents")
    parser.add_option("-B", "--browsers", dest="browsers",
                      help="comma seperated list of browsers")
    parser.add_option("-g", "--gui", dest="gui",
                      action="store_true", help="run tests in gui")
    parser.add_option("-c", "--config", dest="cfg_file",
                      action="store", help="config file",
                      default="settings.ini")
 
    (options, args) = parser.parse_args()
    if options.list_tests:
        list_tests()
    elif options.list_agents:
        cfg = ConfigParser()
        cfg.read(options.cfg_file)
        print 'Available user agents:'
        for section in cfg.sections():
            print ' %s' % section
    else:
        matrix_args = {}
        if args != []:
            matrix_args['tests'] = args
        if options.browsers:
            matrix_args['browsers'] = options.browsers.split(',')
        main(options.cfg_file, matrix_args, options.gui)