/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
262
262
        self.stream.flush()
263
263
        # seems best to treat this as success from point-of-view of unittest
264
264
        # -- it actually does nothing so it barely matters :)
265
 
        unittest.TestResult.addSuccess(self, test)
 
265
        try:
 
266
            test.tearDown()
 
267
        except KeyboardInterrupt:
 
268
            raise
 
269
        except:
 
270
            self.addError(test, test.__exc_info())
 
271
        else:
 
272
            unittest.TestResult.addSuccess(self, test)
266
273
 
267
274
    def printErrorList(self, flavour, errors):
268
275
        for test, err in errors:
552
559
 
553
560
        Read contents into memory, close, and delete.
554
561
        """
 
562
        if self._log_file is None:
 
563
            return
555
564
        bzrlib.trace.disable_test_log(self._log_nonce)
556
565
        self._log_file.seek(0)
557
566
        self._log_contents = self._log_file.read()
739
748
            encoding = bzrlib.user_encoding
740
749
        return self.run_bzr(*args, **kwargs)[0].decode(encoding)
741
750
 
 
751
    def run_bzr_error(self, error_regexes, *args, **kwargs):
 
752
        """Run bzr, and check that stderr contains the supplied regexes
 
753
        
 
754
        :param error_regexes: Sequence of regular expressions which 
 
755
            must each be found in the error output. The relative ordering
 
756
            is not enforced.
 
757
        :param args: command-line arguments for bzr
 
758
        :param kwargs: Keyword arguments which are interpreted by run_bzr
 
759
            This function changes the default value of retcode to be 3,
 
760
            since in most cases this is run when you expect bzr to fail.
 
761
        :return: (out, err) The actual output of running the command (in case you
 
762
                 want to do more inspection)
 
763
 
 
764
        Examples of use:
 
765
            # Make sure that commit is failing because there is nothing to do
 
766
            self.run_bzr_error(['no changes to commit'],
 
767
                               'commit', '-m', 'my commit comment')
 
768
            # Make sure --strict is handling an unknown file, rather than
 
769
            # giving us the 'nothing to do' error
 
770
            self.build_tree(['unknown'])
 
771
            self.run_bzr_error(['Commit refused because there are unknown files'],
 
772
                               'commit', '--strict', '-m', 'my commit comment')
 
773
        """
 
774
        kwargs.setdefault('retcode', 3)
 
775
        out, err = self.run_bzr(*args, **kwargs)
 
776
        for regex in error_regexes:
 
777
            self.assertContainsRe(err, regex)
 
778
        return out, err
 
779
 
742
780
    def run_bzr_subprocess(self, *args, **kwargs):
743
781
        """Run bzr in a subprocess for testing.
744
782