1
1
import math
2
- from typing import TYPE_CHECKING , Dict , Iterable , Optional , Sequence
2
+ from typing import TYPE_CHECKING , Dict , Iterable , List , Optional , Sequence
3
3
4
4
import pytest
5
5
@@ -36,53 +36,45 @@ def build_req_info(
36
36
@pytest .mark .parametrize (
37
37
"identifier, information, backtrack_causes, user_requested, expected" ,
38
38
[
39
- # Test case for REQUIRES_PYTHON_IDENTIFIER
40
- (
41
- REQUIRES_PYTHON_IDENTIFIER ,
42
- {REQUIRES_PYTHON_IDENTIFIER : [build_req_info ("python" )]},
43
- [],
44
- {},
45
- (False , False , True , True , math .inf , True , REQUIRES_PYTHON_IDENTIFIER ),
46
- ),
47
39
# Pinned package with "=="
48
40
(
49
41
"pinned-package" ,
50
42
{"pinned-package" : [build_req_info ("pinned-package==1.0" )]},
51
43
[],
52
44
{},
53
- (True , False , False , True , math .inf , False , "pinned-package" ),
45
+ (False , False , True , math .inf , False , "pinned-package" ),
54
46
),
55
47
# Package that caused backtracking
56
48
(
57
49
"backtrack-package" ,
58
50
{"backtrack-package" : [build_req_info ("backtrack-package" )]},
59
51
[build_req_info ("backtrack-package" )],
60
52
{},
61
- (True , False , True , False , math .inf , True , "backtrack-package" ),
53
+ (False , True , False , math .inf , True , "backtrack-package" ),
62
54
),
63
55
# Root package requested by user
64
56
(
65
57
"root-package" ,
66
58
{"root-package" : [build_req_info ("root-package" )]},
67
59
[],
68
60
{"root-package" : 1 },
69
- (True , False , True , True , 1 , True , "root-package" ),
61
+ (False , True , True , 1 , True , "root-package" ),
70
62
),
71
63
# Unfree package (with specifier operator)
72
64
(
73
65
"unfree-package" ,
74
66
{"unfree-package" : [build_req_info ("unfree-package<1" )]},
75
67
[],
76
68
{},
77
- (True , False , True , True , math .inf , False , "unfree-package" ),
69
+ (False , True , True , math .inf , False , "unfree-package" ),
78
70
),
79
71
# Free package (no operator)
80
72
(
81
73
"free-package" ,
82
74
{"free-package" : [build_req_info ("free-package" )]},
83
75
[],
84
76
{},
85
- (True , False , True , True , math .inf , True , "free-package" ),
77
+ (False , True , True , math .inf , True , "free-package" ),
86
78
),
87
79
],
88
80
)
@@ -107,3 +99,49 @@ def test_get_preference(
107
99
)
108
100
109
101
assert preference == expected , f"Expected { expected } , got { preference } "
102
+
103
+
104
+ @pytest .mark .parametrize (
105
+ "identifiers, expected" ,
106
+ [
107
+ # Case 1: REQUIRES_PYTHON_IDENTIFIER is present at the beginning
108
+ (
109
+ [REQUIRES_PYTHON_IDENTIFIER , "package1" , "package2" ],
110
+ [REQUIRES_PYTHON_IDENTIFIER ],
111
+ ),
112
+ # Case 2: REQUIRES_PYTHON_IDENTIFIER is present in the middle
113
+ (
114
+ ["package1" , REQUIRES_PYTHON_IDENTIFIER , "package2" ],
115
+ [REQUIRES_PYTHON_IDENTIFIER ],
116
+ ),
117
+ # Case 3: REQUIRES_PYTHON_IDENTIFIER is not present
118
+ (
119
+ ["package1" , "package2" ],
120
+ ["package1" , "package2" ],
121
+ ),
122
+ # Case 4: Empty list of identifiers
123
+ (
124
+ [],
125
+ [],
126
+ ),
127
+ ],
128
+ )
129
+ def test_narrow_requirement_selection (
130
+ identifiers : List [str ],
131
+ expected : List [str ],
132
+ factory : Factory ,
133
+ ) -> None :
134
+ """Test that narrow_requirement_selection correctly prioritizes
135
+ REQUIRES_PYTHON_IDENTIFIER when present in the list of identifiers.
136
+ """
137
+ provider = PipProvider (
138
+ factory = factory ,
139
+ constraints = {},
140
+ ignore_dependencies = False ,
141
+ upgrade_strategy = "to-satisfy-only" ,
142
+ user_requested = {},
143
+ )
144
+
145
+ result = provider .narrow_requirement_selection (identifiers , {}, {}, {}, [])
146
+
147
+ assert list (result ) == expected , f"Expected { expected } , got { list (result )} "
0 commit comments