當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。