2019-01-13 11:36:44 +00:00
|
|
|
"""
|
|
|
|
Integration tests found in:
|
|
|
|
- test_cli.py
|
|
|
|
- test_output.py
|
|
|
|
"""
|
|
|
|
|
2018-08-27 11:15:50 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
import pytest_mock
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2019-01-03 08:57:30 +00:00
|
|
|
def Popen(mocker: "pytest_mock.MockFixture"):
|
2018-08-29 07:57:08 +00:00
|
|
|
real_Popen = subprocess.Popen
|
2018-08-27 11:15:50 +00:00
|
|
|
|
2018-08-29 07:57:08 +00:00
|
|
|
def popen_factory(*args, **kwargs):
|
|
|
|
popen = mocker.create_autospec(real_Popen)
|
2018-08-29 08:08:05 +00:00
|
|
|
|
|
|
|
popen.stdin = mocker.mock_open()(os.devnull, "wb")
|
|
|
|
popen.stdout = mocker.mock_open()(os.devnull, "rb")
|
|
|
|
assert popen.stdin != popen.stdout
|
|
|
|
|
2018-08-29 07:57:08 +00:00
|
|
|
popen.wait.return_value = 0
|
|
|
|
return popen
|
2018-08-27 11:15:50 +00:00
|
|
|
|
2019-01-03 08:57:30 +00:00
|
|
|
Popen = mocker.patch.object(subprocess, "Popen", autospec=True)
|
2018-08-29 07:57:08 +00:00
|
|
|
Popen.side_effect = popen_factory
|
2018-08-27 11:15:50 +00:00
|
|
|
yield Popen
|