本文整理汇总了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)
示例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)
示例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
示例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'),
]
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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)