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

Revision 945, 3.6 KB checked in by lele@…, 8 years ago (diff)

Disable the logging while testing

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, logging
9from unittest import TestProgram, TestSuite
10
11from shwrap import *
12from cvsps import *
13from cvs import *
14from darcs import *
15from svn import *
16from config import *
17from statefile import *
18from tailor import *
19from svndump import *
20
21ExternalCommand.VERBOSE = False
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  -q, --quiet      Minimal output
34  -l, --list       List available tests without running them
35
36Examples:
37  %(progName)s                               - run default set of tests
38  %(progName)s MyTestSuite                   - run suite 'MyTestSuite'
39  %(progName)s MyTestCase.testSomething      - run MyTestCase.testSomething
40  %(progName)s MyTestCase                    - run all 'test*' test methods
41                                               in MyTestCase
42"""
43
44    def __init__(self):
45        logging.disable(logging.CRITICAL)
46        del sys.argv[1]
47        TestProgram.__init__(self, module='vcpx.tests', argv=sys.argv)
48
49    def parseArgs(self, argv):
50        import getopt
51        try:
52            options, args = getopt.getopt(argv[1:], 'hHvql',
53                                          ['help','verbose','quiet','list'])
54            listonly = False
55            for opt, value in options:
56                if opt in ('-h','-H','--help'):
57                    self.usageExit()
58                if opt in ('-q','--quiet'):
59                    self.verbosity = 0
60                if opt in ('-v','--verbose'):
61                    self.verbosity = 2
62                if opt in ('-l','--list'):
63                    listonly = True
64            if len(args) == 0 and self.defaultTest is None:
65                self.test = self.testLoader.loadTestsFromModule(self.module)
66            else:
67                if len(args) > 0:
68                    self.testNames = args
69                else:
70                    self.testNames = (self.defaultTest,)
71                self.createTests()
72            if listonly:
73                def listsuite(suite):
74                    tcount = 0
75                    scount = 0
76                    tclass = None
77                    for t in suite._tests:
78                        if isinstance(t, TestSuite):
79                            tc,sc = listsuite(t)
80                            tcount += tc
81                            scount += sc + 1
82                        else:
83                            tcount += 1
84                            if tclass <> t.__class__:
85                                tclass = t.__class__
86                                title = tclass.__name__
87                                if tclass.__doc__:
88                                    title += ': ' + tclass.__doc__.strip()
89                                print
90                                print title
91                                print '='*len(title)
92                            print t._TestCase__testMethodName, '--',
93                            print t.shortDescription()
94                    return tcount, scount
95                tcount, scount = listsuite(self.test)
96                print
97                print "%d tests in %d suites" % (tcount,scount)
98                sys.exit(0)
99        except getopt.error, msg:
100            self.usageExit(msg)
101
102main = TailorTest
Note: See TracBrowser for help on using the repository browser.