~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Robert Collins
  • Date: 2005-09-14 09:01:06 UTC
  • mto: (1185.1.12)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: robertc@robertcollins.net-20050914090106-50ddfad9500a8ae9
make diff lsdiff/filterdiff friendly

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import tempfile
21
21
import os
22
22
import sys
23
 
import errno
24
23
import subprocess
25
 
import shutil
26
24
 
27
 
import testsweet
 
25
from testsweet import run_suite
28
26
import bzrlib.commands
29
27
 
30
28
import bzrlib.trace
68
66
 
69
67
        hdlr = logging.StreamHandler(self._log_file)
70
68
        hdlr.setLevel(logging.DEBUG)
71
 
        hdlr.setFormatter(logging.Formatter('%(levelname)8s  %(message)s'))
 
69
        hdlr.setFormatter(logging.Formatter('%(levelname)4.4s  %(message)s'))
72
70
        logging.getLogger('').addHandler(hdlr)
73
71
        logging.getLogger('').setLevel(logging.DEBUG)
74
72
        self._log_hdlr = hdlr
76
74
        
77
75
        self._log_file_name = name
78
76
 
 
77
    def run(self, result):
 
78
        self.apply_redirected(None, None, None,
 
79
                              unittest.TestCase.run, self, result)
79
80
        
80
81
    def tearDown(self):
81
82
        logging.getLogger('').removeHandler(self._log_hdlr)
140
141
        if stdin is None:
141
142
            stdin = StringIO("")
142
143
        if stdout is None:
143
 
            stdout = self._log_file
 
144
            if hasattr(self, "_log_file"):
 
145
                stdout = self._log_file
 
146
            else:
 
147
                stdout = StringIO()
144
148
        if stderr is None:
145
 
            stderr = self._log_file
 
149
            if hasattr(self, "_log_file"):
 
150
                stderr = self._log_file
 
151
            else:
 
152
                stderr = StringIO()
146
153
        real_stdin = sys.stdin
147
154
        real_stdout = sys.stdout
148
155
        real_stderr = sys.stderr
186
193
            self.fail("contents of %s not as expected")
187
194
 
188
195
    def _make_test_root(self):
 
196
        import os
 
197
        import shutil
 
198
        import tempfile
 
199
        
189
200
        if TestCaseInTempDir.TEST_ROOT is not None:
190
201
            return
191
 
        i = 0
192
 
        while True:
193
 
            root = 'test%04d.tmp' % i
194
 
            try:
195
 
                os.mkdir(root)
196
 
            except OSError, e:
197
 
                if e.errno == errno.EEXIST:
198
 
                    i += 1
199
 
                    continue
200
 
                else:
201
 
                    raise
202
 
            # successfully created
203
 
            TestCaseInTempDir.TEST_ROOT = os.path.abspath(root)
204
 
            break
 
202
        TestCaseInTempDir.TEST_ROOT = os.path.abspath(
 
203
                                 tempfile.mkdtemp(suffix='.tmp',
 
204
                                                  prefix=self._TEST_NAME + '-',
 
205
                                                  dir=os.curdir))
 
206
    
205
207
        # make a fake bzr directory there to prevent any tests propagating
206
208
        # up onto the source directory's real branch
207
209
        os.mkdir(os.path.join(TestCaseInTempDir.TEST_ROOT, '.bzr'))
211
213
        import os
212
214
        self._make_test_root()
213
215
        self._currentdir = os.getcwdu()
214
 
        short_id = self.id().replace('bzrlib.selftest.', '') \
215
 
                   .replace('__main__.', '')
216
 
        self.test_dir = os.path.join(self.TEST_ROOT, short_id)
 
216
        self.test_dir = os.path.join(self.TEST_ROOT, self.id())
217
217
        os.mkdir(self.test_dir)
218
218
        os.chdir(self.test_dir)
219
219
        
297
297
 
298
298
 
299
299
def selftest(verbose=False, pattern=".*"):
300
 
    """Run the whole test suite under the enhanced runner"""
301
 
    return testsweet.run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
 
300
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
302
301
 
303
302
 
304
303
def test_suite():
305
 
    """Build and return TestSuite for the whole program."""
306
304
    from bzrlib.selftest.TestUtil import TestLoader, TestSuite
307
305
    import bzrlib, bzrlib.store, bzrlib.inventory, bzrlib.branch
308
306
    import bzrlib.osutils, bzrlib.commands, bzrlib.merge3, bzrlib.plugin
316
314
 
317
315
    testmod_names = \
318
316
                  ['bzrlib.selftest.MetaTestLog',
 
317
                   'bzrlib.selftest.test_parent',
319
318
                   'bzrlib.selftest.testinv',
 
319
                   'bzrlib.selftest.testfetch',
320
320
                   'bzrlib.selftest.versioning',
 
321
                   'bzrlib.selftest.whitebox',
321
322
                   'bzrlib.selftest.testmerge3',
322
323
                   'bzrlib.selftest.testhashcache',
323
324
                   'bzrlib.selftest.teststatus',
324
325
                   'bzrlib.selftest.testlog',
 
326
                   'bzrlib.selftest.blackbox',
325
327
                   'bzrlib.selftest.testrevisionnamespaces',
326
328
                   'bzrlib.selftest.testbranch',
327
 
#                   'bzrlib.selftest.testrevision',
328
 
#                   'bzrlib.selftest.test_merge_core',
 
329
                   'bzrlib.selftest.testrevision',
 
330
                   'bzrlib.selftest.test_merge_core',
329
331
                   'bzrlib.selftest.test_smart_add',
330
332
                   'bzrlib.selftest.testdiff',
331
 
#                   'bzrlib.selftest.test_parent',
332
333
                   'bzrlib.selftest.test_xml',
333
 
#                   'bzrlib.selftest.testfetch',
334
 
#                   'bzrlib.selftest.whitebox',
 
334
                   'bzrlib.fetch',
335
335
                   'bzrlib.selftest.teststore',
336
 
#                   'bzrlib.selftest.blackbox',
 
336
                   'bzrlib.selftest.testgraph',
337
337
                   ]
338
338
 
339
339
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,