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


Python MockPopen.set_command方法代码示例

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


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

示例1: test_invalid_method_or_attr

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_invalid_method_or_attr(self):
     Popen = MockPopen()
     Popen.set_command('command')
     process = Popen('command')
     with ShouldRaise(
             AttributeError("Mock object has no attribute 'foo'")):
         process.foo()
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:9,代码来源:test_popen.py

示例2: test_job

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
def test_job():
    Popen = MockPopen()
    Popen.set_command('top', stdout=b'o', stderr=b'e', returncode=1, pid=1000)
    process = Popen('top', stdout=b'o', stderr=b'e', shell=True)
    process.wait()
    execute.kill_job(process)
    assert process.returncode == 1
开发者ID:rapid7,项目名称:lockex,代码行数:9,代码来源:test_job.py

示例3: test_pass_executable

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_pass_executable(self):
     Popen = MockPopen()
     Popen.set_command('a command', b'a', returncode=1)
     Popen('a command', executable='/foo/bar')
     compare(Popen.all_calls, expected=[
         call.Popen('a command', executable='/foo/bar')
     ])
开发者ID:Simplistix,项目名称:testfixtures,代码行数:9,代码来源:test_popen.py

示例4: setup_git_popen

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
class TestGitPopenMockupMixin:
    def setup_git_popen(self):
        # repository mockup (in a temporary place)
        self.repository = Repo.init(self.tempdir.name)
        # setup git command mockup
        self.Popen = MockPopen()
        def FixPopen(*a, **k):
            if 'start_new_session' in k:
                del k['start_new_session']
            return self.Popen.Popen(*a, **k)
        self.Popen.mock.Popen.side_effect = FixPopen
        self.Popen.mock.Popen_instance.stdin = None
        self.Popen.mock.Popen_instance.wait = lambda *a, **k: self.Popen.wait()
        self.Popen.mock.Popen_instance.__enter__ = lambda self: self
        self.Popen.mock.Popen_instance.__exit__ = lambda self, *a, **k: None

    def set_mock_popen_commands(self, cmd_list):
        for cmd, out, err, rc in cmd_list:
            self.Popen.set_command(cmd, out, err, returncode=rc)

    def mockup_git(self, namespace, repository, url=None):
        # disable refspec check
        from git import remote
        remote.Remote._assert_refspec = lambda self: None
        # write FETCH_HEAD ref
        with open(os.path.join(self.repository.git_dir, 'FETCH_HEAD'), 'w') as f:
            url = url or "{}:{}/{}".format(self.service.fqdn, namespace, repository)
            f.write("749656b8b3b282d11a4221bb84e48291ca23ecc6" \
                    "		branch 'master' of {}".format(url))
        return Replace('git.cmd.Popen', self.Popen)
开发者ID:guyzmo,项目名称:git-repo,代码行数:32,代码来源:helpers.py

示例5: TestCommandTaskWithMockPopen

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
class TestCommandTaskWithMockPopen(MockLoggerMixin, unittest.TestCase):
    """ Run command tasks with a mocked popen """

    def setUp(self):
        self.global_config = BaseGlobalConfig()
        self.project_config = BaseProjectConfig(
            self.global_config, config={"noyaml": True}
        )
        self.task_config = TaskConfig()

        self._task_log_handler.reset()
        self.task_log = self._task_log_handler.messages

        self.Popen = MockPopen()
        self.r = Replacer()
        self.r.replace("cumulusci.tasks.command.subprocess.Popen", self.Popen)
        self.addCleanup(self.r.restore)

    def test_functional_mock_command(self):
        """ Functional test that runs a command with mocked
        popen results and checks the log.
        """

        self.task_config.config["options"] = {"command": "ls -la"}

        self.Popen.set_command("ls -la", stdout=b"testing testing 123", stderr=b"e")

        task = Command(self.project_config, self.task_config)
        task()

        self.assertTrue(any("testing testing" in s for s in self.task_log["info"]))
开发者ID:SalesforceFoundation,项目名称:CumulusCI,代码行数:33,代码来源:test_command.py

示例6: test_invalid_terminate

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_invalid_terminate(self):
     Popen = MockPopen()
     Popen.set_command('bar')
     process = Popen('bar')
     with ShouldRaise(TypeError(
             "terminate() got an unexpected keyword argument 'foo'"
     )):
         process.terminate(foo='bar')
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:10,代码来源:test_popen.py

示例7: test_read_from_stdout_with_stderr_redirected_check_stdout_contents

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_read_from_stdout_with_stderr_redirected_check_stdout_contents(self):
     # setup
     Popen = MockPopen()
     Popen.set_command('a command', stdout=b'foo', stderr=b'bar')
     # usage
     process = Popen('a command', stdout=PIPE, stderr=STDOUT, shell=True)
     # test stdout contents
     compare(b'foobar', process.stdout.read())
     compare(process.stderr, None)
开发者ID:Simplistix,项目名称:testfixtures,代码行数:11,代码来源:test_popen.py

示例8: test_read_from_stdout_with_stderr_redirected_check_stdout_stderr_interleaved

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_read_from_stdout_with_stderr_redirected_check_stdout_stderr_interleaved(self):
     # setup
     Popen = MockPopen()
     Popen.set_command('a command', stdout=b'o1\no2\no3\no4\n', stderr=b'e1\ne2\n')
     # usage
     process = Popen('a command', stdout=PIPE, stderr=STDOUT, shell=True)
     self.assertTrue(isinstance(process.stdout.fileno(), int))
     # test stdout contents
     compare(b'o1\ne1\no2\ne2\no3\no4\n', process.stdout.read())
开发者ID:Simplistix,项目名称:testfixtures,代码行数:11,代码来源:test_popen.py

示例9: test_read_from_stderr

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_read_from_stderr(self):
     # setup
     Popen = MockPopen()
     Popen.set_command("a command", stderr=b"foo")
     # usage
     process = Popen("a command", stdout=PIPE, stderr=PIPE, shell=True)
     self.assertTrue(isinstance(process.stdout.fileno(), int))
     compare(process.stderr.read(), b"foo")
     # test call list
     compare([call.Popen("a command", shell=True, stderr=-1, stdout=-1)], Popen.mock.method_calls)
开发者ID:Simplistix,项目名称:testfixtures,代码行数:12,代码来源:test_popen.py

示例10: test_command_is_sequence

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
    def test_command_is_sequence(self):
        Popen = MockPopen()
        Popen.set_command("a command")

        process = Popen(["a", "command"], stdout=PIPE, stderr=PIPE)

        compare(process.wait(), 0)
        compare(
            [call.Popen(["a", "command"], stderr=-1, stdout=-1), call.Popen_instance.wait()], Popen.mock.method_calls
        )
开发者ID:Simplistix,项目名称:testfixtures,代码行数:12,代码来源:test_popen.py

示例11: test_communicate_with_stderr_redirected_check_stderr_is_none

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_communicate_with_stderr_redirected_check_stderr_is_none(self):
     # setup
     Popen = MockPopen()
     Popen.set_command('a command', stdout=b'foo', stderr=b'bar')
     # usage
     process = Popen('a command', stdout=PIPE, stderr=STDOUT, shell=True)
     out, err = process.communicate()
     # test stderr is None
     compare(out, b'foobar')
     compare(err, None)
开发者ID:Simplistix,项目名称:testfixtures,代码行数:12,代码来源:test_popen.py

示例12: test_read_from_stdout_and_stderr

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_read_from_stdout_and_stderr(self):
     # setup
     Popen = MockPopen()
     Popen.set_command("a command", stdout=b"foo", stderr=b"bar")
     # usage
     process = Popen("a command", stdout=PIPE, stderr=PIPE, shell=True)
     compare(process.stdout.read(), b"foo")
     compare(process.stderr.read(), b"bar")
     # test call list
     compare([call.Popen("a command", shell=True, stderr=PIPE, stdout=PIPE)], Popen.mock.method_calls)
开发者ID:Simplistix,项目名称:testfixtures,代码行数:12,代码来源:test_popen.py

示例13: test_invalid_poll

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_invalid_poll(self):
     Popen = MockPopen()
     Popen.set_command('bar')
     process = Popen('bar')
     if PY2:
         text = 'poll() takes exactly 1 argument (2 given)'
     else:
         text = 'poll() takes 1 positional argument but 2 were given'
     with ShouldRaise(TypeError(text)):
         process.poll('moo')
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:12,代码来源:test_popen.py

示例14: test_start_new_session

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_start_new_session(self):
     # setup
     Popen = MockPopen()
     Popen.set_command('a command')
     # usage
     Popen('a command', start_new_session=True)
     # test call list
     compare([
         call.Popen('a command', start_new_session=True),
     ], Popen.mock.method_calls)
开发者ID:Simplistix,项目名称:testfixtures,代码行数:12,代码来源:test_popen.py

示例15: test_terminate

# 需要导入模块: from testfixtures.popen import MockPopen [as 别名]
# 或者: from testfixtures.popen.MockPopen import set_command [as 别名]
 def test_terminate(self):
     # setup
     Popen = MockPopen()
     Popen.set_command("a command")
     # usage
     process = Popen("a command", stdout=PIPE, stderr=PIPE, shell=True)
     process.terminate()
     # result checking
     compare(
         [call.Popen("a command", shell=True, stderr=-1, stdout=-1), call.Popen_instance.terminate()],
         Popen.mock.method_calls,
     )
开发者ID:Simplistix,项目名称:testfixtures,代码行数:14,代码来源:test_popen.py


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