151
151
os.umask(orig_umask)
153
def assertFormatedDelta(self, expected, seconds):
154
"""Assert osutils.format_delta formats as expected"""
155
actual = osutils.format_delta(seconds)
156
self.assertEqual(expected, actual)
158
def test_format_delta(self):
159
self.assertFormatedDelta('0 seconds ago', 0)
160
self.assertFormatedDelta('1 second ago', 1)
161
self.assertFormatedDelta('10 seconds ago', 10)
162
self.assertFormatedDelta('59 seconds ago', 59)
163
self.assertFormatedDelta('89 seconds ago', 89)
164
self.assertFormatedDelta('1 minute, 30 seconds ago', 90)
165
self.assertFormatedDelta('3 minutes, 0 seconds ago', 180)
166
self.assertFormatedDelta('3 minutes, 1 second ago', 181)
167
self.assertFormatedDelta('10 minutes, 15 seconds ago', 615)
168
self.assertFormatedDelta('30 minutes, 59 seconds ago', 1859)
169
self.assertFormatedDelta('31 minutes, 0 seconds ago', 1860)
170
self.assertFormatedDelta('60 minutes, 0 seconds ago', 3600)
171
self.assertFormatedDelta('89 minutes, 59 seconds ago', 5399)
172
self.assertFormatedDelta('1 hour, 30 minutes ago', 5400)
173
self.assertFormatedDelta('2 hours, 30 minutes ago', 9017)
174
self.assertFormatedDelta('10 hours, 0 minutes ago', 36000)
175
self.assertFormatedDelta('24 hours, 0 minutes ago', 86400)
176
self.assertFormatedDelta('35 hours, 59 minutes ago', 129599)
177
self.assertFormatedDelta('36 hours, 0 minutes ago', 129600)
178
self.assertFormatedDelta('36 hours, 0 minutes ago', 129601)
179
self.assertFormatedDelta('36 hours, 1 minute ago', 129660)
180
self.assertFormatedDelta('36 hours, 1 minute ago', 129661)
181
self.assertFormatedDelta('84 hours, 10 minutes ago', 303002)
183
# We handle when time steps the wrong direction because computers
184
# don't have synchronized clocks.
185
self.assertFormatedDelta('84 hours, 10 minutes in the future', -303002)
186
self.assertFormatedDelta('1 second in the future', -1)
187
self.assertFormatedDelta('2 seconds in the future', -2)
154
190
class TestSafeUnicode(TestCase):