summaryrefslogtreecommitdiff
path: root/test_pyproject_requirements_txt.py
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-03-23 02:28:22 +0000
committerCoprDistGit <infra@openeuler.org>2023-03-23 02:28:22 +0000
commit6d8e39fe5ab063ff2a4c2a918cb6ad5b5d4aec45 (patch)
treebd5138cc2ba1ebbbdbc52bd269b506114f8caa12 /test_pyproject_requirements_txt.py
parentb0e529d9a17eaf6cc3ff98b78de743e401913baf (diff)
automatic import of pyproject-rpm-macros
Diffstat (limited to 'test_pyproject_requirements_txt.py')
-rw-r--r--test_pyproject_requirements_txt.py78
1 files changed, 78 insertions, 0 deletions
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 <END>
+
+ # 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('<END>', ''))
+ 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
+