~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testsweet.py

  • Committer: Robert Collins
  • Date: 2005-08-23 06:52:09 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050823065209-81cd5962c401751b
move io redirection into each test case from the global runner

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
    pass
51
51
 
52
52
 
53
 
 
54
53
class TestSkipped(Exception):
55
54
    """Indicates that a test was intentionally skipped, rather than failing."""
56
55
    # XXX: Not used yet
74
73
 
75
74
    def setUp(self):
76
75
        super(TestCase, self).setUp()
 
76
        # save stdout & stderr so there's no leakage from code-under-test
 
77
        self.real_stdout = sys.stdout
 
78
        self.real_stderr = sys.stderr
 
79
        sys.stdout = sys.stderr = TestCase.TEST_LOG
77
80
        self.log("%s setup" % self.id())
78
81
 
79
 
 
80
82
    def tearDown(self):
81
 
        super(TestCase, self).tearDown()
 
83
        sys.stdout = self.real_stdout
 
84
        sys.stderr = self.real_stderr
82
85
        self.log("%s teardown" % self.id())
83
86
        self.log('')
84
 
 
 
87
        super(TestCase, self).tearDown()
85
88
 
86
89
    def formcmd(self, cmd):
87
90
        if isinstance(cmd, basestring):
215
218
class InTempDir(TestCase):
216
219
    """Base class for tests run in a temporary branch."""
217
220
    def setUp(self):
 
221
        super(InTempDir, self).setUp()
218
222
        import os
219
223
        self.test_dir = os.path.join(self.TEST_ROOT, self.__class__.__name__)
220
224
        os.mkdir(self.test_dir)
223
227
    def tearDown(self):
224
228
        import os
225
229
        os.chdir(self.TEST_ROOT)
 
230
        super(InTempDir, self).tearDown()
226
231
 
227
232
 
228
233
class _MyResult(unittest._TextTestResult):
244
249
        # python2.3 has the bad habit of just "runit" for doctests
245
250
        if what == 'runit':
246
251
            what = test.shortDescription()
247
 
        
248
252
        if self.style == 'verbose':
249
253
            print >>self.out, '%-60.60s' % what,
250
254
            self.out.flush()
300
304
        import os
301
305
        import shutil
302
306
        import time
303
 
        import sys
304
307
        
305
308
        self._setup_test_log()
306
309
        self._setup_test_dir()
307
310
        print
308
311
    
309
 
        # save stdout & stderr so there's no leakage from code-under-test
310
 
        real_stdout = sys.stdout
311
 
        real_stderr = sys.stderr
312
 
        sys.stdout = sys.stderr = TestCase.TEST_LOG
313
 
        try:
314
 
            super(TestSuite,self).run(result)
315
 
        finally:
316
 
            sys.stdout = real_stdout
317
 
            sys.stderr = real_stderr
318
 
        return result
 
312
        return super(TestSuite,self).run(result)
319
313
 
320
314
    def _setup_test_log(self):
321
315
        import time