~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:44:54 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-20050823064454-830ef7d426be03f6
move log and temp dir setup foo into the TestSuite we use

Show diffs side-by-side

added added

removed removed

Lines of Context:
302
302
        import time
303
303
        import sys
304
304
        
305
 
        _setup_test_log(self._name)
306
 
        _setup_test_dir(self._name)
 
305
        self._setup_test_log()
 
306
        self._setup_test_dir()
307
307
        print
308
308
    
309
309
        # save stdout & stderr so there's no leakage from code-under-test
317
317
            sys.stderr = real_stderr
318
318
        return result
319
319
 
 
320
    def _setup_test_log(self):
 
321
        import time
 
322
        import os
 
323
        
 
324
        log_filename = os.path.abspath(self._name + '.log')
 
325
        # line buffered
 
326
        TestCase.TEST_LOG = open(log_filename, 'wt', buffering=1)
 
327
    
 
328
        print >>TestCase.TEST_LOG, "tests run at " + time.ctime()
 
329
        print '%-30s %s' % ('test log', log_filename)
 
330
 
 
331
    def _setup_test_dir(self):
 
332
        import os
 
333
        import shutil
 
334
        
 
335
        TestCase.ORIG_DIR = os.getcwdu()
 
336
        TestCase.TEST_ROOT = os.path.abspath(self._name + '.tmp')
 
337
    
 
338
        print '%-30s %s' % ('running tests in', TestCase.TEST_ROOT)
 
339
    
 
340
        if os.path.exists(TestCase.TEST_ROOT):
 
341
            shutil.rmtree(TestCase.TEST_ROOT)
 
342
        os.mkdir(TestCase.TEST_ROOT)
 
343
        os.chdir(TestCase.TEST_ROOT)
 
344
    
 
345
        # make a fake bzr directory there to prevent any tests propagating
 
346
        # up onto the source directory's real branch
 
347
        os.mkdir(os.path.join(TestCase.TEST_ROOT, '.bzr'))
 
348
 
 
349
 
320
350
class TextTestRunner(unittest.TextTestRunner):
321
351
 
322
 
    def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1):
 
352
    def __init__(self, stream=sys.stderr, descriptions=1, verbosity=0, style='progress'):
323
353
        super(TextTestRunner, self).__init__(stream, descriptions, verbosity)
 
354
        self.style = style
324
355
 
325
356
    def _makeResult(self):
326
 
        return _MyResult(self.stream, self.verbosity)
 
357
        return _MyResult(self.stream, self.style)
327
358
 
328
359
    # If we want the old 4 line summary output (count, 0 failures, 0 errors)
329
360
    # we can override run() too.
335
366
        style = 'verbose'
336
367
    else:
337
368
        style = 'progress'
338
 
    runner = TextTestRunner(stream=sys.stdout, verbosity=style)
 
369
    runner = TextTestRunner(stream=sys.stdout, style=style)
339
370
    result = runner.run(suite)
340
371
    return result.wasSuccessful()
341
 
 
342
 
 
343
 
def _setup_test_log(name):
344
 
    import time
345
 
    import os
346
 
    
347
 
    log_filename = os.path.abspath(name + '.log')
348
 
    TestCase.TEST_LOG = open(log_filename, 'wt', buffering=1) # line buffered
349
 
 
350
 
    print >>TestCase.TEST_LOG, "tests run at " + time.ctime()
351
 
    print '%-30s %s' % ('test log', log_filename)
352
 
 
353
 
 
354
 
def _setup_test_dir(name):
355
 
    import os
356
 
    import shutil
357
 
    
358
 
    TestCase.ORIG_DIR = os.getcwdu()
359
 
    TestCase.TEST_ROOT = os.path.abspath(name + '.tmp')
360
 
 
361
 
    print '%-30s %s' % ('running tests in', TestCase.TEST_ROOT)
362
 
 
363
 
    if os.path.exists(TestCase.TEST_ROOT):
364
 
        shutil.rmtree(TestCase.TEST_ROOT)
365
 
    os.mkdir(TestCase.TEST_ROOT)
366
 
    os.chdir(TestCase.TEST_ROOT)
367
 
 
368
 
    # make a fake bzr directory there to prevent any tests propagating
369
 
    # up onto the source directory's real branch
370
 
    os.mkdir(os.path.join(TestCase.TEST_ROOT, '.bzr'))