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


Python Testbed.init_images_stub方法代码示例

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


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

示例1: StubManager

# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import init_images_stub [as 别名]
class StubManager(object):
    def __init__(self):
        self.testbed = None
        self.active_stubs = None
        self.pre_test_stubs = None

    def setup_stubs(self, connection):
        if self.active_stubs is not None:
            return
        if not have_appserver:
            self.activate_stubs(connection)

    def activate_stubs(self, connection):
        try:
            from google.appengine.tools import dev_appserver_main

            self.setup_local_stubs(connection)
        except ImportError:
            self.activate_test_stubs(connection)

    def reset_stubs(self, connection, datastore_path=None):
        if self.active_stubs == "test":
            self.deactivate_test_stubs()
            self.activate_test_stubs(connection, datastore_path)

        elif self.active_stubs == "local":
            self.setup_local_stubs(connection)

        elif self.active_stubs == "remote":
            self.setup_remote_stubs(connection)

    def activate_test_stubs(self, connection, datastore_path=None):
        if self.active_stubs == "test":
            return

        if self.testbed is None:
            from google.appengine.ext.testbed import Testbed

            self.testbed = Testbed()

        self.testbed.activate()
        self.pre_test_stubs = self.active_stubs
        self.active_stubs = "test"

        os.environ["APPLICATION_ID"] = "dev~" + appid
        os.environ["HTTP_HOST"] = "%s.appspot.com" % appid

        appserver_opts = connection.settings_dict.get("DEV_APPSERVER_OPTIONS", {})
        high_replication = appserver_opts.get("high_replication", False)
        require_indexes = appserver_opts.get("require_indexes", False)
        use_sqlite = appserver_opts.get("use_sqlite", False)

        datastore_opts = {"require_indexes": require_indexes, "use_sqlite": use_sqlite}

        if high_replication:
            from google.appengine.datastore import datastore_stub_util

            datastore_opts["consistency_policy"] = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)

        self.testbed.init_datastore_v3_stub(datastore_file=datastore_path, **datastore_opts)
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub(auto_task_running=True, root_path=PROJECT_DIR)
        self.testbed.init_urlfetch_stub()
        self.testbed.init_user_stub()
        self.testbed.init_xmpp_stub()
        self.testbed.init_channel_stub()
        self.testbed.init_app_identity_stub()
        self.testbed.init_blobstore_stub()
        self.testbed.init_files_stub()
        self.testbed.init_images_stub()

    def deactivate_test_stubs(self):
        if self.active_stubs == "test":
            self.testbed.deactivate()
            self.active_stubs = self.pre_test_stubs

    def setup_local_stubs(self, connection):
        if self.active_stubs == "local":
            return

        from .base import get_datastore_paths
        from google.appengine.tools import dev_appserver_main

        args = dev_appserver_main.DEFAULT_ARGS.copy()
        args.update(get_datastore_paths(connection.settings_dict))
        args.update(connection.settings_dict.get("DEV_APPSERVER_OPTIONS", {}))
        log_level = logging.getLogger().getEffectiveLevel()
        logging.getLogger().setLevel(logging.WARNING)

        try:
            from google.appengine.tools import dev_appserver
        except ImportError:
            from google.appengine.tools import old_dev_appserver as dev_appserver
        dev_appserver.SetupStubs("dev~" + appid, **args)
        logging.getLogger().setLevel(log_level)
        self.active_stubs = "local"

    def setup_remote_stubs(self, connection):
        if self.active_stubs == "remote":
            return
#.........这里部分代码省略.........
开发者ID:JohnDevitt,项目名称:cloud_3.0,代码行数:103,代码来源:stubs.py


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