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

Unified Diff: chrome/common/extensions/docs/server2/test_util.py

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix 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 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..02dc25fc4f0abee203617433a0cc32bdbc75f91b 100644
--- a/chrome/common/extensions/docs/server2/test_util.py
+++ b/chrome/common/extensions/docs/server2/test_util.py
@@ -2,18 +2,35 @@
# 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
+
+# TODO(kalman): Use this everywhere. A lot of tests are doing this.
+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