| 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:
|
|
|