Example #1
0
def writer(tmpdir_cwd):
    with open("src_file", "w"), open("src_file2", "w"):
        pass

    cli_args = [
        "--dry-run",
        "--output-file",
        "requirements.txt",
        "src_file",
        "src_file2",
    ]

    with cli.make_context("pip-compile", cli_args) as ctx:
        writer = OutputWriter(
            src_files=["src_file", "src_file2"],
            dst_file=ctx.params["output_file"],
            click_ctx=ctx,
            dry_run=True,
            emit_header=True,
            emit_index=True,
            emit_trusted_host=True,
            annotate=True,
            generate_hashes=False,
            default_index_url=None,
            index_urls=[],
            trusted_hosts=[],
            format_control=FormatControl(set(), set()),
            allow_unsafe=False,
            find_links=[],
            emit_find_links=True,
        )
        yield writer
Example #2
0
def test_iter_lines__unsafe_dependencies(from_line, allow_unsafe):

    writer = OutputWriter(
        src_files=["src_file", "src_file2"], dst_file="dst_file",
        dry_run=True,
        emit_header=True, emit_index=True, emit_trusted_host=True,
        annotate=True,
        generate_hashes=False,
        default_index_url=None, index_urls=[],
        trusted_hosts=[],
        format_control=FormatControl(set(), set()),
        allow_unsafe=allow_unsafe,
    )

    ireq = [from_line('test==1.2')]
    unsafe_req = [from_line('setuptools')]
    reverse_dependencies = {'test': ['xyz']}

    str_lines = list(writer._iter_lines(
        ireq,
        unsafe_req,
        reverse_dependencies,
        ['test'],
        {},
        None,
    ))
    assert comment('# The following packages are considered to be unsafe in a requirements file:') in str_lines
    if allow_unsafe:
        assert 'setuptools' in str_lines
    else:
        assert comment('# setuptools') in str_lines
    assert 'test==1.2' in str_lines
Example #3
0
def writer():
    return OutputWriter(src_files=["src_file", "src_file2"], dst_file="dst_file",
                        dry_run=True,
                        emit_header=True, emit_index=True, emit_trusted_host=True,
                        annotate=True,
                        generate_hashes=False,
                        default_index_url=None, index_urls=[],
                        trusted_hosts=[],
                        format_control=FormatControl(set(), set()),
                        allow_unsafe=False)
Example #4
0
def test_write_format_controls(writer):
    """
    Tests --no-binary/--only-binary options.
    """

    writer.format_control = FormatControl(no_binary=["psycopg2", "click"],
                                          only_binary=["pytz", "django"])
    lines = list(writer.write_format_controls())

    assert "--no-binary psycopg2" in lines
    assert "--no-binary click" in lines

    assert "--only-binary pytz" in lines
    assert "--only-binary django" in lines
def test_write_format_controls(writer):
    """
    Tests --no-binary/--only-binary options.
    """

    writer.format_control = FormatControl(no_binary=['psycopg2', 'click'],
                                          only_binary=['pytz', 'django'])
    lines = list(writer.write_format_controls())

    assert '--no-binary psycopg2' in lines
    assert '--no-binary click' in lines

    assert '--only-binary pytz' in lines
    assert '--only-binary django' in lines