source: tailor/vcpx/tests/__init__.py @ 1267

Revision 1267, 3.7 KB checked in by lele@…, 7 years ago (diff)

New --debug option for tests, to show external commands

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- Test suite
3# :Creato:   mar 20 apr 2004 16:19:15 CEST
4# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
5# :Licenza:  GNU General Public License
6#
7
8import sys
9from unittest import TestProgram, TestSuite
10
11DEBUG = False
12
13from shwrap import *
14from cvsps import *
15from cvs import *
16from darcs import *
17from svn import *
18from config import *
19from statefile import *
20from tailor import *
21from fixed_bugs import *
22
23class TailorTest(TestProgram):
24    """A command-line program that runs a set of tests; this is primarily
25       for making test modules conveniently executable.
26    """
27    USAGE = """\
28Usage: %(progName)s [options] [test] [...]
29
30Options:
31  -h, --help       Show this message
32  -v, --verbose    Verbose output
33  -d, --debug      Debug output
34  -q, --quiet      Minimal output
35  -l, --list       List available tests without running them
36
37Examples:
38  %(progName)s                               - run default set of tests
39  %(progName)s MyTestSuite                   - run suite 'MyTestSuite'
40  %(progName)s MyTestCase.testSomething      - run MyTestCase.testSomething
41  %(progName)s MyTestCase                    - run all 'test*' test methods
42                                               in MyTestCase
43"""
44
45    def __init__(self):
46        TestProgram.__init__(self, module='vcpx.tests', argv=sys.argv)
47
48    def parseArgs(self, argv):
49        import getopt
50        try:
51            options, args = getopt.getopt(argv[1:], 'hHvdql',
52                                          ['help','verbose','debug','quiet','list'])
53            listonly = False
54            for opt, value in options:
55                if opt in ('-h','-H','--help'):
56                    self.usageExit()
57                if opt in ('-q','--quiet'):
58                    self.verbosity = 0
59                if opt in ('-v','--verbose'):
60                    self.verbosity = 2
61                if opt in ('-d','--debug'):
62                    global DEBUG
63                    DEBUG = True
64                if opt in ('-l','--list'):
65                    listonly = True
66            if len(args) == 0 and self.defaultTest is None:
67                self.test = self.testLoader.loadTestsFromModule(self.module)
68            else:
69                if len(args) > 0:
70                    self.testNames = args
71                else:
72                    self.testNames = (self.defaultTest,)
73                self.createTests()
74            if listonly:
75                def listsuite(suite):
76                    tcount = 0
77                    scount = 0
78                    tclass = None
79                    for t in suite._tests:
80                        if isinstance(t, TestSuite):
81                            tc,sc = listsuite(t)
82                            tcount += tc
83                            scount += sc + 1
84                        else:
85                            tcount += 1
86                            if tclass <> t.__class__:
87                                tclass = t.__class__
88                                title = tclass.__name__
89                                if tclass.__doc__:
90                                    title += ': ' + tclass.__doc__.strip()
91                                print
92                                print title
93                                print '='*len(title)
94                            print t._TestCase__testMethodName, '--',
95                            print t.shortDescription()
96                    return tcount, scount
97                tcount, scount = listsuite(self.test)
98                print
99                print "%d tests in %d suites" % (tcount,scount)
100                sys.exit(0)
101        except getopt.error, msg:
102            self.usageExit(msg)
103
104main = TailorTest
Note: See TracBrowser for help on using the repository browser.