当前位置: 首页>>代码示例>>Python>>正文


Python ExpiringCache.get方法代码示例

本文整理汇总了Python中robotide.namespace.cache.ExpiringCache.get方法的典型用法代码示例。如果您正苦于以下问题:Python ExpiringCache.get方法的具体用法?Python ExpiringCache.get怎么用?Python ExpiringCache.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在robotide.namespace.cache.ExpiringCache的用法示例。


在下文中一共展示了ExpiringCache.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cache_expiration

# 需要导入模块: from robotide.namespace.cache import ExpiringCache [as 别名]
# 或者: from robotide.namespace.cache.ExpiringCache import get [as 别名]
 def test_cache_expiration(self):
     cache = ExpiringCache(0.01)
     cache.put('a', 'b')
     time.sleep(0.1)
     assert_is_none(cache.get('a'))
     cache.put('a', 'c')
     assert_equals('c', cache.get('a'))
开发者ID:Garjy,项目名称:RIDE,代码行数:9,代码来源:test_expiring_cache.py

示例2: DatafileRetriever

# 需要导入模块: from robotide.namespace.cache import ExpiringCache [as 别名]
# 或者: from robotide.namespace.cache.ExpiringCache import get [as 别名]
class DatafileRetriever(object):
    def __init__(self, lib_cache, resource_factory):
        self._lib_cache = lib_cache
        self._resource_factory = resource_factory
        self.keyword_cache = ExpiringCache()
        self._default_kws = None

    def get_all_cached_library_names(self):
        return self._lib_cache.get_all_cached_library_names()

    @property
    def default_kws(self):
        if self._default_kws is None:
            self._default_kws = self._lib_cache.get_default_keywords()
        return self._default_kws

    def expire_cache(self):
        self.keyword_cache = ExpiringCache()
        self._lib_cache.expire()

    def get_keywords_from_several(self, datafiles):
        kws = set()
        kws.update(self.default_kws)
        for df in datafiles:
            kws.update(self.get_keywords_from(df, RetrieverContext()))
        return kws

    def get_keywords_from(self, datafile, ctx):
        self._get_vars_recursive(datafile, ctx)
        ctx.allow_going_through_resources_again()
        return sorted(set(self._get_datafile_keywords(datafile) +\
              self._get_imported_resource_keywords(datafile, ctx) +\
              self._get_imported_library_keywords(datafile, ctx)))

    def is_library_import_ok(self, datafile, imp, ctx):
        self._get_vars_recursive(datafile, ctx)
        return bool(self._lib_kw_getter(imp, ctx))

    def is_variables_import_ok(self, datafile, imp, ctx):
        self._get_vars_recursive(datafile, ctx)
        return self._import_vars(ctx, datafile, imp)

    def _get_datafile_keywords(self, datafile):
        if isinstance(datafile, robotapi.ResourceFile):
            return [ResourceUserKeywordInfo(kw) for kw in datafile.keywords]
        return [TestCaseUserKeywordInfo(kw) for kw in datafile.keywords]

    def _get_imported_library_keywords(self, datafile, ctx):
        return self._collect_kws_from_imports(datafile, robotapi.Library,
                                              self._lib_kw_getter, ctx)

    def _collect_kws_from_imports(self, datafile, instance_type, getter, ctx):
        kws = []
        for imp in self._collect_import_of_type(datafile, instance_type):
            kws.extend(getter(imp, ctx))
        return kws

    def _lib_kw_getter(self, imp, ctx):
        name = ctx.replace_variables(imp.name)
        name = self._convert_to_absolute_path(name, imp)
        args = [ctx.replace_variables(a) for a in imp.args]
        alias = ctx.replace_variables(imp.alias) if imp.alias else None
        return self._lib_cache.get_library_keywords(name, args, alias)

    def _convert_to_absolute_path(self, name, import_):
        full_name = os.path.join(import_.directory, name)
        if os.path.exists(full_name):
            return full_name
        return name

    def _collect_import_of_type(self, datafile, instance_type):
        return [imp for imp in datafile.imports
                if isinstance(imp, instance_type)]

    def _get_imported_resource_keywords(self, datafile, ctx):
        return self._collect_kws_from_imports(datafile, robotapi.Resource,
                                              self._res_kw_recursive_getter,
                                              ctx)

    def _res_kw_recursive_getter(self, imp, ctx):
        kws = []
        res = self._resource_factory.get_resource_from_import(imp, ctx)
        if not res or res in ctx.parsed:
            return kws
        ctx.parsed.add(res)
        ctx.set_variables_from_datafile_variable_table(res)
        for child in self._collect_import_of_type(res, robotapi.Resource):
            kws.extend(self._res_kw_recursive_getter(child, ctx))
        kws.extend(self._get_imported_library_keywords(res, ctx))
        return [ResourceUserKeywordInfo(kw) for kw in res.keywords] + kws

    def get_variables_from(self, datafile, ctx=None):
        return self._get_vars_recursive(datafile,
                                        ctx or RetrieverContext()).vars

    def _get_vars_recursive(self, datafile, ctx):
        ctx.set_variables_from_datafile_variable_table(datafile)
        self._collect_vars_from_variable_files(datafile, ctx)
        self._collect_each_res_import(datafile, ctx, self._var_collector)
        return ctx
#.........这里部分代码省略.........
开发者ID:pskpg86,项目名称:RIDE,代码行数:103,代码来源:namespace.py

示例3: test_cache_hit

# 需要导入模块: from robotide.namespace.cache import ExpiringCache [as 别名]
# 或者: from robotide.namespace.cache.ExpiringCache import get [as 别名]
 def test_cache_hit(self):
     cache = ExpiringCache(0.1)
     cache.put('a', 'b')
     assert_equals('b', cache.get('a'))
开发者ID:Garjy,项目名称:RIDE,代码行数:6,代码来源:test_expiring_cache.py


注:本文中的robotide.namespace.cache.ExpiringCache.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。