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


Python Program.execute方法代码示例

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


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

示例1: shows_UnexpectedExit_repr_when_streams_hidden

# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import execute [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)
开发者ID:gtback,项目名称:invoke,代码行数:32,代码来源:program.py

示例2: UnexpectedExit_str_encodes_stdout_and_err

# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import execute [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
开发者ID:offbyone,项目名称:invoke,代码行数:35,代码来源:program.py

示例3: expected_failure_types_dont_raise_exceptions

# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import execute [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)
开发者ID:gyuu,项目名称:invoke,代码行数:13,代码来源:program.py

示例4: UnexpectedExit_exits_with_code_when_no_hiding

# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import execute [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)
开发者ID:miradam,项目名称:invoke,代码行数:15,代码来源:program.py

示例5: _test_flag

# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import execute [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)
开发者ID:gyuu,项目名称:invoke,代码行数:7,代码来源:program.py

示例6: turns_KeyboardInterrupt_into_exit_code_130

# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import execute [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)
开发者ID:KuangEleven,项目名称:invoke,代码行数:7,代码来源:program.py

示例7: _test_flag

# 需要导入模块: from invoke import Program [as 别名]
# 或者: from invoke.Program import execute [as 别名]
 def _test_flag(self, flag, key, value=True):
     p = Program()
     p.execute = Mock()  # neuter
     p.run("inv {} foo".format(flag))
     assert p.config.run[key] == value
开发者ID:miradam,项目名称:invoke,代码行数:7,代码来源:program.py


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