/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2010-10-13 08:01:36 UTC
  • mfrom: (5447.5.1 config-read)
  • mto: This revision was merged to the branch mainline in revision 5499.
  • Revision ID: v.ladeuil+lp@free.fr-20101013080136-7o5qbbwgxhgncsj8
Merge config-read into config-modify

Show diffs side-by-side

added added

removed removed

Lines of Context:
195
195
        self._strict = strict
196
196
        self._first_thread_leaker_id = None
197
197
        self._tests_leaking_threads_count = 0
 
198
        self._traceback_from_test = None
198
199
 
199
200
    def stopTestRun(self):
200
201
        run = self.testsRun
260
261
 
261
262
    def _elapsedTestTimeString(self):
262
263
        """Return a time string for the overall time the current test has taken."""
263
 
        return self._formatTime(time.time() - self._start_time)
 
264
        return self._formatTime(self._delta_to_float(
 
265
            self._now() - self._start_datetime))
264
266
 
265
267
    def _testTimeString(self, testCase):
266
268
        benchmark_time = self._extractBenchmarkTime(testCase)
280
282
        what = re.sub(r'^bzrlib\.tests\.', '', what)
281
283
        return what
282
284
 
 
285
    # GZ 2010-10-04: Cloned tests may end up harmlessly calling this method
 
286
    #                multiple times in a row, because the handler is added for
 
287
    #                each test but the container list is shared between cases.
 
288
    #                See lp:498869 lp:625574 and lp:637725 for background.
 
289
    def _record_traceback_from_test(self, exc_info):
 
290
        """Store the traceback from passed exc_info tuple till"""
 
291
        self._traceback_from_test = exc_info[2]
 
292
 
283
293
    def startTest(self, test):
284
294
        super(ExtendedTestResult, self).startTest(test)
285
295
        if self.count == 0:
288
298
        self.report_test_start(test)
289
299
        test.number = self.count
290
300
        self._recordTestStartTime()
 
301
        # Make testtools cases give us the real traceback on failure
 
302
        addOnException = getattr(test, "addOnException", None)
 
303
        if addOnException is not None:
 
304
            addOnException(self._record_traceback_from_test)
291
305
        # Only check for thread leaks if the test case supports cleanups
292
306
        addCleanup = getattr(test, "addCleanup", None)
293
307
        if addCleanup is not None:
297
311
        self.report_tests_starting()
298
312
        self._active_threads = threading.enumerate()
299
313
 
 
314
    def stopTest(self, test):
 
315
        self._traceback_from_test = None
 
316
 
300
317
    def _check_leaked_threads(self, test):
301
318
        """See if any threads have leaked since last call
302
319
 
315
332
 
316
333
    def _recordTestStartTime(self):
317
334
        """Record that a test has started."""
318
 
        self._start_time = time.time()
 
335
        self._start_datetime = self._now()
319
336
 
320
337
    def addError(self, test, err):
321
338
        """Tell result that test finished with an error.
323
340
        Called from the TestCase run() method when the test
324
341
        fails with an unexpected error.
325
342
        """
326
 
        self._post_mortem()
 
343
        self._post_mortem(self._traceback_from_test)
327
344
        super(ExtendedTestResult, self).addError(test, err)
328
345
        self.error_count += 1
329
346
        self.report_error(test, err)
336
353
        Called from the TestCase run() method when the test
337
354
        fails because e.g. an assert() method failed.
338
355
        """
339
 
        self._post_mortem()
 
356
        self._post_mortem(self._traceback_from_test)
340
357
        super(ExtendedTestResult, self).addFailure(test, err)
341
358
        self.failure_count += 1
342
359
        self.report_failure(test, err)
384
401
        self.not_applicable_count += 1
385
402
        self.report_not_applicable(test, reason)
386
403
 
387
 
    def _post_mortem(self):
 
404
    def _post_mortem(self, tb=None):
388
405
        """Start a PDB post mortem session."""
389
406
        if os.environ.get('BZR_TEST_PDB', None):
390
 
            import pdb;pdb.post_mortem()
 
407
            import pdb
 
408
            pdb.post_mortem(tb)
391
409
 
392
410
    def progress(self, offset, whence):
393
411
        """The test is adjusting the count of tests to run."""
840
858
        self._track_transports()
841
859
        self._track_locks()
842
860
        self._clear_debug_flags()
 
861
        # Isolate global verbosity level, to make sure it's reproducible
 
862
        # between tests.  We should get rid of this altogether: bug 656694. --
 
863
        # mbp 20101008
 
864
        self.overrideAttr(bzrlib.trace, '_verbosity_level', 0)
843
865
 
844
866
    def debug(self):
845
867
        # debug a frame up.
984
1006
            try:
985
1007
                workingtree.WorkingTree.open(path)
986
1008
            except (errors.NotBranchError, errors.NoWorkingTree):
987
 
                return
 
1009
                raise TestSkipped('Needs a working tree of bzr sources')
988
1010
        finally:
989
1011
            self.enable_directory_isolation()
990
1012
 
3787
3809
        'bzrlib.tests.test_rio',
3788
3810
        'bzrlib.tests.test_rules',
3789
3811
        'bzrlib.tests.test_sampler',
 
3812
        'bzrlib.tests.test_scenarios',
3790
3813
        'bzrlib.tests.test_script',
3791
3814
        'bzrlib.tests.test_selftest',
3792
3815
        'bzrlib.tests.test_serializer',
3860
3883
        'bzrlib.tests',
3861
3884
        'bzrlib.tests.fixtures',
3862
3885
        'bzrlib.timestamp',
 
3886
        'bzrlib.transport.http',
3863
3887
        'bzrlib.version_info_formats.format_custom',
3864
3888
        ]
3865
3889
 
3968
3992
    return suite
3969
3993
 
3970
3994
 
3971
 
def multiply_scenarios(scenarios_left, scenarios_right):
 
3995
def multiply_scenarios(*scenarios):
 
3996
    """Multiply two or more iterables of scenarios.
 
3997
 
 
3998
    It is safe to pass scenario generators or iterators.
 
3999
 
 
4000
    :returns: A list of compound scenarios: the cross-product of all 
 
4001
        scenarios, with the names concatenated and the parameters
 
4002
        merged together.
 
4003
    """
 
4004
    return reduce(_multiply_two_scenarios, map(list, scenarios))
 
4005
 
 
4006
 
 
4007
def _multiply_two_scenarios(scenarios_left, scenarios_right):
3972
4008
    """Multiply two sets of scenarios.
3973
4009
 
3974
4010
    :returns: the cartesian product of the two sets of scenarios, that is