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() |