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


Python Context.sudo方法代码示例

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


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

示例1: _expect_responses

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import sudo [as 别名]
        def _expect_responses(self,
            expected, Local, getpass,
            config=None, kwargs=None, getpass_reply=None,
        ):
            """
            Execute mocked sudo(), expecting watchers= kwarg in its run().

            * expected: list of 2-tuples of FailingResponder prompt/response
            * config: Config object, if an overridden one is needed
            * kwargs: sudo() kwargs, if needed
            * getpass_reply: return value of getpass.getpass, if needed

            (Local and getpass are just mock injections.)
            """
            if kwargs is None:
                kwargs = {}
            getpass.getpass.return_value = getpass_reply
            runner = Local.return_value
            context = Context(config=config) if config else Context()
            context.sudo('whoami', **kwargs)
            # Tease out the interesting bits - pattern/response - ignoring the
            # sentinel, etc for now.
            prompt_responses = [
                (watcher.pattern, watcher.response)
                for watcher in runner.run.call_args[1]['watchers']
            ]
            eq_(prompt_responses, expected)
开发者ID:gtback,项目名称:invoke,代码行数:29,代码来源:context.py

示例2: prefixes_should_apply_to_sudo

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import sudo [as 别名]
        def prefixes_should_apply_to_sudo(self, Local):
            runner = Local.return_value
            c = Context()
            with c.prefix("cd foo"):
                c.sudo("whoami")

            cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami"
            assert runner.run.called, "sudo() never called runner.run()!"
            assert runner.run.call_args[0][0] == cmd
开发者ID:miradam,项目名称:invoke,代码行数:11,代码来源:context.py

示例3: prefixes_should_apply_to_sudo

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import sudo [as 别名]
        def prefixes_should_apply_to_sudo(self, Local):
            runner = Local.return_value
            ctx = Context()
            with ctx.prefix('cd foo'):
                ctx.sudo('whoami')

            cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami"
            ok_(runner.run.called, "sudo() never called runner.run()!")
            eq_(runner.run.call_args[0][0], cmd)
开发者ID:yws,项目名称:invoke,代码行数:11,代码来源:context.py

示例4: cd_should_apply_to_sudo

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import sudo [as 别名]
        def cd_should_apply_to_sudo(self, Local):
            runner = Local.return_value
            c = Context()
            with c.cd('foo'):
                c.sudo('whoami')

            cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami"
            assert runner.run.called, "sudo() never called runner.run()!"
            assert runner.run.call_args[0][0] == cmd
开发者ID:offbyone,项目名称:invoke,代码行数:11,代码来源:context.py

示例5: kwarg_only_adds_to_kwarg

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import sudo [as 别名]
 def kwarg_only_adds_to_kwarg(self, Local):
     runner = Local.return_value
     context = Context()
     watcher = self.watcher_klass()
     context.sudo("whoami", watchers=[watcher])
     # When sudo() called w/ user-specified watchers, we add ours to
     # that list
     watchers = runner.run.call_args[1]["watchers"]
     # Will raise ValueError if not in the list
     watchers.remove(watcher)
     # Only remaining item in list should be our sudo responder
     assert len(watchers) == 1
     assert isinstance(watchers[0], FailingResponder)
     assert watchers[0].pattern == self.escaped_prompt
开发者ID:miradam,项目名称:invoke,代码行数:16,代码来源:context.py

示例6: _expect_responses

# 需要导入模块: from invoke import Context [as 别名]
# 或者: from invoke.Context import sudo [as 别名]
        def _expect_responses(self, expected, config=None, kwargs=None):
            """
            Execute mocked sudo(), expecting watchers= kwarg in its run().

            * expected: list of 2-tuples of FailingResponder prompt/response
            * config: Config object, if an overridden one is needed
            * kwargs: sudo() kwargs, if needed
            """
            if kwargs is None:
                kwargs = {}
            Local = Mock()
            runner = Local.return_value
            context = Context(config=config) if config else Context()
            context.config.runners.local = Local
            context.sudo("whoami", **kwargs)
            # Tease out the interesting bits - pattern/response - ignoring the
            # sentinel, etc for now.
            prompt_responses = [
                (watcher.pattern, watcher.response)
                for watcher in runner.run.call_args[1]["watchers"]
            ]
            assert prompt_responses == expected
开发者ID:miradam,项目名称:invoke,代码行数:24,代码来源:context.py


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