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

Unified Diff: appengine/findit/common/test/time_util_test.py

Issue 2391063002: [Findit] Fix flaky tests due to importing pytz. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/findit/common/time_util.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/common/test/time_util_test.py
diff --git a/appengine/findit/common/test/time_util_test.py b/appengine/findit/common/test/time_util_test.py
index aa43d756778cac6937c33ed73caac7d00c69dd1a..c6828cbf357a3055189b8bce6de8944668550865 100644
--- a/appengine/findit/common/test/time_util_test.py
+++ b/appengine/findit/common/test/time_util_test.py
@@ -2,14 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import mock
import unittest
from common import time_util
from datetime import datetime
from datetime import timedelta
-import pytz
-
class DiffTest(unittest.TestCase):
def testRemoveMicrosecondsFromDelta(self):
@@ -38,11 +37,11 @@ class DiffTest(unittest.TestCase):
time_util.FormatDatetime(datetime(2016, 1, 2, 1, 2, 3)),
'2016-01-02 01:02:03 UTC')
- def testGetDateTimeInTimezone(self):
- utc_datetime = datetime(2016, 9, 27, 20, 46, 18, 1, pytz.utc)
- result_pst_datetime = time_util.GetDatetimeInTimezone(
- 'US/Pacific', utc_datetime)
- expected_pst_datetime = datetime(2016, 9, 27, 13, 46, 18, 1,
- pytz.timezone('US/Pacific'))
- self.assertEqual(result_pst_datetime.date(), expected_pst_datetime.date())
- self.assertEqual(result_pst_datetime.time(), expected_pst_datetime.time())
+ @mock.patch('common.time_util.pytz')
+ def testGetDateTimeInTimezoneWithGivenDatetime(self, mocked_pytz_module):
+ mocked_datetime = mock.MagicMock()
+ mocked_datetime.astimezone.return_value = 'expected'
+
+ self.assertEqual('expected',
+ time_util.GetDatetimeInTimezone('PST', mocked_datetime))
+ mocked_pytz_module.timezone.assert_called_with('PST')
« no previous file with comments | « no previous file | appengine/findit/common/time_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698