~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-12 20:36:40 UTC
  • mfrom: (2413 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070412203640-z1jld315288moxvy
[merge] bzr.dev 2413

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
                      bzrlib.store,
105
105
                      ]
106
106
 
107
 
NUMBERED_DIRS = False   # dirs kind for TestCaseInTempDir (numbered or named)
108
 
 
109
107
 
110
108
def packages_to_test():
111
109
    """Return a list of packages to test.
154
152
    def __init__(self, stream, descriptions, verbosity,
155
153
                 bench_history=None,
156
154
                 num_tests=None,
 
155
                 use_numbered_dirs=False,
157
156
                 ):
158
157
        """Construct new TestResult.
159
158
 
184
183
        self.skip_count = 0
185
184
        self.unsupported = {}
186
185
        self.count = 0
 
186
        self.use_numbered_dirs = use_numbered_dirs
187
187
        self._overall_start_time = time.time()
188
188
    
189
189
    def extractBenchmarkTime(self, testCase):
290
290
        for test, err in errors:
291
291
            self.stream.writeln(self.separator1)
292
292
            self.stream.write("%s: " % flavour)
293
 
            if NUMBERED_DIRS:
 
293
            if self.use_numbered_dirs:
294
294
                self.stream.write('#%d ' % test.number)
295
295
            self.stream.writeln(self.getDescription(test))
296
296
            if getattr(test, '_get_log', None) is not None:
320
320
                 bench_history=None,
321
321
                 num_tests=None,
322
322
                 pb=None,
 
323
                 use_numbered_dirs=False,
323
324
                 ):
324
325
        ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
325
 
            bench_history, num_tests)
 
326
            bench_history, num_tests, use_numbered_dirs)
326
327
        if pb is None:
327
328
            self.pb = self.ui.nested_progress_bar()
328
329
            self._supplied_pb = False
364
365
                + self._shortened_test_description(test))
365
366
 
366
367
    def _test_description(self, test):
367
 
        if NUMBERED_DIRS:
 
368
        if self.use_numbered_dirs:
368
369
            return '#%d %s' % (self.count,
369
370
                               self._shortened_test_description(test))
370
371
        else:
433
434
        # width needs space for 6 char status, plus 1 for slash, plus 2 10-char
434
435
        # numbers, plus a trailing blank
435
436
        # when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on space
436
 
        if NUMBERED_DIRS:
 
437
        if self.use_numbered_dirs:
437
438
            self.stream.write('%5d ' % self.count)
438
439
            self.stream.write(self._ellipsize_to_right(name,
439
440
                                osutils.terminal_width()-36))
444
445
 
445
446
    def _error_summary(self, err):
446
447
        indent = ' ' * 4
447
 
        if NUMBERED_DIRS:
 
448
        if self.use_numbered_dirs:
448
449
            indent += ' ' * 6
449
450
        return '%s%s' % (indent, err[1])
450
451
 
493
494
                 descriptions=0,
494
495
                 verbosity=1,
495
496
                 keep_output=False,
496
 
                 bench_history=None):
 
497
                 bench_history=None,
 
498
                 use_numbered_dirs=False,
 
499
                 ):
497
500
        self.stream = unittest._WritelnDecorator(stream)
498
501
        self.descriptions = descriptions
499
502
        self.verbosity = verbosity
500
503
        self.keep_output = keep_output
501
504
        self._bench_history = bench_history
 
505
        self.use_numbered_dirs = use_numbered_dirs
502
506
 
503
507
    def run(self, test):
504
508
        "Run the given test case or test suite."
512
516
                              self.verbosity,
513
517
                              bench_history=self._bench_history,
514
518
                              num_tests=test.countTestCases(),
 
519
                              use_numbered_dirs=self.use_numbered_dirs,
515
520
                              )
516
521
        result.stop_early = self.stop_on_failure
517
522
        result.report_starting()
570
575
                else:
571
576
                    test_root = test_root.encode(
572
577
                        sys.getfilesystemencoding())
573
 
                try:
574
 
                    osutils.rmtree(test_root)
575
 
                except OSError, e:
576
 
                    if sys.platform == 'win32' and e.errno == errno.EACCES:
577
 
                        print >>sys.stderr, ('Permission denied: '
578
 
                                             'unable to remove testing dir '
579
 
                                             '%s' % os.path.basename(test_root))
580
 
                    else:
581
 
                        raise
 
578
                _rmtree_temp_dir(test_root)
582
579
        else:
583
580
            note("Failed tests working directories are in '%s'\n", test_root)
584
581
        TestCaseWithMemoryTransport.TEST_ROOT = None
755
752
        self._benchcalls = []
756
753
        self._benchtime = None
757
754
        # prevent hooks affecting tests
758
 
        self._preserved_hooks = bzrlib.branch.Branch.hooks
 
755
        self._preserved_hooks = {
 
756
            bzrlib.branch.Branch:bzrlib.branch.Branch.hooks,
 
757
            bzrlib.smart.server.SmartTCPServer:bzrlib.smart.server.SmartTCPServer.hooks,
 
758
            }
759
759
        self.addCleanup(self._restoreHooks)
760
760
        # this list of hooks must be kept in sync with the defaults
761
761
        # in branch.py
1101
1101
            osutils.set_or_unset_env(name, value)
1102
1102
 
1103
1103
    def _restoreHooks(self):
1104
 
        bzrlib.branch.Branch.hooks = self._preserved_hooks
 
1104
        for klass, hooks in self._preserved_hooks.items():
 
1105
            setattr(klass, 'hooks', hooks)
1105
1106
 
1106
1107
    def knownFailure(self, reason):
1107
1108
        """This test has failed for some known reason."""
1826
1827
    """
1827
1828
 
1828
1829
    OVERRIDE_PYTHON = 'python'
 
1830
    use_numbered_dirs = False
1829
1831
 
1830
1832
    def check_file_contents(self, filename, expect):
1831
1833
        self.log("check contents of file %s" % filename)
1841
1843
        For TestCaseInTempDir we create a temporary directory based on the test
1842
1844
        name and then create two subdirs - test and home under it.
1843
1845
        """
1844
 
        if NUMBERED_DIRS:       # strongly recommended on Windows
1845
 
                                # due the path length limitation (260 chars)
 
1846
        if self.use_numbered_dirs:  # strongly recommended on Windows
 
1847
                                    # due the path length limitation (260 ch.)
1846
1848
            candidate_dir = '%s/%dK/%05d' % (self.TEST_ROOT,
1847
1849
                                             int(self.number/1000),
1848
1850
                                             self.number)
2070
2072
              transport=None, lsprof_timed=None, bench_history=None,
2071
2073
              matching_tests_first=None,
2072
2074
              numbered_dirs=None):
2073
 
    global NUMBERED_DIRS
 
2075
    use_numbered_dirs = bool(numbered_dirs)
 
2076
 
 
2077
    TestCase._gather_lsprof_in_benchmarks = lsprof_timed
2074
2078
    if numbered_dirs is not None:
2075
 
        NUMBERED_DIRS = bool(numbered_dirs)
2076
 
 
2077
 
    TestCase._gather_lsprof_in_benchmarks = lsprof_timed
 
2079
        TestCaseInTempDir.use_numbered_dirs = use_numbered_dirs
2078
2080
    if verbose:
2079
2081
        verbosity = 2
2080
2082
    else:
2083
2085
                            descriptions=0,
2084
2086
                            verbosity=verbosity,
2085
2087
                            keep_output=keep_output,
2086
 
                            bench_history=bench_history)
 
2088
                            bench_history=bench_history,
 
2089
                            use_numbered_dirs=use_numbered_dirs,
 
2090
                            )
2087
2091
    runner.stop_on_failure=stop_on_failure
2088
2092
    if pattern != '.*':
2089
2093
        if matching_tests_first:
2287
2291
        suite.addTests(adapter.adapt(test))
2288
2292
 
2289
2293
 
 
2294
def _rmtree_temp_dir(dirname):
 
2295
    try:
 
2296
        osutils.rmtree(dirname)
 
2297
    except OSError, e:
 
2298
        if sys.platform == 'win32' and e.errno == errno.EACCES:
 
2299
            print >>sys.stderr, ('Permission denied: '
 
2300
                                 'unable to remove testing dir '
 
2301
                                 '%s' % os.path.basename(test_root))
 
2302
        else:
 
2303
            raise
 
2304
 
 
2305
 
2290
2306
def clean_selftest_output(root=None, quiet=False):
2291
2307
    """Remove all selftest output directories from root directory.
2292
2308
 
2304
2320
        if os.path.isdir(i) and re_dir.match(i):
2305
2321
            if not quiet:
2306
2322
                print 'delete directory:', i
2307
 
            shutil.rmtree(i)
 
2323
            _rmtree_temp_dir(i)
2308
2324
 
2309
2325
 
2310
2326
class Feature(object):