1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-19 12:24:29 +00:00

39 lines
1004 B
Python
Raw Normal View History

2015-07-24 03:56:21 +03:00
import os
import pytest
from contextlib import contextmanager
import pexpect
import subprocess
import shutil
from tempfile import mkdtemp
from pathlib import Path
root = str(Path(__file__).parent.parent.parent.resolve())
def build_container(tag, dockerfile):
tmpdir = mkdtemp()
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
file.write(dockerfile)
2015-07-24 07:38:45 +03:00
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
cwd=root) != 0:
2015-07-24 03:56:21 +03:00
raise Exception("Can't build container")
shutil.rmtree(tmpdir)
@contextmanager
2015-07-24 07:38:45 +03:00
def spawn(tag, dockerfile):
build_container(tag, dockerfile)
2015-07-24 03:56:21 +03:00
proc = pexpect.spawnu(
2015-07-24 07:38:45 +03:00
'docker run --volume {}:/src --tty=true --interactive=true {}'.format(root, tag))
proc.sendline('pip install /src')
2015-07-24 03:56:21 +03:00
try:
yield proc
finally:
proc.terminate()
functional = pytest.mark.skipif(
not os.environ.get('FUNCTIONAL'),
reason='Functional tests are disabled by default.')