~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testsweet.py

  • Committer: Robert Collins
  • Date: 2005-08-23 05:32:41 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-20050823053241-f91c6edb3ca2ff82
turn runsuite into a smaller method and a TestSuite decorator

Show diffs side-by-side

added added

removed removed

Lines of Context:
281
281
 
282
282
 
283
283
 
284
 
def run_suite(suite, name='test', verbose=False):
285
 
    import os
286
 
    import shutil
287
 
    import time
 
284
class TestSuite(unittest.TestSuite):
 
285
    
 
286
    def __init__(self, tests=(), name='test'):
 
287
        super(TestSuite, self).__init__(tests)
 
288
        self._name = name
 
289
 
 
290
    def run(self, result):
 
291
        import os
 
292
        import shutil
 
293
        import time
 
294
        import sys
 
295
        
 
296
        _setup_test_log(self._name)
 
297
        _setup_test_dir(self._name)
 
298
        print
 
299
    
 
300
        # save stdout & stderr so there's no leakage from code-under-test
 
301
        real_stdout = sys.stdout
 
302
        real_stderr = sys.stderr
 
303
        sys.stdout = sys.stderr = TestCase.TEST_LOG
 
304
        try:
 
305
            super(TestSuite,self).run(result)
 
306
        finally:
 
307
            sys.stdout = real_stdout
 
308
            sys.stderr = real_stderr
 
309
        return result
 
310
 
 
311
def run_suite(a_suite, name='test', verbose=False):
288
312
    import sys
289
 
    
290
 
    _setup_test_log(name)
291
 
    _setup_test_dir(name)
292
 
    print
293
 
 
294
 
    # save stdout & stderr so there's no leakage from code-under-test
295
 
    real_stdout = sys.stdout
296
 
    real_stderr = sys.stderr
297
 
    sys.stdout = sys.stderr = TestCase.TEST_LOG
298
 
    try:
299
 
        if verbose:
300
 
            style = 'verbose'
301
 
        else:
302
 
            style = 'progress'
303
 
        result = _MyResult(real_stdout, style)
304
 
        suite.run(result)
305
 
    finally:
306
 
        sys.stdout = real_stdout
307
 
        sys.stderr = real_stderr
308
 
 
 
313
    suite = TestSuite((a_suite,),name)
 
314
    if verbose:
 
315
        style = 'verbose'
 
316
    else:
 
317
        style = 'progress'
 
318
    result = _MyResult(sys.stdout, style)
 
319
    suite.run(result)
309
320
    _show_results(result)
310
 
 
311
321
    return result.wasSuccessful()
312
322
 
313
323
 
314
 
 
315
324
def _setup_test_log(name):
316
325
    import time
317
326
    import os