~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Martin Pool
  • Date: 2005-08-30 05:35:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050830053511-71f6b3ba8ca93827
- add new Branch.set_parent and tests

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
107
105
                                       bzrlib.commands.run_bzr, args)
108
106
        self.assertEquals(result, retcode)
109
107
        
110
 
        
111
108
    def check_inventory_shape(self, inv, shape):
112
109
        """
113
110
        Compare an inventory to a list of expected names.
146
143
        real_stdin = sys.stdin
147
144
        real_stdout = sys.stdout
148
145
        real_stderr = sys.stderr
 
146
        result = None
149
147
        try:
150
148
            sys.stdout = stdout
151
149
            sys.stderr = stderr
152
150
            sys.stdin = stdin
153
 
            return a_callable(*args, **kwargs)
 
151
            result = a_callable(*args, **kwargs)
154
152
        finally:
155
153
            sys.stdout = real_stdout
156
154
            sys.stderr = real_stderr
157
155
            sys.stdin = real_stdin
 
156
        return result
158
157
 
159
158
 
160
159
BzrTestBase = TestCase
186
185
            self.fail("contents of %s not as expected")
187
186
 
188
187
    def _make_test_root(self):
 
188
        import os
 
189
        import shutil
 
190
        import tempfile
 
191
        
189
192
        if TestCaseInTempDir.TEST_ROOT is not None:
190
193
            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
 
194
        TestCaseInTempDir.TEST_ROOT = os.path.abspath(
 
195
                                 tempfile.mkdtemp(suffix='.tmp',
 
196
                                                  prefix=self._TEST_NAME + '-',
 
197
                                                  dir=os.curdir))
 
198
    
205
199
        # make a fake bzr directory there to prevent any tests propagating
206
200
        # up onto the source directory's real branch
207
201
        os.mkdir(os.path.join(TestCaseInTempDir.TEST_ROOT, '.bzr'))
211
205
        import os
212
206
        self._make_test_root()
213
207
        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)
 
208
        self.test_dir = os.path.join(self.TEST_ROOT, self.id())
217
209
        os.mkdir(self.test_dir)
218
210
        os.chdir(self.test_dir)
219
211
        
297
289
 
298
290
 
299
291
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)
 
292
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
302
293
 
303
294
 
304
295
def test_suite():
305
 
    """Build and return TestSuite for the whole program."""
306
296
    from bzrlib.selftest.TestUtil import TestLoader, TestSuite
307
297
    import bzrlib, bzrlib.store, bzrlib.inventory, bzrlib.branch
308
298
    import bzrlib.osutils, bzrlib.commands, bzrlib.merge3, bzrlib.plugin
316
306
 
317
307
    testmod_names = \
318
308
                  ['bzrlib.selftest.MetaTestLog',
 
309
                   'bzrlib.selftest.test_parent',
319
310
                   'bzrlib.selftest.testinv',
 
311
                   'bzrlib.selftest.testfetch',
320
312
                   'bzrlib.selftest.versioning',
 
313
                   'bzrlib.selftest.whitebox',
321
314
                   'bzrlib.selftest.testmerge3',
322
315
                   'bzrlib.selftest.testhashcache',
323
316
                   'bzrlib.selftest.teststatus',
324
317
                   'bzrlib.selftest.testlog',
 
318
                   'bzrlib.selftest.blackbox',
325
319
                   'bzrlib.selftest.testrevisionnamespaces',
326
320
                   'bzrlib.selftest.testbranch',
327
 
#                   'bzrlib.selftest.testrevision',
328
 
#                   'bzrlib.selftest.test_merge_core',
 
321
                   'bzrlib.selftest.testrevision',
 
322
                   'bzrlib.selftest.test_merge_core',
329
323
                   'bzrlib.selftest.test_smart_add',
330
324
                   'bzrlib.selftest.testdiff',
331
 
#                   'bzrlib.selftest.test_parent',
332
 
                   'bzrlib.selftest.test_xml',
333
 
#                   'bzrlib.selftest.testfetch',
334
 
#                   'bzrlib.selftest.whitebox',
335
 
                   'bzrlib.selftest.teststore',
336
 
#                   'bzrlib.selftest.blackbox',
 
325
                   'bzrlib.fetch'
337
326
                   ]
338
327
 
339
328
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,