本文整理汇总了Python中invoke.Program.run方法的典型用法代码示例。如果您正苦于以下问题:Python Program.run方法的具体用法?Python Program.run怎么用?Python Program.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invoke.Program
的用法示例。
在下文中一共展示了Program.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UnexpectedExit_str_encodes_stdout_and_err
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def UnexpectedExit_str_encodes_stdout_and_err(self, mock_exit):
p = Program()
oops = UnexpectedExit(Result(
command='meh',
exited=54,
stdout=u'this is not ascii: \u1234',
stderr=u'this is also not ascii: \u4321',
encoding='utf-8',
hide=('stdout', 'stderr'),
))
p.execute = Mock(side_effect=oops)
p.run("myapp foo")
# NOTE: using explicit binary ASCII here, & accessing raw
# getvalue() of the faked sys.stderr (spec.trap auto-decodes it
# normally) to have a not-quite-tautological test. otherwise we'd
# just be comparing unicode to unicode. shrug?
expected = b"""Encountered a bad command exit code!
Command: 'meh'
Exit code: 54
Stdout:
this is not ascii: \xe1\x88\xb4
Stderr:
this is also not ascii: \xe4\x8c\xa1
"""
got = six.BytesIO.getvalue(sys.stderr)
assert got == expected
示例2: defaults_to_sys_argv
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def defaults_to_sys_argv(self, mock_sys):
argv = ['inv', '--version']
mock_sys.argv = argv
p = Program()
p.print_version = Mock()
p.run(exit=False)
p.print_version.assert_called()
示例3: expect
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def expect(invocation, out=None, err=None, program=None, invoke=True,
test=None):
"""
Run ``invocation`` via ``program`` and expect resulting output to match.
May give one or both of ``out``/``err`` (but not neither).
``program`` defaults to ``Program()``.
To skip automatically assuming the argv under test starts with ``"invoke
"``, say ``invoke=False``.
To customize the operator used for testing (default: equality), use
``test`` (which should be an assertion wrapper of some kind).
"""
if program is None:
program = Program()
if invoke:
invocation = "invoke {0}".format(invocation)
program.run(invocation, exit=False)
# Perform tests
if out is not None:
(test or eq_)(sys.stdout.getvalue(), out)
if err is not None:
(test or eq_)(sys.stderr.getvalue(), err)
示例4: shows_UnexpectedExit_repr_when_streams_hidden
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def shows_UnexpectedExit_repr_when_streams_hidden(self, mock_exit):
p = Program()
oops = UnexpectedExit(Result(
command='meh',
exited=54,
stdout='things!',
stderr='ohnoz!',
hide=('stdout', 'stderr'),
))
p.execute = Mock(side_effect=oops)
p.run("myapp foo")
# Expect repr() of exception prints to stderr
# NOTE: this partially duplicates a test in runners.py; whatever.
eq_(sys.stderr.getvalue(), """Encountered a bad command exit code!
Command: 'meh'
Exit code: 54
Stdout:
things!
Stderr:
ohnoz!
""")
# And exit with expected code (vs e.g. 1 or 0)
mock_exit.assert_called_with(54)
示例5: config_attribute_is_memoized
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def config_attribute_is_memoized(self):
klass = Mock()
# Can't .config without .run (meh); .run calls .config once.
p = Program(config_class=klass)
p.run("myapp foo", exit=False)
eq_(klass.call_count, 1)
# Second access should use cached value
p.config
eq_(klass.call_count, 1)
示例6: expected_failure_types_dont_raise_exceptions
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def expected_failure_types_dont_raise_exceptions(self, mock_exit):
"expected failure types don't raise exceptions"
for side_effect in (
SimpleFailure,
ParseError("boo!"),
):
p = Program()
p.execute = Mock(side_effect=side_effect)
p.run("myapp -c foo mytask") # valid task name for parse step
# Make sure we still exited fail-wise
mock_exit.assert_called_with(1)
示例7: ParseErrors_display_message_and_exit_1
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def ParseErrors_display_message_and_exit_1(self, mock_exit):
p = Program()
# Run with a definitely-parser-angering incorrect input; the fact
# that this line doesn't raise an exception and thus fail the
# test, is what we're testing...
nah = 'nopenotvalidsorry'
p.run("myapp {0}".format(nah))
# Expect that we did print the core body of the ParseError (e.g.
# "no idea what foo is!") and exit 1. (Intent is to display that
# info w/o a full traceback, basically.)
eq_(sys.stderr.getvalue(), "No idea what '{0}' is!\n".format(nah))
mock_exit.assert_called_with(1)
示例8: UnexpectedExit_exits_with_code_when_no_hiding
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def UnexpectedExit_exits_with_code_when_no_hiding(self, mock_exit):
p = Program()
oops = UnexpectedExit(
Result(command="meh", exited=17, hide=tuple())
)
p.execute = Mock(side_effect=oops)
p.run("myapp foo")
# Expect NO repr printed, because stdout/err were not hidden, so we
# don't want to add extra annoying verbosity - we want to be more
# Make-like here.
assert sys.stderr.getvalue() == ""
# But we still exit with expected code (vs e.g. 1 or 0)
mock_exit.assert_called_with(17)
示例9: env_var_prefix_can_be_overridden
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def env_var_prefix_can_be_overridden(self, monkeypatch):
monkeypatch.setenv('MYAPP_RUN_HIDE', 'both')
# This forces the execution stuff, including Executor, to run
# NOTE: it's not really possible to rework the impl so this test is
# cleaner - tasks require per-task/per-collection config, which can
# only be realized at the time a given task is to be executed.
# Unless we overhaul the Program/Executor relationship so Program
# does more of the heavy lifting re: task lookup/load/etc...
# NOTE: check-hide will kaboom if its context's run.hide is not set
# to True (default False).
class MyConf(Config):
env_prefix = 'MYAPP'
p = Program(config_class=MyConf)
p.run('inv -c contextualized check-hide')
示例10: run
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def run(invocation, program=None, invoke=True):
"""
Run ``invocation`` via ``program``, returning output stream captures.
``program`` defaults to ``Program()``.
To skip automatically assuming the argv under test starts with ``"invoke
"``, say ``invoke=False``.
:returns: Two-tuple of ``stdout, stderr`` strings.
"""
if program is None:
program = Program()
if invoke:
invocation = "invoke {}".format(invocation)
program.run(invocation, exit=False)
return sys.stdout.getvalue(), sys.stderr.getvalue()
示例11: uses_a_list_unaltered
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def uses_a_list_unaltered(self):
p = Program()
p.print_version = Mock()
p.run(['inv', '--version'], exit=False)
p.print_version.assert_called()
示例12: _test_flag
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def _test_flag(self, flag, key, value=True):
p = Program()
p.execute = Mock() # neuter
p.run('inv {0} foo'.format(flag))
eq_(p.config.run[key], value)
示例13: splits_a_string
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def splits_a_string(self):
p = Program()
p.print_version = Mock()
p.run("inv --version", exit=False)
p.print_version.assert_called()
示例14: turns_KeyboardInterrupt_into_exit_code_130
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def turns_KeyboardInterrupt_into_exit_code_130(self, mock_exit):
p = Program()
p.execute = Mock(side_effect=KeyboardInterrupt)
p.run("myapp -c foo mytask")
mock_exit.assert_called_with(130)
示例15: main
# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import run [as 别名]
def main():
program = Program(namespace=Collection.from_module(sys.modules[__name__]),
version='0.1.0')
program.run()