1
- from typing import Dict , List , Optional , Tuple , cast
1
+ from typing import Dict , List , Optional , Set , Tuple , cast
2
2
from unittest import mock
3
3
4
4
import pytest
@@ -103,7 +103,7 @@ def test_new_resolver_get_installation_order(
103
103
104
104
105
105
@pytest .mark .parametrize (
106
- "name, edges, expected_weights" ,
106
+ "name, edges, requirement_keys, expected_weights" ,
107
107
[
108
108
(
109
109
# From https://github.com/pypa/pip/pull/8127#discussion_r414564664
@@ -116,7 +116,8 @@ def test_new_resolver_get_installation_order(
116
116
("three" , "four" ),
117
117
("four" , "five" ),
118
118
],
119
- {None : 0 , "five" : 5 , "four" : 4 , "one" : 4 , "three" : 2 , "two" : 1 },
119
+ {"one" , "two" , "three" , "four" , "five" },
120
+ {"five" : 5 , "four" : 4 , "one" : 4 , "three" : 2 , "two" : 1 },
120
121
),
121
122
(
122
123
"linear" ,
@@ -127,7 +128,20 @@ def test_new_resolver_get_installation_order(
127
128
("three" , "four" ),
128
129
("four" , "five" ),
129
130
],
130
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
131
+ {"one" , "two" , "three" , "four" , "five" },
132
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
133
+ ),
134
+ (
135
+ "linear AND restricted" ,
136
+ [
137
+ (None , "one" ),
138
+ ("one" , "two" ),
139
+ ("two" , "three" ),
140
+ ("three" , "four" ),
141
+ ("four" , "five" ),
142
+ ],
143
+ {"one" , "three" , "five" },
144
+ {"one" : 1 , "three" : 3 , "five" : 5 },
131
145
),
132
146
(
133
147
"linear AND root -> two" ,
@@ -139,7 +153,8 @@ def test_new_resolver_get_installation_order(
139
153
("four" , "five" ),
140
154
(None , "two" ),
141
155
],
142
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
156
+ {"one" , "two" , "three" , "four" , "five" },
157
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
143
158
),
144
159
(
145
160
"linear AND root -> three" ,
@@ -151,7 +166,8 @@ def test_new_resolver_get_installation_order(
151
166
("four" , "five" ),
152
167
(None , "three" ),
153
168
],
154
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
169
+ {"one" , "two" , "three" , "four" , "five" },
170
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
155
171
),
156
172
(
157
173
"linear AND root -> four" ,
@@ -163,7 +179,8 @@ def test_new_resolver_get_installation_order(
163
179
("four" , "five" ),
164
180
(None , "four" ),
165
181
],
166
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
182
+ {"one" , "two" , "three" , "four" , "five" },
183
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
167
184
),
168
185
(
169
186
"linear AND root -> five" ,
@@ -175,7 +192,8 @@ def test_new_resolver_get_installation_order(
175
192
("four" , "five" ),
176
193
(None , "five" ),
177
194
],
178
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
195
+ {"one" , "two" , "three" , "four" , "five" },
196
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
179
197
),
180
198
(
181
199
"linear AND one -> four" ,
@@ -187,7 +205,8 @@ def test_new_resolver_get_installation_order(
187
205
("four" , "five" ),
188
206
("one" , "four" ),
189
207
],
190
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
208
+ {"one" , "two" , "three" , "four" , "five" },
209
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
191
210
),
192
211
(
193
212
"linear AND two -> four" ,
@@ -199,7 +218,8 @@ def test_new_resolver_get_installation_order(
199
218
("four" , "five" ),
200
219
("two" , "four" ),
201
220
],
202
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
221
+ {"one" , "two" , "three" , "four" , "five" },
222
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
203
223
),
204
224
(
205
225
"linear AND four -> one (cycle)" ,
@@ -211,7 +231,8 @@ def test_new_resolver_get_installation_order(
211
231
("four" , "five" ),
212
232
("four" , "one" ),
213
233
],
214
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
234
+ {"one" , "two" , "three" , "four" , "five" },
235
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
215
236
),
216
237
(
217
238
"linear AND four -> two (cycle)" ,
@@ -223,7 +244,8 @@ def test_new_resolver_get_installation_order(
223
244
("four" , "five" ),
224
245
("four" , "two" ),
225
246
],
226
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
247
+ {"one" , "two" , "three" , "four" , "five" },
248
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
227
249
),
228
250
(
229
251
"linear AND four -> three (cycle)" ,
@@ -235,16 +257,44 @@ def test_new_resolver_get_installation_order(
235
257
("four" , "five" ),
236
258
("four" , "three" ),
237
259
],
238
- {None : 0 , "one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
260
+ {"one" , "two" , "three" , "four" , "five" },
261
+ {"one" : 1 , "two" : 2 , "three" : 3 , "four" : 4 , "five" : 5 },
262
+ ),
263
+ (
264
+ "linear AND four -> three (cycle) AND restricted 1-2-3" ,
265
+ [
266
+ (None , "one" ),
267
+ ("one" , "two" ),
268
+ ("two" , "three" ),
269
+ ("three" , "four" ),
270
+ ("four" , "five" ),
271
+ ("four" , "three" ),
272
+ ],
273
+ {"one" , "two" , "three" },
274
+ {"one" : 1 , "two" : 2 , "three" : 3 },
275
+ ),
276
+ (
277
+ "linear AND four -> three (cycle) AND restricted 4-5" ,
278
+ [
279
+ (None , "one" ),
280
+ ("one" , "two" ),
281
+ ("two" , "three" ),
282
+ ("three" , "four" ),
283
+ ("four" , "five" ),
284
+ ("four" , "three" ),
285
+ ],
286
+ {"four" , "five" },
287
+ {"four" : 4 , "five" : 5 },
239
288
),
240
289
],
241
290
)
242
291
def test_new_resolver_topological_weights (
243
292
name : str ,
244
293
edges : List [Tuple [Optional [str ], Optional [str ]]],
294
+ requirement_keys : Set [str ],
245
295
expected_weights : Dict [Optional [str ], int ],
246
296
) -> None :
247
297
graph = _make_graph (edges )
248
298
249
- weights = get_topological_weights (graph , len ( expected_weights ) )
299
+ weights = get_topological_weights (graph , requirement_keys )
250
300
assert weights == expected_weights
0 commit comments