Changeset 882 in tailor for vcpx/tests/__init__.py


Ignore:
Timestamp:
10/06/05 01:20:46 (8 years ago)
Author:
lele@…
Hash name:
20051005232046-97f81-a428e84c397d7e458a784e40f3316a2c2c070055
Message:

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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/tests/__init__.py

    r729 r882  
    55# :Licenza:  GNU General Public License 
    66# 
     7 
     8import sys 
     9from unittest import TestProgram, TestSuite 
    710 
    811from shwrap import * 
     
    1720 
    1821ExternalCommand.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 TracChangeset for help on using the changeset viewer.