~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-29 10:57:01 UTC
  • mfrom: (1092.1.41)
  • Revision ID: mbp@sourcefrog.net-20050829105701-7aaa81ecf1bfee05
- merge in merge improvements and additional tests 
  from aaron and lifeless

robertc@robertcollins.net-20050825131100-85772edabc817481

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import unittest
20
20
import tempfile
21
21
import os
 
22
import sys
22
23
 
23
24
from testsweet import run_suite
24
 
 
25
25
import bzrlib.commands
 
26
 
26
27
import bzrlib.trace
 
28
import bzrlib.fetch
27
29
 
28
30
MODULES_TO_TEST = []
29
31
MODULES_TO_DOCTEST = []
95
97
        that is slower, harder to debug, and generally not necessary.
96
98
        """
97
99
        retcode = kwargs.get('retcode', 0)
98
 
        self.assertEquals(bzrlib.commands.run_bzr(args), retcode)
 
100
        result = self.apply_redirected(None, None, None,
 
101
                                       bzrlib.commands.run_bzr, args)
 
102
        self.assertEquals(result, retcode)
99
103
        
100
104
    def check_inventory_shape(self, inv, shape):
101
105
        """
246
250
                f.close()
247
251
                
248
252
 
 
253
    def apply_redirected(self, stdin=None, stdout=None, stderr=None,
 
254
                         a_callable=None, *args, **kwargs):
 
255
        """Call callable with redirected std io pipes.
 
256
 
 
257
        Returns the return code."""
 
258
        from StringIO import StringIO
 
259
        if not callable(a_callable):
 
260
            raise ValueError("a_callable must be callable.")
 
261
        if stdin is None:
 
262
            stdin = StringIO("")
 
263
        if stdout is None:
 
264
            stdout = self._log_file
 
265
        if stderr is None:
 
266
            stderr = self._log_file
 
267
        real_stdin = sys.stdin
 
268
        real_stdout = sys.stdout
 
269
        real_stderr = sys.stderr
 
270
        result = None
 
271
        try:
 
272
            sys.stdout = stdout
 
273
            sys.stderr = stderr
 
274
            sys.stdin = stdin
 
275
            result = a_callable(*args, **kwargs)
 
276
        finally:
 
277
            sys.stdout = real_stdout
 
278
            sys.stderr = real_stderr
 
279
            sys.stdin = real_stdin
 
280
        return result
 
281
 
 
282
 
 
283
InTempDir = FunctionalTestCase
 
284
 
249
285
 
250
286
class MetaTestLog(TestCase):
251
287
    def test_logging(self):
256
292
        ##assert 0
257
293
 
258
294
 
259
 
InTempDir = FunctionalTestCase
260
 
 
261
 
 
262
 
def selftest(verbose=False):
263
 
    from unittest import TestLoader, TestSuite
 
295
def selftest(verbose=False, pattern=".*"):
 
296
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
 
297
 
 
298
 
 
299
def test_suite():
 
300
    from bzrlib.selftest.TestUtil import TestLoader, TestSuite
264
301
    import bzrlib, bzrlib.store, bzrlib.inventory, bzrlib.branch
265
302
    import bzrlib.osutils, bzrlib.commands, bzrlib.merge3, bzrlib.plugin
266
303
    from doctest import DocTestSuite
285
322
                   'bzrlib.selftest.testrevisionnamespaces',
286
323
                   'bzrlib.selftest.testbranch',
287
324
                   'bzrlib.selftest.testrevision',
288
 
                   'bzrlib.merge_core',
 
325
                   'bzrlib.selftest.test_merge_core',
 
326
                   'bzrlib.selftest.test_smart_add',
289
327
                   'bzrlib.selftest.testdiff',
 
328
                   'bzrlib.fetch'
290
329
                   ]
291
330
 
292
331
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,
296
335
 
297
336
    TestCase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
298
337
    print '%-30s %s' % ('bzr binary', TestCase.BZRPATH)
299
 
 
300
338
    print
301
 
 
302
339
    suite = TestSuite()
303
 
 
304
340
    suite.addTest(TestLoader().loadTestsFromNames(testmod_names))
305
 
 
306
341
    for m in MODULES_TO_TEST:
307
342
         suite.addTest(TestLoader().loadTestsFromModule(m))
308
 
 
309
343
    for m in (MODULES_TO_DOCTEST):
310
344
        suite.addTest(DocTestSuite(m))
311
 
 
312
345
    for p in bzrlib.plugin.all_plugins:
313
346
        if hasattr(p, 'test_suite'):
314
347
            suite.addTest(p.test_suite())
315
 
 
316
 
    import bzrlib.merge_core
317
 
    suite.addTest(unittest.makeSuite(bzrlib.merge_core.MergeTest, 'test_'))
318
 
 
319
 
    return run_suite(suite, 'testbzr', verbose=verbose)
320
 
 
321
 
 
 
348
    return suite
322
349