本文整理汇总了Python中testfixtures.popen.MockPopen类的典型用法代码示例。如果您正苦于以下问题:Python MockPopen类的具体用法?Python MockPopen怎么用?Python MockPopen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockPopen类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setup_git_popen
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,代码行数:30,代码来源:helpers.py
示例2: TestCommandTaskWithMockPopen
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,代码行数:31,代码来源:test_command.py
示例3: test_pass_executable
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,代码行数:7,代码来源:test_popen.py
示例4: test_job
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,代码行数:7,代码来源:test_job.py
示例5: test_invalid_method_or_attr
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,代码行数:7,代码来源:test_popen.py
示例6: test_invalid_terminate
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,代码行数:8,代码来源:test_popen.py
示例7: test_read_from_stdout_with_stderr_redirected_check_stdout_contents
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,代码行数:9,代码来源:test_popen.py
示例8: test_read_from_stdout_with_stderr_redirected_check_stdout_stderr_interleaved
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,代码行数:9,代码来源:test_popen.py
示例9: test_read_from_stderr
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,代码行数:10,代码来源:test_popen.py
示例10: test_command_is_sequence
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,代码行数:10,代码来源:test_popen.py
示例11: test_invalid_poll
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:Simplistix,项目名称:testfixtures,代码行数:10,代码来源:test_popen.py
示例12: test_read_from_stdout_and_stderr
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,代码行数:10,代码来源:test_popen.py
示例13: test_start_new_session
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,代码行数:10,代码来源:test_popen.py
示例14: test_communicate_with_stderr_redirected_check_stderr_is_none
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,代码行数:10,代码来源:test_popen.py
示例15: test_wait_and_return_code
def test_wait_and_return_code(self):
# setup
Popen = MockPopen()
Popen.set_command("a command", returncode=3)
# usage
process = Popen("a command")
compare(process.returncode, None)
# result checking
compare(process.wait(), 3)
compare(process.returncode, 3)
# test call list
compare([call.Popen("a command"), call.Popen_instance.wait()], Popen.mock.method_calls)
开发者ID:Simplistix,项目名称:testfixtures,代码行数:12,代码来源:test_popen.py
示例16: test_terminate
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,代码行数:12,代码来源:test_popen.py
示例17: test_read_from_stdout_and_stderr
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:Alexhuszagh,项目名称:XLDiscoverer,代码行数:12,代码来源:test_popen.py
示例18: test_sprocess_safe_wait_and_return_code
def test_sprocess_safe_wait_and_return_code(self):
command = "a command"
Popen = MockPopen()
Popen.set_command(command, returncode=3)
process = Popen(command)
compare(process.returncode, None)
compare(process.wait(), 3)
compare(process.returncode, 3)
compare([
call.Popen(command),
call.Popen_instance.wait(),
], Popen.mock.method_calls)
开发者ID:dpmatthews,项目名称:cylc,代码行数:12,代码来源:test_cylc_subproc.py
示例19: test_kill
def test_kill(self):
# setup
Popen = MockPopen()
Popen.set_command('a command')
# usage
process = Popen('a command', stdout=PIPE, stderr=PIPE, shell=True)
process.kill()
# result checking
compare([
call.Popen('a command', shell=True, stderr=-1, stdout=-1),
call.Popen_instance.kill(),
], Popen.mock.method_calls)
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:12,代码来源:test_popen.py
示例20: test_write_to_stdin
def test_write_to_stdin(self):
# setup
Popen = MockPopen()
Popen.set_command('a command')
# usage
process = Popen('a command', stdin=PIPE, shell=True)
process.stdin.write('some text')
# test call list
compare([
call.Popen('a command', shell=True, stdin=PIPE),
call.Popen_instance.stdin.write('some text'),
], Popen.mock.method_calls)
开发者ID:nebulans,项目名称:testfixtures,代码行数:12,代码来源:test_popen.py
注:本文中的testfixtures.popen.MockPopen类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论