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

Side by Side Diff: client/third_party/infra_libs/time_functions/testing.py

Issue 2013943002: Changing license header, again! (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698