~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Martin Pool
  • Date: 2005-09-16 09:19:54 UTC
  • Revision ID: mbp@sourcefrog.net-20050916091954-aee6d7be00db6354
- more docs in commit code

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
23
24
import subprocess
 
25
import shutil
24
26
 
25
 
from testsweet import run_suite
 
27
import testsweet
26
28
import bzrlib.commands
27
29
 
28
30
import bzrlib.trace
66
68
 
67
69
        hdlr = logging.StreamHandler(self._log_file)
68
70
        hdlr.setLevel(logging.DEBUG)
69
 
        hdlr.setFormatter(logging.Formatter('%(levelname)4.4s  %(message)s'))
 
71
        hdlr.setFormatter(logging.Formatter('%(levelname)8s  %(message)s'))
70
72
        logging.getLogger('').addHandler(hdlr)
71
73
        logging.getLogger('').setLevel(logging.DEBUG)
72
74
        self._log_hdlr = hdlr
107
109
        
108
110
        
109
111
    def check_inventory_shape(self, inv, shape):
110
 
        """
111
 
        Compare an inventory to a list of expected names.
 
112
        """Compare an inventory to a list of expected names.
112
113
 
113
114
        Fail if they are not precisely equal.
114
115
        """
184
185
            self.fail("contents of %s not as expected")
185
186
 
186
187
    def _make_test_root(self):
187
 
        import os
188
 
        import shutil
189
 
        import tempfile
190
 
        
191
188
        if TestCaseInTempDir.TEST_ROOT is not None:
192
189
            return
193
 
        TestCaseInTempDir.TEST_ROOT = os.path.abspath(
194
 
                                 tempfile.mkdtemp(suffix='.tmp',
195
 
                                                  prefix=self._TEST_NAME + '-',
196
 
                                                  dir=os.curdir))
197
 
    
 
190
        i = 0
 
191
        while True:
 
192
            root = 'test%04d.tmp' % i
 
193
            try:
 
194
                os.mkdir(root)
 
195
            except OSError, e:
 
196
                if e.errno == errno.EEXIST:
 
197
                    i += 1
 
198
                    continue
 
199
                else:
 
200
                    raise
 
201
            # successfully created
 
202
            TestCaseInTempDir.TEST_ROOT = os.path.abspath(root)
 
203
            break
198
204
        # make a fake bzr directory there to prevent any tests propagating
199
205
        # up onto the source directory's real branch
200
206
        os.mkdir(os.path.join(TestCaseInTempDir.TEST_ROOT, '.bzr'))
204
210
        import os
205
211
        self._make_test_root()
206
212
        self._currentdir = os.getcwdu()
207
 
        self.test_dir = os.path.join(self.TEST_ROOT, self.id())
 
213
        short_id = self.id().replace('bzrlib.selftest.', '') \
 
214
                   .replace('__main__.', '')
 
215
        self.test_dir = os.path.join(self.TEST_ROOT, short_id)
208
216
        os.mkdir(self.test_dir)
209
217
        os.chdir(self.test_dir)
210
218
        
288
296
 
289
297
 
290
298
def selftest(verbose=False, pattern=".*"):
291
 
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
 
299
    """Run the whole test suite under the enhanced runner"""
 
300
    return testsweet.run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
292
301
 
293
302
 
294
303
def test_suite():
 
304
    """Build and return TestSuite for the whole program."""
295
305
    from bzrlib.selftest.TestUtil import TestLoader, TestSuite
296
306
    import bzrlib, bzrlib.store, bzrlib.inventory, bzrlib.branch
297
307
    import bzrlib.osutils, bzrlib.commands, bzrlib.merge3, bzrlib.plugin
305
315
 
306
316
    testmod_names = \
307
317
                  ['bzrlib.selftest.MetaTestLog',
308
 
                   'bzrlib.selftest.test_parent',
309
318
                   'bzrlib.selftest.testinv',
310
 
                   'bzrlib.selftest.testfetch',
 
319
                   'bzrlib.selftest.test_commit',
311
320
                   'bzrlib.selftest.versioning',
312
 
                   'bzrlib.selftest.whitebox',
313
321
                   'bzrlib.selftest.testmerge3',
314
322
                   'bzrlib.selftest.testhashcache',
315
323
                   'bzrlib.selftest.teststatus',
316
324
                   'bzrlib.selftest.testlog',
317
 
                   'bzrlib.selftest.blackbox',
318
325
                   'bzrlib.selftest.testrevisionnamespaces',
319
326
                   'bzrlib.selftest.testbranch',
320
327
                   'bzrlib.selftest.testrevision',
321
328
                   'bzrlib.selftest.test_merge_core',
322
329
                   'bzrlib.selftest.test_smart_add',
323
330
                   'bzrlib.selftest.testdiff',
324
 
                   'bzrlib.fetch',
 
331
                   'bzrlib.selftest.test_parent',
 
332
                   'bzrlib.selftest.test_xml',
 
333
                   'bzrlib.selftest.test_weave',
 
334
                   'bzrlib.selftest.testfetch',
 
335
                   'bzrlib.selftest.whitebox',
325
336
                   'bzrlib.selftest.teststore',
 
337
                   'bzrlib.selftest.blackbox',
326
338
                   ]
327
339
 
328
340
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,