# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# pylint: disable=W0212
import functools
+import inspect
import types
If CreateFoo() accepts parameters, a separate cached value is maintained
for each unique parameter combination.
- """
- cache = obj.__cache = {}
+ Cached methods maintain their cache for the lifetime of the /instance/, while
+ cached functions maintain their cache for the lifetime of the /module/.
+ """
@functools.wraps(obj)
def Cacher(*args, **kwargs):
- key = str(args) + str(kwargs)
- if key not in cache:
- cache[key] = obj(*args, **kwargs)
- return cache[key]
+ cacher = args[0] if inspect.getargspec(obj).args[:1] == ['self'] else obj
+ cacher.__cache = cacher.__cache if hasattr(cacher, '__cache') else {}
+ key = str(obj) + str(args) + str(kwargs)
+ if key not in cacher.__cache:
+ cacher.__cache[key] = obj(*args, **kwargs)
+ return cacher.__cache[key]
return Cacher
return _Enabled
-# pylint: disable=W0212
-def IsEnabled(test, browser_type, platform):
- """Returns True iff |test| is enabled given the |browser_type| and |platform|.
+def IsEnabled(test, possible_browser):
+ """Returns True iff |test| is enabled given the |possible_browser|.
Use to respect the @Enabled / @Disabled decorators.
Args:
test: A function or class that may contain _disabled_strings and/or
_enabled_strings attributes.
- browser_type: A string representing the --browser string.
- platform: A platform.Platform instance for the target of |browser_type|.
+ possible_browser: A PossibleBrowser to check whether |test| may run against.
"""
platform_attributes = [a.lower() for a in [
- browser_type,
- platform.GetOSName(),
- platform.GetOSVersionName(),
+ possible_browser.browser_type,
+ possible_browser.platform.GetOSName(),
+ possible_browser.platform.GetOSVersionName(),
]]
+ if possible_browser.supports_tab_control:
+ platform_attributes.append('has tabs')
if hasattr(test, '__name__'):
name = test.__name__