Blame SOURCES/test_pyproject_requirements_txt.py

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