~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Merge from mbp.

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
29
30
 
30
31
import bzrlib.branch
31
32
import bzrlib.commands
116
117
        self._start_time = time.time()
117
118
 
118
119
    def addError(self, test, err):
 
120
        if isinstance(err[1], TestSkipped):
 
121
            return self.addSkipped(test, err)    
119
122
        unittest.TestResult.addError(self, test, err)
120
123
        if self.showAll:
121
124
            self.stream.writeln("ERROR %s" % self._elapsedTime())
139
142
        self.stream.flush()
140
143
        unittest.TestResult.addSuccess(self, test)
141
144
 
 
145
    def addSkipped(self, test, skip_excinfo):
 
146
        if self.showAll:
 
147
            print >>self.stream, ' SKIP %s' % self._elapsedTime()
 
148
            print >>self.stream, '     %s' % skip_excinfo[1]
 
149
        elif self.dots:
 
150
            self.stream.write('S')
 
151
        self.stream.flush()
 
152
        # seems best to treat this as success from point-of-view of unittest
 
153
        # -- it actually does nothing so it barely matters :)
 
154
        unittest.TestResult.addSuccess(self, test)
 
155
 
142
156
    def printErrorList(self, flavour, errors):
143
157
        for test, err in errors:
144
158
            self.stream.writeln(self.separator1)
145
159
            self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
146
160
            if hasattr(test, '_get_log'):
147
 
                self.stream.writeln()
148
 
                self.stream.writeln('log from this test:')
 
161
                print >>self.stream
 
162
                print >>self.stream, \
 
163
                        ('vvvv[log from %s]' % test).ljust(78,'-')
149
164
                print >>self.stream, test._get_log()
 
165
                print >>self.stream, \
 
166
                        ('^^^^[log from %s]' % test).ljust(78,'-')
150
167
            self.stream.writeln(self.separator2)
151
168
            self.stream.writeln("%s" % err)
152
169
 
247
264
            raise AssertionError('pattern "%s" not found in "%s"'
248
265
                    % (needle_re, haystack))
249
266
 
 
267
    def AssertSubset(self, sublist, superlist):
 
268
        """Assert that every entry in sublist is present in superlist."""
 
269
        missing = []
 
270
        for entry in sublist:
 
271
            if entry not in superlist:
 
272
                missing.append(entry)
 
273
        if len(missing) > 0:
 
274
            raise AssertionError("value(s) %r not present in container %r" % 
 
275
                                 (missing, superlist))
 
276
 
250
277
    def _startLogFile(self):
251
278
        """Send bzr and test log messages to a temporary file.
252
279
 
253
280
        The file is removed as the test is torn down.
254
281
        """
255
282
        fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
256
 
        self._log_file = os.fdopen(fileno, 'w+')
 
283
        encoder, decoder, stream_reader, stream_writer = codecs.lookup('UTF-8')
 
284
        self._log_file = stream_writer(os.fdopen(fileno, 'w+'))
257
285
        bzrlib.trace.enable_test_log(self._log_file)
258
286
        self._log_file_name = name
259
287
        self.addCleanup(self._finishLogFile)
604
632
    global MODULES_TO_DOCTEST
605
633
 
606
634
    testmod_names = [ \
 
635
                   'bzrlib.tests.test_ancestry',
 
636
                   'bzrlib.tests.test_annotate',
607
637
                   'bzrlib.tests.test_api',
608
 
                   'bzrlib.tests.test_gpg',
609
 
                   'bzrlib.tests.test_identitymap',
610
 
                   'bzrlib.tests.test_inv',
611
 
                   'bzrlib.tests.test_ancestry',
 
638
                   'bzrlib.tests.test_bad_files',
 
639
                   'bzrlib.tests.test_branch',
 
640
                   'bzrlib.tests.test_command',
612
641
                   'bzrlib.tests.test_commit',
613
 
                   'bzrlib.tests.test_command',
614
642
                   'bzrlib.tests.test_commit_merge',
615
643
                   'bzrlib.tests.test_config',
616
 
                   'bzrlib.tests.test_merge3',
617
 
                   'bzrlib.tests.test_merge',
 
644
                   'bzrlib.tests.test_conflicts',
 
645
                   'bzrlib.tests.test_diff',
 
646
                   'bzrlib.tests.test_fetch',
 
647
                   'bzrlib.tests.test_gpg',
 
648
                   'bzrlib.tests.test_graph',
618
649
                   'bzrlib.tests.test_hashcache',
619
 
                   'bzrlib.tests.test_status',
 
650
                   'bzrlib.tests.test_http',
 
651
                   'bzrlib.tests.test_identitymap',
 
652
                   'bzrlib.tests.test_inv',
620
653
                   'bzrlib.tests.test_log',
621
 
                   'bzrlib.tests.test_revisionnamespaces',
622
 
                   'bzrlib.tests.test_branch',
 
654
                   'bzrlib.tests.test_merge',
 
655
                   'bzrlib.tests.test_merge3',
 
656
                   'bzrlib.tests.test_merge_core',
 
657
                   'bzrlib.tests.test_missing',
 
658
                   'bzrlib.tests.test_msgeditor',
 
659
                   'bzrlib.tests.test_nonascii',
 
660
                   'bzrlib.tests.test_options',
 
661
                   'bzrlib.tests.test_parent',
 
662
                   'bzrlib.tests.test_plugins',
 
663
                   'bzrlib.tests.test_remove',
623
664
                   'bzrlib.tests.test_revision',
624
665
                   'bzrlib.tests.test_revision_info',
625
 
                   'bzrlib.tests.test_merge_core',
 
666
                   'bzrlib.tests.test_revisionnamespaces',
 
667
                   'bzrlib.tests.test_revprops',
 
668
                   'bzrlib.tests.test_reweave',
 
669
                   'bzrlib.tests.test_rio',
 
670
                   'bzrlib.tests.test_sampler',
 
671
                   'bzrlib.tests.test_selftest',
 
672
                   'bzrlib.tests.test_setup',
 
673
                   'bzrlib.tests.test_sftp',
626
674
                   'bzrlib.tests.test_smart_add',
627
 
                   'bzrlib.tests.test_bad_files',
628
 
                   'bzrlib.tests.test_diff',
629
 
                   'bzrlib.tests.test_parent',
630
 
                   'bzrlib.tests.test_xml',
631
 
                   'bzrlib.tests.test_weave',
632
 
                   'bzrlib.tests.test_fetch',
633
 
                   'bzrlib.tests.test_whitebox',
 
675
                   'bzrlib.tests.test_source',
 
676
                   'bzrlib.tests.test_status',
634
677
                   'bzrlib.tests.test_store',
635
 
                   'bzrlib.tests.test_sampler',
 
678
                   'bzrlib.tests.test_testament',
 
679
                   'bzrlib.tests.test_trace',
636
680
                   'bzrlib.tests.test_transactions',
637
681
                   'bzrlib.tests.test_transport',
638
 
                   'bzrlib.tests.test_sftp',
639
 
                   'bzrlib.tests.test_graph',
 
682
                   'bzrlib.tests.test_tsort',
 
683
                   'bzrlib.tests.test_ui',
 
684
                   'bzrlib.tests.test_uncommit',
 
685
                   'bzrlib.tests.test_upgrade',
 
686
                   'bzrlib.tests.test_weave',
 
687
                   'bzrlib.tests.test_whitebox',
640
688
                   'bzrlib.tests.test_workingtree',
641
 
                   'bzrlib.tests.test_upgrade',
642
 
                   'bzrlib.tests.test_uncommit',
643
 
                   'bzrlib.tests.test_ui',
644
 
                   'bzrlib.tests.test_conflicts',
645
 
                   'bzrlib.tests.test_testament',
646
 
                   'bzrlib.tests.test_annotate',
647
 
                   'bzrlib.tests.test_revprops',
648
 
                   'bzrlib.tests.test_options',
649
 
                   'bzrlib.tests.test_http',
650
 
                   'bzrlib.tests.test_nonascii',
651
 
                   'bzrlib.tests.test_reweave',
652
 
                   'bzrlib.tests.test_tsort',
653
 
                   'bzrlib.tests.test_trace',
654
 
                   'bzrlib.tests.test_rio',
655
 
                   'bzrlib.tests.test_msgeditor',
656
 
                   'bzrlib.tests.test_selftest',
 
689
                   'bzrlib.tests.test_xml',
657
690
                   ]
658
691
 
659
692
    print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
674
707
        suite.addTest(loader.loadTestsFromModule(m))
675
708
    for m in (MODULES_TO_DOCTEST):
676
709
        suite.addTest(DocTestSuite(m))
677
 
    for p in bzrlib.plugin.all_plugins:
678
 
        if hasattr(p, 'test_suite'):
679
 
            suite.addTest(p.test_suite())
 
710
    for name, plugin in bzrlib.plugin.all_plugins().items():
 
711
        if hasattr(plugin, 'test_suite'):
 
712
            suite.addTest(plugin.test_suite())
680
713
    return suite
681
714
 
682
715