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

Unified 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, 8 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
Index: chrome/common/extensions/docs/server2/test_util.py
diff --git a/chrome/common/extensions/docs/server2/test_util.py b/chrome/common/extensions/docs/server2/test_util.py
index 1f3aed12e0316f1bc87d27372e846bbcd70bff03..4104248f3b259b4645b3c7cd02b881629dcbda6f 100644
--- a/chrome/common/extensions/docs/server2/test_util.py
+++ b/chrome/common/extensions/docs/server2/test_util.py
@@ -2,18 +2,34 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from __future__ import print_function
+
import logging
+import os
+import sys
+
+def EnableLogging(name):
+ '''Returns the output of the log with |name| to stdout.
+ '''
+ return _ReplaceLogging(name, lambda message: print(message))
def DisableLogging(name):
'''Disables the log with |name| for the duration of the decorated function.
'''
+ return _ReplaceLogging(name, lambda _: None)
+
+def _ReplaceLogging(name, replacement):
def decorator(fn):
def impl(*args, **optargs):
saved = getattr(logging, name)
- setattr(logging, name, lambda _: None)
+ setattr(logging, name, replacement)
try:
return fn(*args, **optargs)
finally:
setattr(logging, name, saved)
return impl
return decorator
+
+def ReadFile(name):
+ with open(os.path.join(sys.path[0], os.pardir, os.pardir, name)) as f:
+ return f.read()

Powered by Google App Engine
This is Rietveld 408576698