OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 # that can be found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 """Provides functions to mock current time in tests.""" | 6 """Provides functions to mock current time in tests.""" |
7 | 7 |
8 import datetime | 8 import datetime |
9 import functools | 9 import functools |
10 import mock | 10 import mock |
11 import pytz | 11 import pytz |
12 import tzlocal | 12 import tzlocal |
13 | 13 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 tzname: Name of the timezone to be used (as passed to pytz.timezone). | 111 tzname: Name of the timezone to be used (as passed to pytz.timezone). |
112 """ | 112 """ |
113 # TODO(sergiyb): Also mock other common libraries, e.g. time, pytz.reference. | 113 # TODO(sergiyb): Also mock other common libraries, e.g. time, pytz.reference. |
114 def decorator(func): | 114 def decorator(func): |
115 @functools.wraps(func) | 115 @functools.wraps(func) |
116 def wrapper(*args, **kwargs): | 116 def wrapper(*args, **kwargs): |
117 with mock.patch('tzlocal.get_localzone', lambda: pytz.timezone(tzname)): | 117 with mock.patch('tzlocal.get_localzone', lambda: pytz.timezone(tzname)): |
118 return func(*args, **kwargs) | 118 return func(*args, **kwargs) |
119 return wrapper | 119 return wrapper |
120 return decorator | 120 return decorator |
OLD | NEW |