~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2015-11-08 12:27:50 UTC
  • mto: This revision was merged to the branch mainline in revision 6607.
  • Revision ID: jelmer@jelmer.uk-20151108122750-m2hcegf5af28mkp4
Add local copy of _delta_to_float from testtools, rather than
relying on the signature and behaviour of a private method to stay the same.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import errno
33
33
import itertools
34
34
import logging
 
35
import math
35
36
import os
36
37
import platform
37
38
import pprint
359
360
            return float(''.join(details['benchtime'].iter_bytes()))
360
361
        return getattr(testCase, "_benchtime", None)
361
362
 
 
363
    def _delta_to_float(self, a_timedelta, precision):
 
364
        # This calls ceiling to ensure that the most pessimistic view of time
 
365
        # taken is shown (rather than leaving it to the Python %f operator
 
366
        # to decide whether to round/floor/ceiling. This was added when we
 
367
        # had pyp3 test failures that suggest a floor was happening.
 
368
        shift = 10 ** precision
 
369
        return math.ceil((a_timedelta.days * 86400.0 + a_timedelta.seconds +
 
370
            a_timedelta.microseconds / 1000000.0) * shift) / shift
 
371
 
362
372
    def _elapsedTestTimeString(self):
363
373
        """Return a time string for the overall time the current test has taken."""
364
374
        return self._formatTime(self._delta_to_float(
365
 
            self._now() - self._start_datetime))
 
375
            self._now() - self._start_datetime), 3)
366
376
 
367
377
    def _testTimeString(self, testCase):
368
378
        benchmark_time = self._extractBenchmarkTime(testCase)