~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2013, 2015, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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)
1359
1369
            % (message,
1360
1370
               pprint.pformat(a), pprint.pformat(b)))
1361
1371
 
 
1372
    # FIXME: This is deprecated in unittest2 but plugins may still use it so we
 
1373
    # need a deprecation period for them -- vila 2016-02-01
1362
1374
    assertEquals = assertEqual
1363
1375
 
1364
1376
    def assertEqualDiff(self, a, b, message=None):
1367
1379
        This is intended for use with multi-line strings where it can
1368
1380
        be hard to find the differences by eye.
1369
1381
        """
1370
 
        # TODO: perhaps override assertEquals to call this for strings?
 
1382
        # TODO: perhaps override assertEqual to call this for strings?
1371
1383
        if a == b:
1372
1384
            return
1373
1385
        if message is None:
2040
2052
        if err:
2041
2053
            self.log('errors:\n%r', err)
2042
2054
        if retcode is not None:
2043
 
            self.assertEquals(retcode, result,
 
2055
            self.assertEqual(retcode, result,
2044
2056
                              message='Unexpected return code')
2045
2057
        return result, out, err
2046
2058