Blame SOURCES/test_pyproject_requirements_txt.py

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