~ubuntu-branches/ubuntu/precise/nvidia-common/precise-proposed

« back to all changes in this revision

Viewing changes to tests/run

  • Committer: Package Import Robot
  • Author(s): Alberto Milone
  • Date: 2012-03-12 12:30:52 UTC
  • Revision ID: package-import@ubuntu.com-20120312123052-o4s60xr1ob9uy5qt
Tags: 1:0.2.41
* Add a test suite and run it at build time with dh_auto_test.
* Work correctly when the pipe symbol is used in "Match" tags.
  This symbol only worked when used in the "Handler" tag.
  Both test cases are covered in the test suite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: UTF-8 -*-
 
3
 
 
4
'''Run self tests.'''
 
5
 
 
6
# (c) 2008 Alberto Milone <albertomilone@alice.it>
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation; either version 2 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License along
 
19
# with this program; if not, write to the Free Software Foundation, Inc.,
 
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
21
 
 
22
import unittest, os.path, sys, logging, os
 
23
import getopt
 
24
 
 
25
def usage():
 
26
    instructionsList = ['The only accepted (optional) parameters are:'
 
27
    '\n  -o, --output=<dirname>', '\tthe directory where the results \n\
 
28
\t\t\t\tof the tests are saved.'
 
29
    
 
30
    '\n  -i, --input=<filename>', '\tthe xorg.conf used for the tests.'
 
31
    
 
32
    '\n  -h, --help', '\t\t\thelp page.'
 
33
    ]
 
34
    print ''.join(instructionsList)
 
35
 
 
36
def main():
 
37
    cwd = os.getcwd()
 
38
    inputFile = os.path.join(cwd, 'xorg.conf')
 
39
    outputDir = cwd
 
40
    err = 'Error: parameters not recognised'
 
41
    
 
42
    try:
 
43
        opts, args = getopt.getopt(sys.argv[1:], 'h:o:i:', ['help', 'output=', 'input='])
 
44
    except getopt.GetoptError, err:
 
45
        # print help information and exit:
 
46
        print str(err) # will print something like 'option -a not recognized'
 
47
        usage()
 
48
        sys.exit(2)
 
49
    printonly = None
 
50
    verbose = None
 
51
    for o, a in opts:
 
52
        if o in ('-i', '--input'):
 
53
            inputFile = a
 
54
        elif o in ('-o', '--output'):
 
55
            outputDir = a
 
56
        elif o in ('-h', '--help'):
 
57
            usage()
 
58
            sys.exit()
 
59
        else:
 
60
            assert False, 'unhandled option'
 
61
    
 
62
    
 
63
    settingsFile = open('settings.py', 'w')
 
64
    if inputFile == os.path.join(cwd, 'xorg.conf') and outputDir == cwd:
 
65
        settingsFile.write('import os\ncwd = os.getcwd()\ninputFile = os.path.join(cwd, "xorg.conf")\noutputDir = cwd')
 
66
    else:    
 
67
        settingsFile.write('inputFile = "%s"\noutputDir = "%s"' % (inputFile, outputDir))
 
68
    settingsFile.close()
 
69
        
 
70
    # run all tests in our directory
 
71
    suite = unittest.TestLoader().loadTestsFromNames(
 
72
        [t[:-3] for t in os.listdir(os.path.dirname(__file__)) 
 
73
         if t.endswith('.py') and t not in ['settings.py', '__init__.py']])
 
74
    res = unittest.TextTestRunner(verbosity=2).run(suite)
 
75
    
 
76
 
 
77
if __name__ == '__main__':
 
78
    main()