~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-15 00:31:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2050.
  • Revision ID: john@arbash-meinel.com-20060915003147-b8b8c95f788ec272
create a helper for formatting a time delta

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import socket
22
22
import stat
23
23
import sys
 
24
import time
24
25
 
25
26
import bzrlib
26
27
from bzrlib.errors import BzrBadParameterNotUnicode, InvalidURL
150
151
        finally:
151
152
            os.umask(orig_umask)
152
153
 
 
154
    def test_format_delta(self):
 
155
        t = time.time()
 
156
 
 
157
        def check(expected, delta):
 
158
            actual = osutils.format_delta(delta)
 
159
            self.assertEqual(expected, actual)
 
160
 
 
161
        check('0 seconds ago', 0)
 
162
        check('1 second ago', 1)
 
163
        check('10 seconds ago', 10)
 
164
        check('59 seconds ago', 59)
 
165
        check('89 seconds ago', 89)
 
166
        check('1 minute, 30 seconds ago', 90)
 
167
        check('3 minutes, 0 seconds ago', 180)
 
168
        check('3 minutes, 1 second ago', 181)
 
169
        check('10 minutes, 15 seconds ago', 615)
 
170
        check('30 minutes, 59 seconds ago', 1859)
 
171
        check('31 minutes, 0 seconds ago', 1860)
 
172
        check('60 minutes, 0 seconds ago', 3600)
 
173
        check('89 minutes, 59 seconds ago', 5399)
 
174
        check('1 hour, 30 minutes ago', 5400)
 
175
        check('2 hours, 30 minutes ago', 9017)
 
176
        check('10 hours, 0 minutes ago', 36000)
 
177
        check('24 hours, 0 minutes ago', 86400)
 
178
        check('35 hours, 59 minutes ago', 129599)
 
179
        check('36 hours, 0 minutes ago', 129600)
 
180
        check('36 hours, 0 minutes ago', 129601)
 
181
        check('36 hours, 1 minute ago', 129660)
 
182
        check('36 hours, 1 minute ago', 129661)
 
183
        check('84 hours, 10 minutes ago', 303002)
 
184
 
 
185
        # We handle when time steps the wrong direction because computers
 
186
        # don't have synchronized clocks.
 
187
        check('84 hours, 10 minutes in the future', -303002)
 
188
        check('1 second in the future', -1)
 
189
        check('2 seconds in the future', -2)
 
190
 
153
191
 
154
192
class TestSafeUnicode(TestCase):
155
193