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

Side by Side Diff: chrome/common/extensions/docs/server2/test_util.py

Issue 14856006: Docserver: achieve online vs offline (cron vs instance) behaviour at the object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 from __future__ import print_function
6
5 import logging 7 import logging
8 import os
9 import sys
10
11 def EnableLogging(name):
12 '''Returns the output of the log with |name| to stdout.
13 '''
14 return _ReplaceLogging(name, lambda message: print(message))
6 15
7 def DisableLogging(name): 16 def DisableLogging(name):
8 '''Disables the log with |name| for the duration of the decorated function. 17 '''Disables the log with |name| for the duration of the decorated function.
9 ''' 18 '''
19 return _ReplaceLogging(name, lambda _: None)
20
21 def _ReplaceLogging(name, replacement):
10 def decorator(fn): 22 def decorator(fn):
11 def impl(*args, **optargs): 23 def impl(*args, **optargs):
12 saved = getattr(logging, name) 24 saved = getattr(logging, name)
13 setattr(logging, name, lambda _: None) 25 setattr(logging, name, replacement)
14 try: 26 try:
15 return fn(*args, **optargs) 27 return fn(*args, **optargs)
16 finally: 28 finally:
17 setattr(logging, name, saved) 29 setattr(logging, name, saved)
18 return impl 30 return impl
19 return decorator 31 return decorator
32
33 def ReadFile(name):
34 with open(os.path.join(sys.path[0], os.pardir, os.pardir, name)) as f:
35 return f.read()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698