當前位置: 首頁>>代碼示例>>Python>>正文


Python invoke.Context類代碼示例

本文整理匯總了Python中invoke.Context的典型用法代碼示例。如果您正苦於以下問題:Python Context類的具體用法?Python Context怎麽用?Python Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: can_be_pickled

 def can_be_pickled(self):
     c = Context()
     c.foo = {'bar': {'biz': ['baz', 'buzz']}}
     c2 = pickle.loads(pickle.dumps(c))
     eq_(c, c2)
     ok_(c is not c2)
     ok_(c.foo.bar.biz is not c2.foo.bar.biz)
開發者ID:yws,項目名稱:invoke,代碼行數:7,代碼來源:context.py

示例2: _expect_responses

        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,代碼行數:27,代碼來源:context.py

示例3: can_be_pickled

 def can_be_pickled(self):
     c = Context()
     c.foo = {'bar': {'biz': ['baz', 'buzz']}}
     c2 = pickle.loads(pickle.dumps(c))
     assert c == c2
     assert c is not c2
     assert c.foo.bar.biz is not c2.foo.bar.biz
開發者ID:offbyone,項目名稱:invoke,代碼行數:7,代碼來源:context.py

示例4: honors_runner_config_setting

 def honors_runner_config_setting(self):
     runner_class = Mock()
     config = Config({'runners': {'local': runner_class}})
     c = Context(config)
     c.run('foo')
     assert runner_class.mock_calls == [
         call(c), call().run('foo'),
     ]
開發者ID:yws,項目名稱:invoke,代碼行數:8,代碼來源:context.py

示例5: prefixes_should_apply_to_sudo

        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,代碼行數:9,代碼來源:context.py

示例6: prefixes_should_apply_to_run

        def prefixes_should_apply_to_run(self, Local):
            runner = Local.return_value
            ctx = Context()
            with ctx.prefix('cd foo'):
                ctx.run('whoami')

            cmd = "cd foo && whoami"
            ok_(runner.run.called, "run() never called runner.run()!")
            eq_(runner.run.call_args[0][0], cmd)
開發者ID:yws,項目名稱:invoke,代碼行數:9,代碼來源:context.py

示例7: prefixes_should_apply_to_run

        def prefixes_should_apply_to_run(self, Local):
            runner = Local.return_value
            c = Context()
            with c.prefix("cd foo"):
                c.run("whoami")

            cmd = "cd foo && whoami"
            assert runner.run.called, "run() never called runner.run()!"
            assert runner.run.call_args[0][0] == cmd
開發者ID:miradam,項目名稱:invoke,代碼行數:9,代碼來源:context.py

示例8: prefixes_should_apply_to_sudo

        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,代碼行數:9,代碼來源:context.py

示例9: cd_should_apply_to_sudo

        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,代碼行數:9,代碼來源:context.py

示例10: cd_should_apply_to_run

        def cd_should_apply_to_run(self, Local):
            runner = Local.return_value
            c = Context()
            with c.cd('foo'):
                c.run('whoami')

            cmd = "cd foo && whoami"
            assert runner.run.called, "run() never called runner.run()!"
            assert runner.run.call_args[0][0] == cmd
開發者ID:offbyone,項目名稱:invoke,代碼行數:9,代碼來源:context.py

示例11: cd_should_occur_before_prefixes

        def cd_should_occur_before_prefixes(self, Local):
            runner = Local.return_value
            c = Context()
            with c.prefix("source venv"):
                with c.cd("foo"):
                    c.run("whoami")

            cmd = "cd foo && source venv && whoami"
            assert runner.run.called, "run() never called runner.run()!"
            assert runner.run.call_args[0][0] == cmd
開發者ID:miradam,項目名稱:invoke,代碼行數:10,代碼來源:context.py

示例12: cd_should_occur_before_prefixes

        def cd_should_occur_before_prefixes(self, Local):
            runner = Local.return_value
            ctx = Context()
            with ctx.prefix('source venv'):
                with ctx.cd('foo'):
                    ctx.run('whoami')

            cmd = "cd foo && source venv && whoami"
            ok_(runner.run.called, "run() never called runner.run()!")
            eq_(runner.run.call_args[0][0], cmd)
開發者ID:yws,項目名稱:invoke,代碼行數:10,代碼來源:context.py

示例13: _build

def _build():
    """
    Build local support docs tree and return the build target dir for cleanup.
    """
    c = Context()
    support = join(dirname(__file__), "_support")
    docs = join(support, "docs")
    build = join(support, "_build")
    command = "sphinx-build -c {} -W {} {}".format(support, docs, build)
    with c.cd(support):
        # Turn off stdin mirroring to avoid irritating pytest.
        c.run(command, in_stream=False)
    return build
開發者ID:pyinvoke,項目名稱:invocations,代碼行數:13,代碼來源:base.py

示例14: kwarg_only_adds_to_kwarg

 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,代碼行數:14,代碼來源:context.py

示例15: sites

def sites(c):
    """
    Builds both doc sites w/ maxed nitpicking.
    """
    # Turn warnings into errors, emit warnings about missing references.
    # This gives us a maximally noisy docs build.
    # Also enable tracebacks for easier debuggage.
    opts = "-W -n -T"
    # This is super lolzy but we haven't actually tackled nontrivial in-Python
    # task calling yet, so...
    docs_c, www_c = Context(config=c.config.clone()), Context(config=c.config.clone())
    docs_c.update(**docs.configuration())
    www_c.update(**www.configuration())
    docs['build'](docs_c, opts=opts)
    www['build'](www_c, opts=opts)
開發者ID:pombredanne,項目名稱:invoke,代碼行數:15,代碼來源:tasks.py


注:本文中的invoke.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。