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

Revision 882, 3.5 KB checked in by lele@…, 8 years ago (diff)

Reorganization of the test suite

  • Dropped "Test" from test names
  • Added an option --list get the available tests
  • Splitted the too heavy operational test into smaller suites
  • Added bazaar-ng source backend test
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 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        del sys.argv[1]
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:], 'hHvql',
52                                          ['help','verbose','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 ('-l','--list'):
62                    listonly = True
63            if len(args) == 0 and self.defaultTest is None:
64                self.test = self.testLoader.loadTestsFromModule(self.module)
65            else:
66                if len(args) > 0:
67                    self.testNames = args
68                else:
69                    self.testNames = (self.defaultTest,)
70                self.createTests()
71            if listonly:
72                def listsuite(suite):
73                    tcount = 0
74                    scount = 0
75                    tclass = None
76                    for t in suite._tests:
77                        if isinstance(t, TestSuite):
78                            tc,sc = listsuite(t)
79                            tcount += tc
80                            scount += sc + 1
81                        else:
82                            tcount += 1
83                            if tclass <> t.__class__:
84                                tclass = t.__class__
85                                title = tclass.__name__
86                                if tclass.__doc__:
87                                    title += ': ' + tclass.__doc__.strip()
88                                print
89                                print title
90                                print '='*len(title)
91                            print t._TestCase__testMethodName, '--',
92                            print t.shortDescription()
93                    return tcount, scount
94                tcount, scount = listsuite(self.test)
95                print
96                print "%d tests in %d suites" % (tcount,scount)
97                sys.exit(0)
98        except getopt.error, msg:
99            self.usageExit(msg)
100
101main = TailorTest
Note: See TracBrowser for help on using the repository browser.