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

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

Issue 22824042: Docserver: SidenavDataSource refactor, transition to DataSourceRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup, deleted unused files/import Created 7 years, 4 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
« no previous file with comments | « chrome/common/extensions/docs/server2/test_data/sidenav_data_source/test_sidenav.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d02bc924dcb5486d2dae1b9a8f1b7e379c5762f9..5822014d7083770ffe0b233ad9500b2f03541384 100644
--- a/chrome/common/extensions/docs/server2/test_util.py
+++ b/chrome/common/extensions/docs/server2/test_util.py
@@ -8,16 +8,37 @@ import logging
import os
import sys
+
+def CaptureLogging(f):
+ '''Call the function |f|, capturing any logging output generated. |f| must
+ take no arguments. Returns a list of LogRecords that were emitted.
+ '''
+ output = []
+ class Capture(object):
+ def filter(self, record):
+ output.append(record)
+
+ cf = Capture()
+ logging.getLogger('').addFilter(cf)
+ f()
+ logging.getLogger('').removeFilter(cf)
+
+ return output
+
+
def EnableLogging(name):
'''Returns the output of the log with |name| to stdout.
'''
+
return _ReplaceLogging(name, lambda message, *args: print(message % args))
+
def DisableLogging(name):
'''Disables the log with |name| for the duration of the decorated function.
'''
return _ReplaceLogging(name, lambda _, *args: None)
+
def _ReplaceLogging(name, replacement):
def decorator(fn):
def impl(*args, **optargs):
@@ -30,6 +51,7 @@ def _ReplaceLogging(name, replacement):
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:
« no previous file with comments | « chrome/common/extensions/docs/server2/test_data/sidenav_data_source/test_sidenav.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698