diff options
author | jaredshumway94@gmail.com <jaredshumway94@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-30 17:17:37 +0000 |
---|---|---|
committer | jaredshumway94@gmail.com <jaredshumway94@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-30 17:17:37 +0000 |
commit | f0960374419d9f4c6ab64ead84c76e396bd7bc2b (patch) | |
tree | 4013ca48c1a2788d477d128aa349a359b28a5190 /chrome/common/extensions/docs/server2/test_util.py | |
parent | 4dbffcc3318651134a4a7a932b43590daffc9505 (diff) | |
download | chromium_src-f0960374419d9f4c6ab64ead84c76e396bd7bc2b.zip chromium_src-f0960374419d9f4c6ab64ead84c76e396bd7bc2b.tar.gz chromium_src-f0960374419d9f4c6ab64ead84c76e396bd7bc2b.tar.bz2 |
Docserver: SidenavDataSource refactor, transition to DataSourceRegistry
The next step in moving towards the DataSourceRegistry architecture
(see bug).
The SidenavDataSource is the first DataSource to rely on the contents of
a request and the DataSourceRegistry had to change. Now DataSources are
given both a ServerInstance and a Request when created. Strings and
Manifest DataSources have been updated.
SidenavDataSource contained some very old code and was in need of
refactoring. The Factory had to be stripped out because it is now
unneeded and doesn't work with the registry.
CreateDataSource was moved into the RenderServlet and is added to the
template data source in Create to give the DataSources access to
a Request.
BUG=275039
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/22824042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/server2/test_util.py')
-rw-r--r-- | chrome/common/extensions/docs/server2/test_util.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/chrome/common/extensions/docs/server2/test_util.py b/chrome/common/extensions/docs/server2/test_util.py index d02bc92..5822014 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: |