Exemple #1
0
def test_subprocess(tempdir, stdin):
    """Test by calling flake8 through subprocess using a dedicated python process.

    :param tempdir: conftest fixture.
    :param str stdin: Pipe this file to stdin of flake8.
    """
    # Prepare.
    cwd = str(tempdir.join('empty' if stdin else ''))
    stdin_handle = tempdir.join(stdin).open() if stdin else None

    # Execute.
    command = [find_executable('flake8'), '--exit-zero', '-' if stdin else '.']
    environ = os.environ.copy()
    environ['COV_CORE_DATAFILE'] = ''  # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
    out = check_output(command, stderr=STDOUT, cwd=cwd, stdin=stdin_handle, env=environ).decode('utf-8')

    # Clean.
    if stdin:
        expected = '\n'.join('stdin:' + l.split(':', 1)[-1] for l in EXPECTED.splitlines() if stdin in l)
    elif os.name == 'nt':
        expected = EXPECTED.replace('./sample', r'.\sample')
    else:
        expected = EXPECTED
    out = '\n'.join(l.rstrip() for l in out.splitlines())

    assert out == expected
Exemple #2
0
def test_subprocess(tempdir, stdin, which_cfg):
    """Test by calling flake8 through subprocess using a dedicated python process.

    :param tempdir: conftest fixture.
    :param str stdin: Pipe this file to stdin of flake8.
    :param str which_cfg: Which config file to test with.
    """
    # Prepare.
    cwd = str(tempdir.join('empty' if stdin else ''))
    stdin_handle = tempdir.join(stdin).open() if stdin else None

    # Write configuration.
    cfg = which_cfg.split()
    section = cfg[1] if len(cfg) > 1 else 'pep257'
    key = 'show-pep257' if section == 'flake8' else 'explain'
    tempdir.join('empty' if stdin else '', cfg[0]).write('[{0}]\n{1} = True\n'.format(section, key))

    # Execute.
    command = [find_executable('flake8'), '--exit-zero', '-' if stdin else '.']
    environ = os.environ.copy()
    environ['COV_CORE_DATAFILE'] = ''  # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
    out = check_output(command, stderr=STDOUT, cwd=cwd, stdin=stdin_handle, env=environ).decode('utf-8')

    # Clean.
    if stdin:
        expected = EXPECTED[0 if stdin == 'sample.py' else 1].replace('./{0}:'.format(stdin), 'stdin:')
    elif os.name == 'nt':
        expected = '\n'.join(EXPECTED).replace('./sample', r'.\sample')
    else:
        expected = '\n'.join(EXPECTED)
    out = '\n'.join(l.rstrip() for l in out.splitlines())

    assert out == expected
Exemple #3
0
def test_subprocess(tempdir, stdin):
    """Test by calling flake8 through subprocess using a dedicated python process.

    :param tempdir: conftest fixture.
    :param str stdin: Pipe this file to stdin of flake8.
    """
    # Prepare.
    cwd = str(tempdir.join('empty' if stdin else ''))
    stdin_handle = tempdir.join(stdin).open() if stdin else None

    # Execute.
    command = [find_executable('flake8'), '--exit-zero', '-' if stdin else '.']
    environ = os.environ.copy()
    environ[
        'COV_CORE_DATAFILE'] = ''  # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
    out = check_output(command,
                       stderr=STDOUT,
                       cwd=cwd,
                       stdin=stdin_handle,
                       env=environ).decode('utf-8')

    # Clean.
    if stdin:
        expected = '\n'.join('stdin:' + l.split(':', 1)[-1]
                             for l in EXPECTED.splitlines() if stdin in l)
    elif os.name == 'nt':
        expected = EXPECTED.replace('./sample', r'.\sample')
    else:
        expected = EXPECTED
    out = '\n'.join(l.rstrip() for l in out.splitlines())

    assert out == expected
Exemple #4
0
def test_subprocess(tempdir, ignore, stdin, which_cfg):
    """Test by calling flake8 through subprocess using a dedicated python process.

    :param tempdir: conftest fixture.
    :param str ignore: Config value for ignore option.
    :param str stdin: Pipe this file to stdin of flake8.
    :param str which_cfg: Which config file to test with.
    """
    # Prepare.
    cwd = str(tempdir.join("empty" if stdin else ""))
    stdin_handle = tempdir.join(stdin).open() if stdin else None

    # Write configuration.
    cfg = which_cfg.split()
    section = cfg[1] if len(cfg) > 1 else "pep257"
    tempdir.join("empty" if stdin else "", cfg[0]).write("[{0}]\nignore = {1}\n".format(section, ignore))

    # Execute.
    command = [find_executable("flake8"), "--exit-zero", "-" if stdin else "."]
    environ = os.environ.copy()
    environ["COV_CORE_DATAFILE"] = ""  # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
    out = check_output(command, stderr=STDOUT, cwd=cwd, stdin=stdin_handle, env=environ).decode("utf-8")

    # Clean.
    if stdin:
        expected = "\n".join("stdin:" + l.split(":", 1)[-1] for l in EXPECTED.splitlines() if stdin in l)
    elif os.name == "nt":
        expected = EXPECTED.replace("./sample", r".\sample")
    else:
        expected = EXPECTED
    out = "\n".join(l.rstrip() for l in out.splitlines())

    assert out == expected
Exemple #5
0
def test_subprocess(tempdir, stdin, which_cfg):
    """Test by calling flake8 through subprocess using a dedicated python process.

    :param tempdir: conftest fixture.
    :param str stdin: Pipe this file to stdin of flake8.
    :param str which_cfg: Which config file to test with.
    """
    # Prepare.
    cwd = str(tempdir.join('empty' if stdin else ''))
    stdin_handle = tempdir.join(stdin).open() if stdin else None

    # Write configuration.
    cfg = which_cfg.split()
    section = cfg[1] if len(cfg) > 1 else 'pep257'
    key = 'show-pep257' if section == 'flake8' else 'explain'
    tempdir.join('empty' if stdin else '',
                 cfg[0]).write('[{0}]\n{1} = True\n'.format(section, key))

    # Execute.
    command = [find_executable('flake8'), '--exit-zero', '-' if stdin else '.']
    environ = os.environ.copy()
    environ[
        'COV_CORE_DATAFILE'] = ''  # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
    out = check_output(command,
                       stderr=STDOUT,
                       cwd=cwd,
                       stdin=stdin_handle,
                       env=environ).decode('utf-8')

    # Clean.
    if stdin:
        expected = EXPECTED[0 if stdin == 'sample.py' else 1].replace(
            './{0}:'.format(stdin), 'stdin:')
    elif os.name == 'nt':
        expected = '\n'.join(EXPECTED).replace('./sample', r'.\sample')
    else:
        expected = '\n'.join(EXPECTED)
    out = '\n'.join(l.rstrip() for l in out.splitlines())

    assert out == expected