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

Revision 1230, 3.5 KB checked in by Adeodato Simo <dato@…>, 7 years ago (diff)

A mock source backend to aid with 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
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 fixed_bugs import *
20
21class TailorTest(TestProgram):
22    """A command-line program that runs a set of tests; this is primarily
23       for making test modules conveniently executable.
24    """
25    USAGE = """\
26Usage: %(progName)s [options] [test] [...]
27
28Options:
29  -h, --help       Show this message
30  -v, --verbose    Verbose output
31  -q, --quiet      Minimal output
32  -l, --list       List available tests without running them
33
34Examples:
35  %(progName)s                               - run default set of tests
36  %(progName)s MyTestSuite                   - run suite 'MyTestSuite'
37  %(progName)s MyTestCase.testSomething      - run MyTestCase.testSomething
38  %(progName)s MyTestCase                    - run all 'test*' test methods
39                                               in MyTestCase
40"""
41
42    def __init__(self):
43        TestProgram.__init__(self, module='vcpx.tests', argv=sys.argv)
44
45    def parseArgs(self, argv):
46        import getopt
47        try:
48            options, args = getopt.getopt(argv[1:], 'hHvql',
49                                          ['help','verbose','quiet','list'])
50            listonly = False
51            for opt, value in options:
52                if opt in ('-h','-H','--help'):
53                    self.usageExit()
54                if opt in ('-q','--quiet'):
55                    self.verbosity = 0
56                if opt in ('-v','--verbose'):
57                    self.verbosity = 2
58                if opt in ('-l','--list'):
59                    listonly = True
60            if len(args) == 0 and self.defaultTest is None:
61                self.test = self.testLoader.loadTestsFromModule(self.module)
62            else:
63                if len(args) > 0:
64                    self.testNames = args
65                else:
66                    self.testNames = (self.defaultTest,)
67                self.createTests()
68            if listonly:
69                def listsuite(suite):
70                    tcount = 0
71                    scount = 0
72                    tclass = None
73                    for t in suite._tests:
74                        if isinstance(t, TestSuite):
75                            tc,sc = listsuite(t)
76                            tcount += tc
77                            scount += sc + 1
78                        else:
79                            tcount += 1
80                            if tclass <> t.__class__:
81                                tclass = t.__class__
82                                title = tclass.__name__
83                                if tclass.__doc__:
84                                    title += ': ' + tclass.__doc__.strip()
85                                print
86                                print title
87                                print '='*len(title)
88                            print t._TestCase__testMethodName, '--',
89                            print t.shortDescription()
90                    return tcount, scount
91                tcount, scount = listsuite(self.test)
92                print
93                print "%d tests in %d suites" % (tcount,scount)
94                sys.exit(0)
95        except getopt.error, msg:
96            self.usageExit(msg)
97
98main = TailorTest
Note: See TracBrowser for help on using the repository browser.