#334 Add performance test

This commit is contained in:
nvbn
2015-08-26 14:34:39 +03:00
parent 354ae119c6
commit 7be71a0121
3 changed files with 67 additions and 7 deletions
+10 -7
View File
@@ -8,28 +8,31 @@ import sys
import pexpect
from tests.utils import root
bare = os.environ.get('BARE')
enabled = os.environ.get('FUNCTIONAL')
def build_container(tag, dockerfile):
def build_container(tag, dockerfile, copy_src=False):
tmpdir = mkdtemp()
try:
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
if copy_src:
subprocess.call(['cp', '-a', str(root), tmpdir])
dockerfile_path = Path(tmpdir).joinpath('Dockerfile')
with dockerfile_path.open('w') as file:
file.write(dockerfile)
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
cwd=str(root)) != 0:
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir]) != 0:
raise Exception("Can't build a container")
finally:
shutil.rmtree(tmpdir)
def spawn(request, tag, dockerfile, cmd, install=True):
def spawn(request, tag, dockerfile, cmd, install=True, copy_src=False):
if bare:
proc = pexpect.spawnu(cmd)
else:
tag = 'thefuck/{}'.format(tag)
build_container(tag, dockerfile)
build_container(tag, dockerfile, copy_src)
proc = pexpect.spawnu('docker run --volume {}:/src --tty=true '
'--interactive=true {} {}'.format(root, tag, cmd))
if install:
@@ -39,7 +42,7 @@ def spawn(request, tag, dockerfile, cmd, install=True):
proc.logfile = sys.stdout
request.addfinalizer(proc.terminate)
request.addfinalizer(lambda: proc.terminate(True))
return proc