~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Andrew Bennetts
  • Date: 2009-12-03 05:57:41 UTC
  • mfrom: (4857 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4869.
  • Revision ID: andrew.bennetts@canonical.com-20091203055741-vmmg0fmjgjw2pwvu
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1524
1524
            'BZR_PROGRESS_BAR': None,
1525
1525
            'BZR_LOG': None,
1526
1526
            'BZR_PLUGIN_PATH': None,
 
1527
            'BZR_CONCURRENCY': None,
1527
1528
            # Make sure that any text ui tests are consistent regardless of
1528
1529
            # the environment the test case is run in; you may want tests that
1529
1530
            # test other combinations.  'dumb' is a reasonable guess for tests
1836
1837
            os.chdir(working_dir)
1837
1838
 
1838
1839
        try:
1839
 
            result = self.apply_redirected(ui.ui_factory.stdin,
1840
 
                stdout, stderr,
1841
 
                bzrlib.commands.run_bzr_catch_user_errors,
1842
 
                args)
 
1840
            try:
 
1841
                result = self.apply_redirected(ui.ui_factory.stdin,
 
1842
                    stdout, stderr,
 
1843
                    bzrlib.commands.run_bzr_catch_user_errors,
 
1844
                    args)
 
1845
            except KeyboardInterrupt:
 
1846
                # Reraise KeyboardInterrupt with contents of redirected stdout
 
1847
                # and stderr as arguments, for tests which are interested in
 
1848
                # stdout and stderr and are expecting the exception.
 
1849
                out = stdout.getvalue()
 
1850
                err = stderr.getvalue()
 
1851
                if out:
 
1852
                    self.log('output:\n%r', out)
 
1853
                if err:
 
1854
                    self.log('errors:\n%r', err)
 
1855
                raise KeyboardInterrupt(out, err)
1843
1856
        finally:
1844
1857
            logger.removeHandler(handler)
1845
1858
            ui.ui_factory = old_ui_factory
2393
2406
            # recreate a new one or all the followng tests will fail.
2394
2407
            # If you need to inspect its content uncomment the following line
2395
2408
            # import pdb; pdb.set_trace()
2396
 
            _rmtree_temp_dir(root + '/.bzr')
 
2409
            _rmtree_temp_dir(root + '/.bzr', test_id=self.id())
2397
2410
            self._create_safety_net()
2398
2411
            raise AssertionError('%s/.bzr should not be modified' % root)
2399
2412
 
2591
2604
 
2592
2605
    def deleteTestDir(self):
2593
2606
        os.chdir(TestCaseWithMemoryTransport.TEST_ROOT)
2594
 
        _rmtree_temp_dir(self.test_base_dir)
 
2607
        _rmtree_temp_dir(self.test_base_dir, test_id=self.id())
2595
2608
 
2596
2609
    def build_tree(self, shape, line_endings='binary', transport=None):
2597
2610
        """Build a test tree according to a pattern.
4119
4132
    return new_test
4120
4133
 
4121
4134
 
4122
 
def _rmtree_temp_dir(dirname):
 
4135
def _rmtree_temp_dir(dirname, test_id=None):
4123
4136
    # If LANG=C we probably have created some bogus paths
4124
4137
    # which rmtree(unicode) will fail to delete
4125
4138
    # so make sure we are using rmtree(str) to delete everything
4137
4150
        # We don't want to fail here because some useful display will be lost
4138
4151
        # otherwise. Polluting the tmp dir is bad, but not giving all the
4139
4152
        # possible info to the test runner is even worse.
 
4153
        if test_id != None:
 
4154
            ui.ui_factory.clear_term()
 
4155
            sys.stderr.write('While running: %s\n' % (test_id,))
4140
4156
        sys.stderr.write('Unable to remove testing dir %s\n%s'
4141
4157
                         % (os.path.basename(dirname), e))
4142
4158