Blame test_pyproject_requirements_txt.py

aeb21f6
from pathlib import Path
aeb21f6
from textwrap import dedent
aeb21f6
aeb21f6
from pyproject_requirements_txt import convert_requirements_txt
aeb21f6
aeb21f6
aeb21f6
def test_requirements_add_pkgname():
aeb21f6
    reqs_txt = dedent(r"""
aeb21f6
        good@git+https://github.com/monty/spam.git@master#egg=bad
aeb21f6
        git+https://github.com/monty/spam.git@master#egg=ugly
aeb21f6
        https://example.com/undead.tar.gz#egg=undead ; python_version > 3.0
aeb21f6
    """)
aeb21f6
    result = convert_requirements_txt(reqs_txt.splitlines())
aeb21f6
aeb21f6
    expected = [
aeb21f6
        'good@git+https://github.com/monty/spam.git@master#egg=bad',
aeb21f6
        'ugly@git+https://github.com/monty/spam.git@master#egg=ugly',
aeb21f6
        'undead@https://example.com/undead.tar.gz#egg=undead ; python_version > 3.0',
aeb21f6
    ]
aeb21f6
    assert result == expected
aeb21f6
aeb21f6
aeb21f6
def test_requirements_preprocess(monkeypatch):
aeb21f6
    reqs_txt = dedent(r"""
aeb21f6
        Normal_Req ~= 1.2.0
aeb21f6
           whitespace-stripped < 3    <END>
aeb21f6
aeb21f6
        # indentation is preserved in continuations:
aeb21f6
        foo <=\
aeb21f6
            30
aeb21f6
        bar<=   \
aeb21f6
        30
aeb21f6
        # names and operators can be split:
aeb21f6
        this-was-\
aeb21f6
        too-long<\
aeb21f6
        =30  
aeb21f6
aeb21f6
        # this is not a multi-line comment \
aeb21f6
        some-dep
aeb21f6
             # neither is this \
aeb21f6
        other-dep
aeb21f6
        another-dep  # but this *is* a multi-line coment \
aeb21f6
        so any garbage can be here
aeb21f6
        dep-a # and this comment ends with the blank line below \
aeb21f6
aeb21f6
        dep-b
aeb21f6
        ${ENVVAR}
aeb21f6
        whitespace-stripped-before-substitution   ${SPACE}
aeb21f6
        ${MISSING_ENVVAR}
aeb21f6
    """.replace('<END>', ''))
aeb21f6
    monkeypatch.setenv('ENVVAR', 'package-from-env')
aeb21f6
    monkeypatch.setenv('SPACE', ' ')
aeb21f6
    monkeypatch.delenv('MISSING_ENVVAR', raising=False)
aeb21f6
    result = convert_requirements_txt(reqs_txt.splitlines())
aeb21f6
aeb21f6
    expected = [
aeb21f6
        'Normal_Req ~= 1.2.0',
aeb21f6
        'whitespace-stripped < 3',
aeb21f6
        'foo <=    30',
aeb21f6
        'bar<=   30',
aeb21f6
        'this-was-too-long<=30',
aeb21f6
        'some-dep',
aeb21f6
        'other-dep',
aeb21f6
        'another-dep',
aeb21f6
        'dep-a',
aeb21f6
        'dep-b',
aeb21f6
        'package-from-env',
aeb21f6
        'whitespace-stripped-before-substitution    ',
aeb21f6
        '${MISSING_ENVVAR}',
aeb21f6
    ]
aeb21f6
    #result = expected
aeb21f6
    assert result == expected
aeb21f6
aeb21f6
    # This test uses pip internals, so it might break in the future.
aeb21f6
    from pip._internal.req.req_file import preprocess
aeb21f6
    expected = [line for lineno, line in preprocess(reqs_txt)]
aeb21f6
    assert result == expected
aeb21f6