@@ -42,39 +42,31 @@ def build_req_info(
42
42
{"pinned-package" : [build_req_info ("pinned-package==1.0" )]},
43
43
[],
44
44
{},
45
- (False , False , True , math .inf , False , "pinned-package" ),
46
- ),
47
- # Package that caused backtracking
48
- (
49
- "backtrack-package" ,
50
- {"backtrack-package" : [build_req_info ("backtrack-package" )]},
51
- [build_req_info ("backtrack-package" )],
52
- {},
53
- (False , True , False , math .inf , True , "backtrack-package" ),
45
+ (False , False , math .inf , False , "pinned-package" ),
54
46
),
55
47
# Root package requested by user
56
48
(
57
49
"root-package" ,
58
50
{"root-package" : [build_req_info ("root-package" )]},
59
51
[],
60
52
{"root-package" : 1 },
61
- (False , True , True , 1 , True , "root-package" ),
53
+ (False , True , 1 , True , "root-package" ),
62
54
),
63
55
# Unfree package (with specifier operator)
64
56
(
65
57
"unfree-package" ,
66
58
{"unfree-package" : [build_req_info ("unfree-package<1" )]},
67
59
[],
68
60
{},
69
- (False , True , True , math .inf , False , "unfree-package" ),
61
+ (False , True , math .inf , False , "unfree-package" ),
70
62
),
71
63
# Free package (no operator)
72
64
(
73
65
"free-package" ,
74
66
{"free-package" : [build_req_info ("free-package" )]},
75
67
[],
76
68
{},
77
- (False , True , True , math .inf , True , "free-package" ),
69
+ (False , True , math .inf , True , "free-package" ),
78
70
),
79
71
],
80
72
)
@@ -102,37 +94,56 @@ def test_get_preference(
102
94
103
95
104
96
@pytest .mark .parametrize (
105
- "identifiers, expected" ,
97
+ "identifiers, backtrack_causes, expected" ,
106
98
[
107
- # Case 1: REQUIRES_PYTHON_IDENTIFIER is present at the beginning
99
+ # REQUIRES_PYTHON_IDENTIFIER is present
108
100
(
109
- [REQUIRES_PYTHON_IDENTIFIER , "package1" , "package2" ],
101
+ [REQUIRES_PYTHON_IDENTIFIER , "package1" , "package2" , "backtrack-package" ],
102
+ [build_req_info ("backtrack-package" )],
110
103
[REQUIRES_PYTHON_IDENTIFIER ],
111
104
),
112
- # Case 2: REQUIRES_PYTHON_IDENTIFIER is present in the middle
105
+ # REQUIRES_PYTHON_IDENTIFIER is present after backtrack causes
113
106
(
114
- ["package1" , REQUIRES_PYTHON_IDENTIFIER , "package2" ],
107
+ ["package1" , "package2" , "backtrack-package" , REQUIRES_PYTHON_IDENTIFIER ],
108
+ [build_req_info ("backtrack-package" )],
115
109
[REQUIRES_PYTHON_IDENTIFIER ],
116
110
),
117
- # Case 3: REQUIRES_PYTHON_IDENTIFIER is not present
111
+ # Backtrack causes present (direct requirement)
112
+ (
113
+ ["package1" , "package2" , "backtrack-package" ],
114
+ [build_req_info ("backtrack-package" )],
115
+ ["backtrack-package" ],
116
+ ),
117
+ # Multiple backtrack causes
118
+ (
119
+ ["package1" , "backtrack1" , "backtrack2" , "package2" ],
120
+ [build_req_info ("backtrack1" ), build_req_info ("backtrack2" )],
121
+ ["backtrack1" , "backtrack2" ],
122
+ ),
123
+ # No special identifiers - return all
118
124
(
119
125
["package1" , "package2" ],
126
+ [],
120
127
["package1" , "package2" ],
121
128
),
122
- # Case 4: Empty list of identifiers
129
+ # Empty list of identifiers
123
130
(
124
131
[],
125
132
[],
133
+ [],
126
134
),
127
135
],
128
136
)
129
137
def test_narrow_requirement_selection (
130
138
identifiers : List [str ],
139
+ backtrack_causes : Sequence ["PreferenceInformation" ],
131
140
expected : List [str ],
132
141
factory : Factory ,
133
142
) -> None :
134
- """Test that narrow_requirement_selection correctly prioritizes
135
- REQUIRES_PYTHON_IDENTIFIER when present in the list of identifiers.
143
+ """Test that narrow_requirement_selection correctly prioritizes identifiers:
144
+ 1. REQUIRES_PYTHON_IDENTIFIER (if present)
145
+ 2. Backtrack causes (if present)
146
+ 3. All other identifiers (as-is)
136
147
"""
137
148
provider = PipProvider (
138
149
factory = factory ,
@@ -142,6 +153,8 @@ def test_narrow_requirement_selection(
142
153
user_requested = {},
143
154
)
144
155
145
- result = provider .narrow_requirement_selection (identifiers , {}, {}, {}, [])
156
+ result = provider .narrow_requirement_selection (
157
+ identifiers , {}, {}, {}, backtrack_causes
158
+ )
146
159
147
160
assert list (result ) == expected , f"Expected { expected } , got { list (result )} "
0 commit comments