From 6d8e39fe5ab063ff2a4c2a918cb6ad5b5d4aec45 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Thu, 23 Mar 2023 02:28:22 +0000 Subject: automatic import of pyproject-rpm-macros --- test_pyproject_requirements_txt.py | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test_pyproject_requirements_txt.py (limited to 'test_pyproject_requirements_txt.py') diff --git a/test_pyproject_requirements_txt.py b/test_pyproject_requirements_txt.py new file mode 100644 index 0000000..4ac89ff --- /dev/null +++ b/test_pyproject_requirements_txt.py @@ -0,0 +1,78 @@ +from pathlib import Path +from textwrap import dedent + +from pyproject_requirements_txt import convert_requirements_txt + + +def test_requirements_add_pkgname(): + reqs_txt = dedent(r""" + good@git+https://github.com/monty/spam.git@master#egg=bad + git+https://github.com/monty/spam.git@master#egg=ugly + https://example.com/undead.tar.gz#egg=undead ; python_version > 3.0 + """) + result = convert_requirements_txt(reqs_txt.splitlines()) + + expected = [ + 'good@git+https://github.com/monty/spam.git@master#egg=bad', + 'ugly@git+https://github.com/monty/spam.git@master#egg=ugly', + 'undead@https://example.com/undead.tar.gz#egg=undead ; python_version > 3.0', + ] + assert result == expected + + +def test_requirements_preprocess(monkeypatch): + reqs_txt = dedent(r""" + Normal_Req ~= 1.2.0 + whitespace-stripped < 3 + + # indentation is preserved in continuations: + foo <=\ + 30 + bar<= \ + 30 + # names and operators can be split: + this-was-\ + too-long<\ + =30 + + # this is not a multi-line comment \ + some-dep + # neither is this \ + other-dep + another-dep # but this *is* a multi-line coment \ + so any garbage can be here + dep-a # and this comment ends with the blank line below \ + + dep-b + ${ENVVAR} + whitespace-stripped-before-substitution ${SPACE} + ${MISSING_ENVVAR} + """.replace('', '')) + monkeypatch.setenv('ENVVAR', 'package-from-env') + monkeypatch.setenv('SPACE', ' ') + monkeypatch.delenv('MISSING_ENVVAR', raising=False) + result = convert_requirements_txt(reqs_txt.splitlines()) + + expected = [ + 'Normal_Req ~= 1.2.0', + 'whitespace-stripped < 3', + 'foo <= 30', + 'bar<= 30', + 'this-was-too-long<=30', + 'some-dep', + 'other-dep', + 'another-dep', + 'dep-a', + 'dep-b', + 'package-from-env', + 'whitespace-stripped-before-substitution ', + '${MISSING_ENVVAR}', + ] + #result = expected + assert result == expected + + # This test uses pip internals, so it might break in the future. + from pip._internal.req.req_file import preprocess + expected = [line for lineno, line in preprocess(reqs_txt)] + assert result == expected + -- cgit v1.2.3