Skip to content

Commit b33d475

Browse files
committed
test: check that requirements files with different versions are handled in pipstar
1 parent a836c88 commit b33d475

File tree

1 file changed

+101
-2
lines changed

1 file changed

+101
-2
lines changed

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
load("@rules_testing//lib:test_suite.bzl", "test_suite")
1818
load("//python/private/pypi:parse_requirements.bzl", "parse_requirements", "select_requirement") # buildifier: disable=bzl-visibility
1919
load("//python/private/pypi:pep508_env.bzl", pep508_env = "env") # buildifier: disable=bzl-visibility
20+
load("//python/private/pypi:evaluate_markers.bzl", "evaluate_markers") # buildifier: disable=bzl-visibility
2021

2122
def _mock_ctx():
2223
testdata = {
@@ -65,6 +66,12 @@ foo[extra]==0.0.1 --hash=sha256:deadbeef
6566
"requirements_marker": """\
6667
foo[extra]==0.0.1 ;marker --hash=sha256:deadbeef
6768
bar==0.0.1 --hash=sha256:deadbeef
69+
""",
70+
"requirements_multi_version": """\
71+
foo==0.0.1; python_full_version < '3.10.0' \
72+
--hash=sha256:deadbeef
73+
foo==0.0.2; python_full_version >= '3.10.0' \
74+
--hash=sha256:deadb11f
6875
""",
6976
"requirements_optional_hash": """
7077
foo==0.0.4 @ https://example.org/foo-0.0.4.whl
@@ -587,10 +594,9 @@ def _test_overlapping_shas_with_index_results(env):
587594

588595
env.expect.that_collection(got).contains_exactly([
589596
struct(
590-
name = "foo",
591597
is_exposed = True,
592-
# TODO @aignas 2025-05-25: how do we rename this?
593598
is_multiple_versions = True,
599+
name = "foo",
594600
srcs = [
595601
struct(
596602
distribution = "foo",
@@ -618,6 +624,99 @@ def _test_overlapping_shas_with_index_results(env):
618624

619625
_tests.append(_test_overlapping_shas_with_index_results)
620626

627+
def _test_get_index_urls_different_versions(env):
628+
got = parse_requirements(
629+
ctx = _mock_ctx(),
630+
requirements_by_platform = {
631+
"requirements_multi_version": [
632+
"cp39_linux_x86_64",
633+
"cp310_linux_x86_64",
634+
],
635+
},
636+
platforms = {
637+
"cp310_linux_x86_64": struct(
638+
env = pep508_env(
639+
python_version = "3.9.0",
640+
os = "linux",
641+
arch = "x86_64",
642+
),
643+
whl_abi_tags = ["none"],
644+
whl_platform_tags = ["any"],
645+
),
646+
"cp39_linux_x86_64": struct(
647+
env = pep508_env(
648+
python_version = "3.9.0",
649+
os = "linux",
650+
arch = "x86_64",
651+
),
652+
whl_abi_tags = ["none"],
653+
whl_platform_tags = ["any"],
654+
),
655+
},
656+
get_index_urls = lambda _, __: {
657+
"foo": struct(
658+
sdists = {},
659+
whls = {
660+
"deadb11f": struct(
661+
url = "super2",
662+
sha256 = "deadb11f",
663+
filename = "foo-0.0.2-py3-none-any.whl",
664+
yanked = False,
665+
),
666+
"deadbaaf": struct(
667+
url = "super2",
668+
sha256 = "deadbaaf",
669+
filename = "foo-0.0.1-py3-none-any.whl",
670+
yanked = False,
671+
),
672+
},
673+
),
674+
},
675+
evaluate_markers = lambda _, requirements: evaluate_markers(
676+
requirements = requirements,
677+
platforms = {
678+
"cp39_linux_x86_64": struct(
679+
env = {"python_full_version": "3.9.0"},
680+
),
681+
"cp310_linux_x86_64": struct(
682+
env = {"python_full_version": "3.10.0"},
683+
),
684+
},
685+
)
686+
)
687+
688+
env.expect.that_collection(got).contains_exactly([
689+
struct(
690+
is_exposed = True,
691+
is_multiple_versions = True,
692+
name = "foo",
693+
srcs = [
694+
struct(
695+
distribution = "foo",
696+
extra_pip_args = [],
697+
filename = "",
698+
requirement_line = "foo==0.0.1 --hash=sha256:deadbeef",
699+
sha256 = "",
700+
target_platforms = ["cp39_linux_x86_64"],
701+
url = "",
702+
yanked = False,
703+
),
704+
struct(
705+
distribution = "foo",
706+
extra_pip_args = [],
707+
filename = "foo-0.0.2-py3-none-any.whl",
708+
requirement_line = "foo==0.0.2",
709+
sha256 = "deadb11f",
710+
target_platforms = ["cp310_linux_x86_64"],
711+
url = "super2",
712+
yanked = False,
713+
),
714+
],
715+
),
716+
])
717+
718+
_tests.append(_test_get_index_urls_different_versions)
719+
621720
def parse_requirements_test_suite(name):
622721
"""Create the test suite.
623722

0 commit comments

Comments
 (0)