~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Robert Collins
  • Date: 2005-10-17 11:56:54 UTC
  • mfrom: (1185.16.59)
  • Revision ID: robertc@robertcollins.net-20051017115654-662239e1587524a8
mergeĀ fromĀ martin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import tempfile
27
27
import unittest
28
28
import time
29
 
import codecs
30
29
 
31
 
import bzrlib.branch
32
30
import bzrlib.commands
33
 
from bzrlib.errors import BzrError
34
 
import bzrlib.inventory
35
 
import bzrlib.merge3
36
 
import bzrlib.osutils
37
 
import bzrlib.plugin
38
 
import bzrlib.store
39
31
import bzrlib.trace
40
 
from bzrlib.trace import mutter
41
 
from bzrlib.tests.TestUtil import TestLoader, TestSuite
42
 
from bzrlib.tests.treeshape import build_tree_contents
 
32
import bzrlib.fetch
 
33
import bzrlib.osutils as osutils
 
34
from bzrlib.selftest import TestUtil
 
35
from bzrlib.selftest.TestUtil import TestLoader, TestSuite
 
36
from bzrlib.selftest.treeshape import build_tree_contents
43
37
 
44
38
MODULES_TO_TEST = []
45
 
MODULES_TO_DOCTEST = [
46
 
                      bzrlib.branch,
47
 
                      bzrlib.commands,
48
 
                      bzrlib.errors,
49
 
                      bzrlib.inventory,
50
 
                      bzrlib.merge3,
51
 
                      bzrlib.osutils,
52
 
                      bzrlib.store,
53
 
                      ]
54
 
def packages_to_test():
55
 
    """Return a list of packages to test.
56
 
 
57
 
    The packages are not globally imported so that import failures are
58
 
    triggered when running selftest, not when importing the command.
59
 
    """
60
 
    import bzrlib.doc
61
 
    import bzrlib.tests.blackbox
62
 
    return [
63
 
            bzrlib.doc,
64
 
            bzrlib.tests.blackbox
65
 
            ]
 
39
MODULES_TO_DOCTEST = []
 
40
 
 
41
from logging import debug, warning, error
 
42
 
66
43
 
67
44
 
68
45
class EarlyStoppingTestResultAdapter(object):
89
66
 
90
67
 
91
68
class _MyResult(unittest._TextTestResult):
92
 
    """Custom TestResult.
 
69
    """
 
70
    Custom TestResult.
93
71
 
94
 
    Shows output in a different format, including displaying runtime for tests.
 
72
    No special behaviour for now.
95
73
    """
96
74
 
97
75
    def _elapsedTime(self):
98
 
        return "%5dms" % (1000 * (time.time() - self._start_time))
 
76
        return "(Took %.3fs)" % (time.time() - self._start_time)
99
77
 
100
78
    def startTest(self, test):
101
79
        unittest.TestResult.startTest(self, test)
102
 
        # In a short description, the important words are in
103
 
        # the beginning, but in an id, the important words are
104
 
        # at the end
105
 
        SHOW_DESCRIPTIONS = False
 
80
        # TODO: Maybe show test.shortDescription somewhere?
 
81
        what = test.shortDescription() or test.id()        
106
82
        if self.showAll:
107
 
            width = bzrlib.osutils.terminal_width()
108
 
            name_width = width - 15
109
 
            what = None
110
 
            if SHOW_DESCRIPTIONS:
111
 
                what = test.shortDescription()
112
 
                if what:
113
 
                    if len(what) > name_width:
114
 
                        what = what[:name_width-3] + '...'
115
 
            if what is None:
116
 
                what = test.id()
117
 
                if what.startswith('bzrlib.tests.'):
118
 
                    what = what[13:]
119
 
                if len(what) > name_width:
120
 
                    what = '...' + what[3-name_width:]
121
 
            what = what.ljust(name_width)
122
 
            self.stream.write(what)
 
83
            self.stream.write('%-70.70s' % what)
123
84
        self.stream.flush()
124
85
        self._start_time = time.time()
125
86
 
126
87
    def addError(self, test, err):
127
 
        if isinstance(err[1], TestSkipped):
128
 
            return self.addSkipped(test, err)    
129
88
        unittest.TestResult.addError(self, test, err)
130
89
        if self.showAll:
131
90
            self.stream.writeln("ERROR %s" % self._elapsedTime())
136
95
    def addFailure(self, test, err):
137
96
        unittest.TestResult.addFailure(self, test, err)
138
97
        if self.showAll:
139
 
            self.stream.writeln(" FAIL %s" % self._elapsedTime())
 
98
            self.stream.writeln("FAIL %s" % self._elapsedTime())
140
99
        elif self.dots:
141
100
            self.stream.write('F')
142
101
        self.stream.flush()
143
102
 
144
103
    def addSuccess(self, test):
145
104
        if self.showAll:
146
 
            self.stream.writeln('   OK %s' % self._elapsedTime())
 
105
            self.stream.writeln('OK %s' % self._elapsedTime())
147
106
        elif self.dots:
148
107
            self.stream.write('~')
149
108
        self.stream.flush()
150
109
        unittest.TestResult.addSuccess(self, test)
151
110
 
152
 
    def addSkipped(self, test, skip_excinfo):
153
 
        if self.showAll:
154
 
            print >>self.stream, ' SKIP %s' % self._elapsedTime()
155
 
            print >>self.stream, '     %s' % skip_excinfo[1]
156
 
        elif self.dots:
157
 
            self.stream.write('S')
158
 
        self.stream.flush()
159
 
        # seems best to treat this as success from point-of-view of unittest
160
 
        # -- it actually does nothing so it barely matters :)
161
 
        unittest.TestResult.addSuccess(self, test)
162
 
 
163
111
    def printErrorList(self, flavour, errors):
164
112
        for test, err in errors:
165
113
            self.stream.writeln(self.separator1)
166
114
            self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
167
115
            if hasattr(test, '_get_log'):
168
 
                print >>self.stream
169
 
                print >>self.stream, \
170
 
                        ('vvvv[log from %s]' % test).ljust(78,'-')
 
116
                self.stream.writeln()
 
117
                self.stream.writeln('log from this test:')
171
118
                print >>self.stream, test._get_log()
172
 
                print >>self.stream, \
173
 
                        ('^^^^[log from %s]' % test).ljust(78,'-')
174
119
            self.stream.writeln(self.separator2)
175
120
            self.stream.writeln("%s" % err)
176
121
 
214
159
 
215
160
    Error and debug log messages are redirected from their usual
216
161
    location into a temporary file, the contents of which can be
217
 
    retrieved by _get_log().  We use a real OS file, not an in-memory object,
218
 
    so that it can also capture file IO.  When the test completes this file
219
 
    is read into memory and removed from disk.
 
162
    retrieved by _get_log().
220
163
       
221
164
    There are also convenience functions to invoke bzr's command-line
222
 
    routine, and to build and check bzr trees.
223
 
   
224
 
    In addition to the usual method of overriding tearDown(), this class also
225
 
    allows subclasses to register functions into the _cleanups list, which is
226
 
    run in order as the object is torn down.  It's less likely this will be
227
 
    accidentally overlooked.
228
 
    """
 
165
    routine, and to build and check bzr trees."""
229
166
 
230
167
    BZRPATH = 'bzr'
231
168
    _log_file_name = None
232
 
    _log_contents = ''
233
169
 
234
170
    def setUp(self):
235
171
        unittest.TestCase.setUp(self)
236
 
        self._cleanups = []
237
 
        self._cleanEnvironment()
 
172
        self.oldenv = os.environ.get('HOME', None)
 
173
        os.environ['HOME'] = os.getcwd()
 
174
        self.bzr_email = os.environ.get('BZREMAIL')
 
175
        if self.bzr_email is not None:
 
176
            del os.environ['BZREMAIL']
 
177
        self.email = os.environ.get('EMAIL')
 
178
        if self.email is not None:
 
179
            del os.environ['EMAIL']
238
180
        bzrlib.trace.disable_default_logging()
239
 
        self._startLogFile()
 
181
        self._enable_file_logging()
240
182
 
241
183
    def _ndiff_strings(self, a, b):
242
 
        """Return ndiff between two strings containing lines.
243
 
        
244
 
        A trailing newline is added if missing to make the strings
245
 
        print properly."""
246
 
        if b and b[-1] != '\n':
247
 
            b += '\n'
248
 
        if a and a[-1] != '\n':
249
 
            a += '\n'
 
184
        """Return ndiff between two strings containing lines."""
250
185
        difflines = difflib.ndiff(a.splitlines(True),
251
186
                                  b.splitlines(True),
252
187
                                  linejunk=lambda x: False,
270
205
        if not re.search(needle_re, haystack):
271
206
            raise AssertionError('pattern "%s" not found in "%s"'
272
207
                    % (needle_re, haystack))
273
 
 
274
 
    def AssertSubset(self, sublist, superlist):
275
 
        """Assert that every entry in sublist is present in superlist."""
276
 
        missing = []
277
 
        for entry in sublist:
278
 
            if entry not in superlist:
279
 
                missing.append(entry)
280
 
        if len(missing) > 0:
281
 
            raise AssertionError("value(s) %r not present in container %r" % 
282
 
                                 (missing, superlist))
283
 
 
284
 
    def _startLogFile(self):
285
 
        """Send bzr and test log messages to a temporary file.
286
 
 
287
 
        The file is removed as the test is torn down.
288
 
        """
 
208
        
 
209
    def _enable_file_logging(self):
289
210
        fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
290
 
        encoder, decoder, stream_reader, stream_writer = codecs.lookup('UTF-8')
291
 
        self._log_file = stream_writer(os.fdopen(fileno, 'w+'))
292
 
        bzrlib.trace.enable_test_log(self._log_file)
 
211
 
 
212
        self._log_file = os.fdopen(fileno, 'w+')
 
213
 
 
214
        hdlr = logging.StreamHandler(self._log_file)
 
215
        hdlr.setLevel(logging.DEBUG)
 
216
        hdlr.setFormatter(logging.Formatter('%(levelname)8s  %(message)s'))
 
217
        logging.getLogger('').addHandler(hdlr)
 
218
        logging.getLogger('').setLevel(logging.DEBUG)
 
219
        self._log_hdlr = hdlr
 
220
        debug('opened log file %s', name)
 
221
        
293
222
        self._log_file_name = name
294
 
        self.addCleanup(self._finishLogFile)
295
 
 
296
 
    def _finishLogFile(self):
297
 
        """Finished with the log file.
298
 
 
299
 
        Read contents into memory, close, and delete.
300
 
        """
301
 
        bzrlib.trace.disable_test_log()
302
 
        self._log_file.seek(0)
303
 
        self._log_contents = self._log_file.read()
 
223
 
 
224
    def tearDown(self):
 
225
        os.environ['HOME'] = self.oldenv
 
226
        if os.environ.get('BZREMAIL') is not None:
 
227
            del os.environ['BZREMAIL']
 
228
        if self.bzr_email is not None:
 
229
            os.environ['BZREMAIL'] = self.bzr_email
 
230
        if os.environ.get('EMAIL') is not None:
 
231
            del os.environ['EMAIL']
 
232
        if self.email is not None:
 
233
            os.environ['EMAIL'] = self.email
 
234
        logging.getLogger('').removeHandler(self._log_hdlr)
 
235
        bzrlib.trace.enable_default_logging()
 
236
        logging.debug('%s teardown', self.id())
304
237
        self._log_file.close()
305
 
        os.remove(self._log_file_name)
306
 
        self._log_file = self._log_file_name = None
307
 
 
308
 
    def addCleanup(self, callable):
309
 
        """Arrange to run a callable when this case is torn down.
310
 
 
311
 
        Callables are run in the reverse of the order they are registered, 
312
 
        ie last-in first-out.
313
 
        """
314
 
        if callable in self._cleanups:
315
 
            raise ValueError("cleanup function %r already registered on %s" 
316
 
                    % (callable, self))
317
 
        self._cleanups.append(callable)
318
 
 
319
 
    def _cleanEnvironment(self):
320
 
        new_env = {
321
 
            'HOME': os.getcwd(),
322
 
            'APPDATA': os.getcwd(),
323
 
            'BZREMAIL': None,
324
 
            'EMAIL': None,
325
 
        }
326
 
        self.__old_env = {}
327
 
        self.addCleanup(self._restoreEnvironment)
328
 
        for name, value in new_env.iteritems():
329
 
            self._captureVar(name, value)
330
 
 
331
 
 
332
 
    def _captureVar(self, name, newvalue):
333
 
        """Set an environment variable, preparing it to be reset when finished."""
334
 
        self.__old_env[name] = os.environ.get(name, None)
335
 
        if newvalue is None:
336
 
            if name in os.environ:
337
 
                del os.environ[name]
338
 
        else:
339
 
            os.environ[name] = newvalue
340
 
 
341
 
    @staticmethod
342
 
    def _restoreVar(name, value):
343
 
        if value is None:
344
 
            if name in os.environ:
345
 
                del os.environ[name]
346
 
        else:
347
 
            os.environ[name] = value
348
 
 
349
 
    def _restoreEnvironment(self):
350
 
        for name, value in self.__old_env.iteritems():
351
 
            self._restoreVar(name, value)
352
 
 
353
 
    def tearDown(self):
354
 
        self._runCleanups()
355
238
        unittest.TestCase.tearDown(self)
356
239
 
357
 
    def _runCleanups(self):
358
 
        """Run registered cleanup functions. 
359
 
 
360
 
        This should only be called from TestCase.tearDown.
361
 
        """
362
 
        for cleanup_fn in reversed(self._cleanups):
363
 
            cleanup_fn()
364
 
 
365
240
    def log(self, *args):
366
 
        mutter(*args)
 
241
        logging.debug(*args)
367
242
 
368
243
    def _get_log(self):
369
244
        """Return as a string the log for this test"""
370
245
        if self._log_file_name:
371
246
            return open(self._log_file_name).read()
372
247
        else:
373
 
            return self._log_contents
374
 
        # TODO: Delete the log after it's been read in
 
248
            return ''
375
249
 
376
 
    def capture(self, cmd, retcode=0):
 
250
    def capture(self, cmd):
377
251
        """Shortcut that splits cmd into words, runs, and returns stdout"""
378
 
        return self.run_bzr_captured(cmd.split(), retcode=retcode)[0]
 
252
        return self.run_bzr_captured(cmd.split())[0]
379
253
 
380
254
    def run_bzr_captured(self, argv, retcode=0):
381
 
        """Invoke bzr and return (stdout, stderr).
 
255
        """Invoke bzr and return (result, stdout, stderr).
382
256
 
383
257
        Useful for code that wants to check the contents of the
384
258
        output, the way error messages are presented, etc.
400
274
        stdout = StringIO()
401
275
        stderr = StringIO()
402
276
        self.log('run bzr: %s', ' '.join(argv))
403
 
        # FIXME: don't call into logging here
404
277
        handler = logging.StreamHandler(stderr)
405
278
        handler.setFormatter(bzrlib.trace.QuietFormatter())
406
279
        handler.setLevel(logging.INFO)
521
394
            return
522
395
        i = 0
523
396
        while True:
524
 
            root = u'test%04d.tmp' % i
 
397
            root = 'test%04d.tmp' % i
525
398
            try:
526
399
                os.mkdir(root)
527
400
            except OSError, e:
538
411
        os.mkdir(os.path.join(TestCaseInTempDir.TEST_ROOT, '.bzr'))
539
412
 
540
413
    def setUp(self):
541
 
        super(TestCaseInTempDir, self).setUp()
542
414
        self._make_test_root()
543
 
        _currentdir = os.getcwdu()
544
 
        short_id = self.id().replace('bzrlib.tests.', '') \
 
415
        self._currentdir = os.getcwdu()
 
416
        short_id = self.id().replace('bzrlib.selftest.', '') \
545
417
                   .replace('__main__.', '')
546
418
        self.test_dir = os.path.join(self.TEST_ROOT, short_id)
547
419
        os.mkdir(self.test_dir)
548
420
        os.chdir(self.test_dir)
549
 
        os.environ['HOME'] = self.test_dir
550
 
        def _leaveDirectory():
551
 
            os.chdir(_currentdir)
552
 
        self.addCleanup(_leaveDirectory)
 
421
        super(TestCaseInTempDir, self).setUp()
553
422
        
554
 
    def build_tree(self, shape, line_endings='native'):
 
423
    def tearDown(self):
 
424
        os.chdir(self._currentdir)
 
425
        super(TestCaseInTempDir, self).tearDown()
 
426
 
 
427
    def build_tree(self, shape):
555
428
        """Build a test tree according to a pattern.
556
429
 
557
430
        shape is a sequence of file specifications.  If the final
558
431
        character is '/', a directory is created.
559
432
 
560
433
        This doesn't add anything to a branch.
561
 
        :param line_endings: Either 'binary' or 'native'
562
 
                             in binary mode, exact contents are written
563
 
                             in native mode, the line endings match the
564
 
                             default platform endings.
565
434
        """
566
435
        # XXX: It's OK to just create them using forward slashes on windows?
567
436
        for name in shape:
568
 
            self.assert_(isinstance(name, basestring))
 
437
            assert isinstance(name, basestring)
569
438
            if name[-1] == '/':
570
439
                os.mkdir(name[:-1])
571
440
            else:
572
 
                if line_endings == 'binary':
573
 
                    f = file(name, 'wb')
574
 
                elif line_endings == 'native':
575
 
                    f = file(name, 'wt')
576
 
                else:
577
 
                    raise BzrError('Invalid line ending request %r' % (line_endings,))
 
441
                f = file(name, 'wt')
578
442
                print >>f, "contents of", name
579
443
                f.close()
580
444
 
581
445
    def build_tree_contents(self, shape):
582
 
        build_tree_contents(shape)
 
446
        bzrlib.selftest.build_tree_contents(shape)
583
447
 
584
448
    def failUnlessExists(self, path):
585
449
        """Fail unless path, which may be abs or relative, exists."""
586
 
        self.failUnless(bzrlib.osutils.lexists(path))
587
 
        
588
 
    def assertFileEqual(self, content, path):
589
 
        """Fail if path does not contain 'content'."""
590
 
        self.failUnless(bzrlib.osutils.lexists(path))
591
 
        self.assertEqualDiff(content, open(path, 'r').read())
592
 
        
 
450
        self.failUnless(osutils.lexists(path))
 
451
        
 
452
 
 
453
class MetaTestLog(TestCase):
 
454
    def test_logging(self):
 
455
        """Test logs are captured when a test fails."""
 
456
        logging.info('an info message')
 
457
        warning('something looks dodgy...')
 
458
        logging.debug('hello, test is running')
 
459
        ## assert 0
 
460
 
593
461
 
594
462
def filter_suite_by_re(suite, pattern):
595
 
    result = TestSuite()
 
463
    result = TestUtil.TestSuite()
596
464
    filter_re = re.compile(pattern)
597
465
    for test in iter_suite_tests(suite):
598
466
        if filter_re.search(test.id()):
601
469
 
602
470
 
603
471
def run_suite(suite, name='test', verbose=False, pattern=".*",
604
 
              stop_on_failure=False, keep_output=False):
 
472
              stop_on_failure=False):
605
473
    TestCaseInTempDir._TEST_NAME = name
606
474
    if verbose:
607
475
        verbosity = 2
617
485
    # This is still a little bogus, 
618
486
    # but only a little. Folk not using our testrunner will
619
487
    # have to delete their temp directories themselves.
620
 
    if result.wasSuccessful() or not keep_output:
 
488
    if result.wasSuccessful():
621
489
        if TestCaseInTempDir.TEST_ROOT is not None:
622
490
            shutil.rmtree(TestCaseInTempDir.TEST_ROOT) 
623
491
    else:
625
493
    return result.wasSuccessful()
626
494
 
627
495
 
628
 
def selftest(verbose=False, pattern=".*", stop_on_failure=True,
629
 
             keep_output=False):
 
496
def selftest(verbose=False, pattern=".*", stop_on_failure=True):
630
497
    """Run the whole test suite under the enhanced runner"""
631
498
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern,
632
 
                     stop_on_failure=stop_on_failure, keep_output=keep_output)
 
499
                     stop_on_failure=stop_on_failure)
633
500
 
634
501
 
635
502
def test_suite():
636
503
    """Build and return TestSuite for the whole program."""
 
504
    import bzrlib.store, bzrlib.inventory, bzrlib.branch
 
505
    import bzrlib.osutils, bzrlib.merge3, bzrlib.plugin
637
506
    from doctest import DocTestSuite
638
507
 
639
 
    global MODULES_TO_DOCTEST
 
508
    global MODULES_TO_TEST, MODULES_TO_DOCTEST
640
509
 
641
 
    testmod_names = [ \
642
 
                   'bzrlib.tests.test_ancestry',
643
 
                   'bzrlib.tests.test_annotate',
644
 
                   'bzrlib.tests.test_api',
645
 
                   'bzrlib.tests.test_bad_files',
646
 
                   'bzrlib.tests.test_branch',
647
 
                   'bzrlib.tests.test_command',
648
 
                   'bzrlib.tests.test_commit',
649
 
                   'bzrlib.tests.test_commit_merge',
650
 
                   'bzrlib.tests.test_config',
651
 
                   'bzrlib.tests.test_conflicts',
652
 
                   'bzrlib.tests.test_diff',
653
 
                   'bzrlib.tests.test_fetch',
654
 
                   'bzrlib.tests.test_gpg',
655
 
                   'bzrlib.tests.test_graph',
656
 
                   'bzrlib.tests.test_hashcache',
657
 
                   'bzrlib.tests.test_http',
658
 
                   'bzrlib.tests.test_identitymap',
659
 
                   'bzrlib.tests.test_inv',
660
 
                   'bzrlib.tests.test_log',
661
 
                   'bzrlib.tests.test_merge',
662
 
                   'bzrlib.tests.test_merge3',
663
 
                   'bzrlib.tests.test_merge_core',
664
 
                   'bzrlib.tests.test_missing',
665
 
                   'bzrlib.tests.test_msgeditor',
666
 
                   'bzrlib.tests.test_nonascii',
667
 
                   'bzrlib.tests.test_options',
668
 
                   'bzrlib.tests.test_parent',
669
 
                   'bzrlib.tests.test_plugins',
670
 
                   'bzrlib.tests.test_remove',
671
 
                   'bzrlib.tests.test_revision',
672
 
                   'bzrlib.tests.test_revision_info',
673
 
                   'bzrlib.tests.test_revisionnamespaces',
674
 
                   'bzrlib.tests.test_revprops',
675
 
                   'bzrlib.tests.test_reweave',
676
 
                   'bzrlib.tests.test_rio',
677
 
                   'bzrlib.tests.test_sampler',
678
 
                   'bzrlib.tests.test_selftest',
679
 
                   'bzrlib.tests.test_setup',
680
 
                   'bzrlib.tests.test_sftp',
681
 
                   'bzrlib.tests.test_smart_add',
682
 
                   'bzrlib.tests.test_source',
683
 
                   'bzrlib.tests.test_status',
684
 
                   'bzrlib.tests.test_store',
685
 
                   'bzrlib.tests.test_testament',
686
 
                   'bzrlib.tests.test_trace',
687
 
                   'bzrlib.tests.test_transactions',
688
 
                   'bzrlib.tests.test_transport',
689
 
                   'bzrlib.tests.test_tsort',
690
 
                   'bzrlib.tests.test_ui',
691
 
                   'bzrlib.tests.test_uncommit',
692
 
                   'bzrlib.tests.test_upgrade',
693
 
                   'bzrlib.tests.test_weave',
694
 
                   'bzrlib.tests.test_whitebox',
695
 
                   'bzrlib.tests.test_workingtree',
696
 
                   'bzrlib.tests.test_xml',
 
510
    testmod_names = \
 
511
                  ['bzrlib.selftest.MetaTestLog',
 
512
                   'bzrlib.selftest.testgpg',
 
513
                   'bzrlib.selftest.testidentitymap',
 
514
                   'bzrlib.selftest.testinv',
 
515
                   'bzrlib.selftest.test_ancestry',
 
516
                   'bzrlib.selftest.test_commit',
 
517
                   'bzrlib.selftest.test_commit_merge',
 
518
                   'bzrlib.selftest.testconfig',
 
519
                   'bzrlib.selftest.versioning',
 
520
                   'bzrlib.selftest.testmerge3',
 
521
                   'bzrlib.selftest.testmerge',
 
522
                   'bzrlib.selftest.testhashcache',
 
523
                   'bzrlib.selftest.teststatus',
 
524
                   'bzrlib.selftest.testlog',
 
525
                   'bzrlib.selftest.testrevisionnamespaces',
 
526
                   'bzrlib.selftest.testbranch',
 
527
                   'bzrlib.selftest.testrevision',
 
528
                   'bzrlib.selftest.test_revision_info',
 
529
                   'bzrlib.selftest.test_merge_core',
 
530
                   'bzrlib.selftest.test_smart_add',
 
531
                   'bzrlib.selftest.test_bad_files',
 
532
                   'bzrlib.selftest.testdiff',
 
533
                   'bzrlib.selftest.test_parent',
 
534
                   'bzrlib.selftest.test_xml',
 
535
                   'bzrlib.selftest.test_weave',
 
536
                   'bzrlib.selftest.testfetch',
 
537
                   'bzrlib.selftest.whitebox',
 
538
                   'bzrlib.selftest.teststore',
 
539
                   'bzrlib.selftest.blackbox',
 
540
                   'bzrlib.selftest.testsampler',
 
541
                   'bzrlib.selftest.testtransactions',
 
542
                   'bzrlib.selftest.testtransport',
 
543
                   'bzrlib.selftest.testgraph',
 
544
                   'bzrlib.selftest.testworkingtree',
 
545
                   'bzrlib.selftest.test_upgrade',
 
546
                   'bzrlib.selftest.test_conflicts',
 
547
                   'bzrlib.selftest.testtestament',
 
548
                   'bzrlib.selftest.testannotate',
 
549
                   'bzrlib.selftest.testrevprops',
 
550
                   'bzrlib.selftest.testoptions',
697
551
                   ]
698
552
 
699
 
    print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
700
 
    print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
 
553
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,
 
554
              bzrlib.osutils, bzrlib.commands, bzrlib.merge3):
 
555
        if m not in MODULES_TO_DOCTEST:
 
556
            MODULES_TO_DOCTEST.append(m)
 
557
 
 
558
    TestCase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
 
559
    print '%-30s %s' % ('bzr binary', TestCase.BZRPATH)
701
560
    print
702
561
    suite = TestSuite()
703
 
    # python2.4's TestLoader.loadTestsFromNames gives very poor 
704
 
    # errors if it fails to load a named module - no indication of what's
705
 
    # actually wrong, just "no such module".  We should probably override that
706
 
    # class, but for the moment just load them ourselves. (mbp 20051202)
707
 
    loader = TestLoader()
708
 
    for mod_name in testmod_names:
709
 
        mod = _load_module_by_name(mod_name)
710
 
        suite.addTest(loader.loadTestsFromModule(mod))
711
 
    for package in packages_to_test():
712
 
        suite.addTest(package.test_suite())
 
562
    suite.addTest(TestLoader().loadTestsFromNames(testmod_names))
713
563
    for m in MODULES_TO_TEST:
714
 
        suite.addTest(loader.loadTestsFromModule(m))
 
564
         suite.addTest(TestLoader().loadTestsFromModule(m))
715
565
    for m in (MODULES_TO_DOCTEST):
716
566
        suite.addTest(DocTestSuite(m))
717
 
    for name, plugin in bzrlib.plugin.all_plugins().items():
718
 
        if hasattr(plugin, 'test_suite'):
719
 
            suite.addTest(plugin.test_suite())
 
567
    for p in bzrlib.plugin.all_plugins:
 
568
        if hasattr(p, 'test_suite'):
 
569
            suite.addTest(p.test_suite())
720
570
    return suite
721
571
 
722
 
 
723
 
def _load_module_by_name(mod_name):
724
 
    parts = mod_name.split('.')
725
 
    module = __import__(mod_name)
726
 
    del parts[0]
727
 
    # for historical reasons python returns the top-level module even though
728
 
    # it loads the submodule; we need to walk down to get the one we want.
729
 
    while parts:
730
 
        module = getattr(module, parts.pop(0))
731
 
    return module