<commit_before>import os
from contextlib import contextmanager
import subprocess
import shutil
from tempfile import mkdtemp
from pathlib import Path
import sys
import pexpect
import pytest

root = str(Path(__file__).parent.parent.parent.resolve())
docker = os.environ.get('DOCKER', 'docker').split(' ')


def build_container(tag, dockerfile):
    tmpdir = mkdtemp()
    with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
        file.write(dockerfile)
    if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
                       cwd=root) != 0:
        raise Exception("Can't build a container")
    shutil.rmtree(tmpdir)


@contextmanager
def spawn(tag, dockerfile):
    tag = 'thefuck/{}'.format(tag)
    build_container(tag, dockerfile)
    proc = pexpect.spawnu(
        'docker run --volume {}:/src --tty=true --interactive=true {}'.format(root, tag))
    proc.logfile = sys.stdout
    proc.sendline('pip install /src')

    try:
        yield proc
    finally:
        proc.terminate()


functional = pytest.mark.skipif(
    not os.environ.get('FUNCTIONAL'),
    reason='Functional tests are disabled by default.')<commit_msg>#N/A Run functional tests in travis-ci<commit_after>import os
from contextlib import contextmanager
import subprocess
import shutil
from tempfile import mkdtemp
from pathlib import Path
import sys
import pexpect
import pytest

root = str(Path(__file__).parent.parent.parent.resolve())
docker = os.environ.get('DOCKER', 'docker')


def build_container(tag, dockerfile):
    tmpdir = mkdtemp()
    with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
        file.write(dockerfile)
    if subprocess.call(
            docker.split(' ') + ['build', '--tag={}'.format(tag), tmpdir],
            cwd=root) != 0:
        raise Exception("Can't build a container")
    shutil.rmtree(tmpdir)


@contextmanager
def spawn(tag, dockerfile):
    tag = 'thefuck/{}'.format(tag)
    build_container(tag, dockerfile)
    proc = pexpect.spawnu(
        '{} run --volume {}:/src --tty=true --interactive=true {}'.format(
            docker, root, tag))
    proc.logfile = sys.stdout
    proc.sendline('pip install /src')

    try:
        yield proc
    finally:
        proc.terminate()


functional = pytest.mark.skipif(
    not os.environ.get('FUNCTIONAL'),
    reason='Functional tests are disabled by default.')
{'fraction_non_alphanumeric': 0.1350780920219502, 'fraction_numerical': 0.0008442380751371887, 'mean_word_length': 3.397031539888683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2068999', 'n_tokens_mistral': 762, 'n_tokens_neox': 739, 'n_words': 186}