Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: appengine/findit/common/test/time_util_test.py

Issue 2376573004: [Findit] For automatic analyses of flaky tests, run the Swarming tasks off PST peak hours. (Closed)
Patch Set: Fix nit. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/findit/common/findit_testcase.py ('k') | appengine/findit/common/time_util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 6
7 from common import time_util 7 from common import time_util
8 from datetime import datetime 8 from datetime import datetime
9 from datetime import timedelta 9 from datetime import timedelta
10 10
11 import pytz
12
11 13
12 class DiffTest(unittest.TestCase): 14 class DiffTest(unittest.TestCase):
13 def testRemoveMicrosecondsFromDelta(self): 15 def testRemoveMicrosecondsFromDelta(self):
14 date1 = datetime(2016, 5, 1, 1, 1, 1, 1) 16 date1 = datetime(2016, 5, 1, 1, 1, 1, 1)
15 date2 = datetime(2016, 5, 1, 1, 1, 1, 2) 17 date2 = datetime(2016, 5, 1, 1, 1, 1, 2)
16 delta = date2 - date1 18 delta = date2 - date1
17 19
18 self.assertEqual( 20 self.assertEqual(
19 time_util.RemoveMicrosecondsFromDelta(delta).microseconds, 21 time_util.RemoveMicrosecondsFromDelta(delta).microseconds,
20 0) 22 0)
21 23
22 def testFormatTimedelta(self): 24 def testFormatTimedelta(self):
23 self.assertIsNone(time_util.FormatTimedelta(None)) 25 self.assertIsNone(time_util.FormatTimedelta(None))
24 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 1)), 26 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 1)),
25 '00:00:01') 27 '00:00:01')
26 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 60)), 28 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 60)),
27 '00:01:00') 29 '00:01:00')
28 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 3600)), 30 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 3600)),
29 '01:00:00') 31 '01:00:00')
30 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 0, 1)), 32 self.assertEqual(time_util.FormatTimedelta(timedelta(0, 0, 1)),
31 '00:00:00') 33 '00:00:00')
32 34
33 def testFormatDatetime(self): 35 def testFormatDatetime(self):
34 self.assertIsNone(time_util.FormatDatetime(None)) 36 self.assertIsNone(time_util.FormatDatetime(None))
35 self.assertEqual( 37 self.assertEqual(
36 time_util.FormatDatetime(datetime(2016, 1, 2, 1, 2, 3)), 38 time_util.FormatDatetime(datetime(2016, 1, 2, 1, 2, 3)),
37 '2016-01-02 01:02:03 UTC') 39 '2016-01-02 01:02:03 UTC')
40
41 def testGetDateTimeInTimezone(self):
42 utc_datetime = datetime(2016, 9, 27, 20, 46, 18, 1, pytz.utc)
43 result_pst_datetime = time_util.GetDatetimeInTimezone(
44 'US/Pacific', utc_datetime)
45 expected_pst_datetime = datetime(2016, 9, 27, 13, 46, 18, 1,
46 pytz.timezone('US/Pacific'))
47 self.assertEqual(result_pst_datetime.date(), expected_pst_datetime.date())
48 self.assertEqual(result_pst_datetime.time(), expected_pst_datetime.time())
OLDNEW
« no previous file with comments | « appengine/findit/common/findit_testcase.py ('k') | appengine/findit/common/time_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698