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


Python Context.popitem方法代码示例

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


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

示例1: setup

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import popitem [as 别名]
    class configuration_proxy:
        "Dict-like proxy for self.config"
        def setup(self):
            config = Config(defaults={'foo': 'bar', 'biz': {'baz': 'boz'}})
            self.c = Context(config=config)

        def direct_access_allowed(self):
            eq_(self.c.config.__class__, Config)
            eq_(self.c.config['foo'], 'bar')
            eq_(self.c.config.foo, 'bar')

        def config_attr_may_be_overwritten_at_runtime(self):
            new_config = Config(defaults={'foo': 'notbar'})
            self.c.config = new_config
            eq_(self.c.foo, 'notbar')

        def getitem(self):
            "___getitem__"
            eq_(self.c['foo'], 'bar')
            eq_(self.c['biz']['baz'], 'boz')

        def getattr(self):
            "__getattr__"
            eq_(self.c.foo, 'bar')
            eq_(self.c.biz.baz, 'boz')

        def get(self):
            eq_(self.c.get('foo'), 'bar')
            eq_(self.c.get('nope', 'wut'), 'wut')
            eq_(self.c.biz.get('nope', 'hrm'), 'hrm')

        def pop(self):
            eq_(self.c.pop('foo'), 'bar')
            eq_(self.c.pop('foo', 'notbar'), 'notbar')
            eq_(self.c.biz.pop('baz'), 'boz')

        def popitem(self):
            eq_(self.c.biz.popitem(), ('baz', 'boz'))
            del self.c['biz']
            eq_(self.c.popitem(), ('foo', 'bar'))
            eq_(self.c.config, {})

        def del_(self):
            "del"
            del self.c['foo']
            del self.c['biz']['baz']
            eq_(self.c.biz, {})
            del self.c['biz']
            eq_(self.c.config, {})

        def clear(self):
            self.c.biz.clear()
            eq_(self.c.biz, {})
            self.c.clear()
            eq_(self.c.config, {})

        def setdefault(self):
            eq_(self.c.setdefault('foo'), 'bar')
            eq_(self.c.biz.setdefault('baz'), 'boz')
            eq_(self.c.setdefault('notfoo', 'notbar'), 'notbar')
            eq_(self.c.notfoo, 'notbar')
            eq_(self.c.biz.setdefault('otherbaz', 'otherboz'), 'otherboz')
            eq_(self.c.biz.otherbaz, 'otherboz')

        def update(self):
            self.c.update({'newkey': 'newval'})
            eq_(self.c['newkey'], 'newval')
            eq_(self.c.foo, 'bar')
            self.c.biz.update(otherbaz='otherboz')
            eq_(self.c.biz.otherbaz, 'otherboz')
开发者ID:yws,项目名称:invoke,代码行数:72,代码来源:context.py

示例2: setup

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import popitem [as 别名]
    class configuration_proxy:
        "Dict-like proxy for self.config"

        def setup(self):
            config = Config(defaults={"foo": "bar", "biz": {"baz": "boz"}})
            self.c = Context(config=config)

        def direct_access_allowed(self):
            assert self.c.config.__class__ == Config
            assert self.c.config["foo"] == "bar"
            assert self.c.config.foo == "bar"

        def config_attr_may_be_overwritten_at_runtime(self):
            new_config = Config(defaults={"foo": "notbar"})
            self.c.config = new_config
            assert self.c.foo == "notbar"

        def getitem(self):
            "___getitem__"
            assert self.c["foo"] == "bar"
            assert self.c["biz"]["baz"] == "boz"

        def getattr(self):
            "__getattr__"
            assert self.c.foo == "bar"
            assert self.c.biz.baz == "boz"

        def get(self):
            assert self.c.get("foo") == "bar"
            assert self.c.get("nope", "wut") == "wut"
            assert self.c.biz.get("nope", "hrm") == "hrm"

        def pop(self):
            assert self.c.pop("foo") == "bar"
            assert self.c.pop("foo", "notbar") == "notbar"
            assert self.c.biz.pop("baz") == "boz"

        def popitem(self):
            assert self.c.biz.popitem() == ("baz", "boz")
            del self.c["biz"]
            assert self.c.popitem() == ("foo", "bar")
            assert self.c.config == {}

        def del_(self):
            "del"
            del self.c["foo"]
            del self.c["biz"]["baz"]
            assert self.c.biz == {}
            del self.c["biz"]
            assert self.c.config == {}

        def clear(self):
            self.c.biz.clear()
            assert self.c.biz == {}
            self.c.clear()
            assert self.c.config == {}

        def setdefault(self):
            assert self.c.setdefault("foo") == "bar"
            assert self.c.biz.setdefault("baz") == "boz"
            assert self.c.setdefault("notfoo", "notbar") == "notbar"
            assert self.c.notfoo == "notbar"
            assert self.c.biz.setdefault("otherbaz", "otherboz") == "otherboz"
            assert self.c.biz.otherbaz == "otherboz"

        def update(self):
            self.c.update({"newkey": "newval"})
            assert self.c["newkey"] == "newval"
            assert self.c.foo == "bar"
            self.c.biz.update(otherbaz="otherboz")
            assert self.c.biz.otherbaz == "otherboz"
开发者ID:miradam,项目名称:invoke,代码行数:73,代码来源:context.py


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