-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
test_solver.py
3795 lines (3006 loc) · 112 KB
/
test_solver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
import pytest
from cleo.io.buffered_io import BufferedIO
from cleo.io.null_io import NullIO
from packaging.utils import canonicalize_name
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.core.version.markers import parse_marker
from poetry.factory import Factory
from poetry.packages import DependencyPackage
from poetry.puzzle import Solver
from poetry.puzzle.exceptions import SolverProblemError
from poetry.repositories.pool import Pool
from poetry.repositories.repository import Repository
from poetry.utils.env import MockEnv
from tests.helpers import MOCK_DEFAULT_GIT_REVISION
from tests.helpers import get_dependency
from tests.helpers import get_package
from tests.repositories.test_legacy_repository import (
MockRepository as MockLegacyRepository,
)
from tests.repositories.test_pypi_repository import MockRepository as MockPyPIRepository
if TYPE_CHECKING:
import httpretty
from pytest_mock import MockerFixture
from poetry.installation.operations.operation import Operation
from poetry.puzzle.provider import Provider
from poetry.puzzle.transaction import Transaction
DEFAULT_SOURCE_REF = (
VCSDependency("poetry", "git", "[email protected]:python-poetry/poetry.git").branch
or "HEAD"
)
def set_package_python_versions(provider: Provider, python_versions: str) -> None:
provider._package.python_versions = python_versions
provider._python_constraint = provider._package.python_constraint
@pytest.fixture()
def io() -> NullIO:
return NullIO()
@pytest.fixture()
def package() -> ProjectPackage:
return ProjectPackage("root", "1.0")
@pytest.fixture()
def repo() -> Repository:
return Repository("repo")
@pytest.fixture()
def pool(repo: Repository) -> Pool:
return Pool([repo])
@pytest.fixture()
def solver(package: ProjectPackage, pool: Pool, io: NullIO) -> Solver:
return Solver(package, pool, [], [], io)
def check_solver_result(
transaction: Transaction,
expected: list[dict[str, Any]],
synchronize: bool = False,
) -> list[Operation]:
for e in expected:
if "skipped" not in e:
e["skipped"] = False
result = []
ops = transaction.calculate_operations(synchronize=synchronize)
for op in ops:
if op.job_type == "update":
result.append(
{
"job": "update",
"from": op.initial_package,
"to": op.target_package,
"skipped": op.skipped,
}
)
else:
job = "install"
if op.job_type == "uninstall":
job = "remove"
result.append({"job": job, "package": op.package, "skipped": op.skipped})
assert result == expected
return ops
def test_solver_install_single(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
repo.add_package(package_a)
transaction = solver.solve([get_dependency("A").name])
check_solver_result(transaction, [{"job": "install", "package": package_a}])
def test_solver_remove_if_no_longer_locked(
package: ProjectPackage, pool: Pool, io: NullIO
):
package_a = get_package("A", "1.0")
solver = Solver(package, pool, [package_a], [package_a], io)
transaction = solver.solve()
check_solver_result(transaction, [{"job": "remove", "package": package_a}])
def test_remove_non_installed(
package: ProjectPackage, repo: Repository, pool: Pool, io: NullIO
):
package_a = get_package("A", "1.0")
repo.add_package(package_a)
solver = Solver(package, pool, [], [package_a], io)
transaction = solver.solve([])
check_solver_result(transaction, [])
def test_install_non_existing_package_fail(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("B", "1"))
package_a = get_package("A", "1.0")
repo.add_package(package_a)
with pytest.raises(SolverProblemError):
solver.solve()
def test_install_unpublished_package_does_not_fail(
package: ProjectPackage, repo: Repository, pool: Pool, io: NullIO
):
package.add_dependency(Factory.create_dependency("B", "1"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1")
package_b.add_dependency(Factory.create_dependency("A", "1.0"))
repo.add_package(package_a)
solver = Solver(package, pool, [package_b], [], io)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_a},
{
"job": "install",
"package": package_b,
"skipped": True, # already installed
},
],
)
def test_solver_with_deps(solver: Solver, repo: Repository, package: ProjectPackage):
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
new_package_b = get_package("B", "1.1")
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(new_package_b)
package_a.add_dependency(get_dependency("B", "<1.1"))
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_b},
{"job": "install", "package": package_a},
],
)
def test_install_honours_not_equal(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
new_package_b11 = get_package("B", "1.1")
new_package_b12 = get_package("B", "1.2")
new_package_b13 = get_package("B", "1.3")
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(new_package_b11)
repo.add_package(new_package_b12)
repo.add_package(new_package_b13)
package_a.add_dependency(get_dependency("B", "<=1.3,!=1.3,!=1.2"))
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": new_package_b11},
{"job": "install", "package": package_a},
],
)
def test_install_with_deps_in_order(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package.add_dependency(Factory.create_dependency("C", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
package_b.add_dependency(get_dependency("A", ">=1.0"))
package_b.add_dependency(get_dependency("C", ">=1.0"))
package_c.add_dependency(get_dependency("A", ">=1.0"))
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_a},
{"job": "install", "package": package_c},
{"job": "install", "package": package_b},
],
)
def test_install_installed(
package: ProjectPackage, repo: Repository, pool: Pool, io: NullIO
):
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
repo.add_package(package_a)
solver = Solver(package, pool, [package_a], [], io)
transaction = solver.solve()
check_solver_result(
transaction, [{"job": "install", "package": package_a, "skipped": True}]
)
def test_update_installed(
package: ProjectPackage, repo: Repository, pool: Pool, io: NullIO
):
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
new_package_a = get_package("A", "1.1")
repo.add_package(package_a)
repo.add_package(new_package_a)
solver = Solver(package, pool, [get_package("A", "1.0")], [], io)
transaction = solver.solve()
check_solver_result(
transaction, [{"job": "update", "from": package_a, "to": new_package_a}]
)
def test_update_with_use_latest(
package: ProjectPackage, repo: Repository, pool: Pool, io: NullIO
):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package_a = get_package("A", "1.0")
new_package_a = get_package("A", "1.1")
package_b = get_package("B", "1.0")
new_package_b = get_package("B", "1.1")
repo.add_package(package_a)
repo.add_package(new_package_a)
repo.add_package(package_b)
repo.add_package(new_package_b)
installed = [get_package("A", "1.0")]
locked = [package_a, package_b]
solver = Solver(package, pool, installed, locked, io)
transaction = solver.solve(use_latest=[package_b.name])
check_solver_result(
transaction,
[
{"job": "install", "package": package_a, "skipped": True},
{"job": "install", "package": new_package_b},
],
)
def test_solver_sets_groups(solver: Solver, repo: Repository, package: ProjectPackage):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*", groups=["dev"]))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
package_b.add_dependency(Factory.create_dependency("C", "~1.0"))
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
transaction = solver.solve()
ops = check_solver_result(
transaction,
[
{"job": "install", "package": package_c},
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
],
)
assert ops[0].package.category == "dev"
assert ops[2].package.category == "dev"
assert ops[1].package.category == "main"
def test_solver_respects_root_package_python_versions(
solver: Solver, repo: Repository, package: ProjectPackage
):
set_package_python_versions(solver.provider, "~3.4")
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_b.python_versions = "^3.3"
package_c = get_package("C", "1.0")
package_c.python_versions = "^3.4"
package_c11 = get_package("C", "1.1")
package_c11.python_versions = "^3.6"
package_b.add_dependency(Factory.create_dependency("C", "^1.0"))
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
repo.add_package(package_c11)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_c},
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
],
)
def test_solver_fails_if_mismatch_root_python_versions(
solver: Solver, repo: Repository, package: ProjectPackage
):
set_package_python_versions(solver.provider, "^3.4")
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_b.python_versions = "^3.6"
package_c = get_package("C", "1.0")
package_c.python_versions = "~3.3"
package_b.add_dependency(Factory.create_dependency("C", "~1.0"))
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
with pytest.raises(SolverProblemError):
solver.solve()
def test_solver_ignores_python_restricted_if_mismatch_root_package_python_versions(
solver: Solver, repo: Repository, package: ProjectPackage
):
set_package_python_versions(solver.provider, "~3.8")
package.add_dependency(
Factory.create_dependency("A", {"version": "1.0", "python": "<3.8"})
)
package.add_dependency(
Factory.create_dependency(
"B", {"version": "1.0", "markers": "python_version < '3.8'"}
)
)
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
repo.add_package(package_a)
repo.add_package(package_b)
transaction = solver.solve()
check_solver_result(transaction, [])
def test_solver_solves_optional_and_compatible_packages(
solver: Solver, repo: Repository, package: ProjectPackage
):
set_package_python_versions(solver.provider, "~3.4")
package.extras["foo"] = [get_dependency("B")]
package.add_dependency(
Factory.create_dependency("A", {"version": "*", "python": "^3.4"})
)
package.add_dependency(
Factory.create_dependency("B", {"version": "*", "optional": True})
)
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_b.python_versions = "^3.3"
package_c = get_package("C", "1.0")
package_c.python_versions = "^3.4"
package_b.add_dependency(Factory.create_dependency("C", "^1.0"))
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_c},
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
],
)
def test_solver_does_not_return_extras_if_not_requested(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
package_b.extras = {"foo": [get_dependency("C", "^1.0")]}
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
],
)
def test_solver_returns_extras_if_requested(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(
Factory.create_dependency("B", {"version": "*", "extras": ["foo"]})
)
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
dep = get_dependency("C", "^1.0", optional=True)
dep.marker = parse_marker("extra == 'foo'")
package_b.extras = {"foo": [dep]}
package_b.add_dependency(dep)
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
transaction = solver.solve()
ops = check_solver_result(
transaction,
[
{"job": "install", "package": package_c},
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
],
)
assert ops[-1].package.marker.is_any()
assert ops[0].package.marker.is_any()
@pytest.mark.parametrize("enabled_extra", ["one", "two", None])
def test_solver_returns_extras_only_requested(
solver: Solver,
repo: Repository,
package: ProjectPackage,
enabled_extra: bool | None,
):
extras = [enabled_extra] if enabled_extra is not None else []
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(
Factory.create_dependency("B", {"version": "*", "extras": extras})
)
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c10 = get_package("C", "1.0")
package_c20 = get_package("C", "2.0")
dep10 = get_dependency("C", "1.0", optional=True)
dep10._in_extras.append("one")
dep10.marker = parse_marker("extra == 'one'")
dep20 = get_dependency("C", "2.0", optional=True)
dep20._in_extras.append("two")
dep20.marker = parse_marker("extra == 'two'")
package_b.extras = {"one": [dep10], "two": [dep20]}
package_b.add_dependency(dep10)
package_b.add_dependency(dep20)
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c10)
repo.add_package(package_c20)
transaction = solver.solve()
expected = [
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
]
if enabled_extra is not None:
expected.insert(
0,
{
"job": "install",
"package": package_c10 if enabled_extra == "one" else package_c20,
},
)
ops = check_solver_result(
transaction,
expected,
)
assert ops[-1].package.marker.is_any()
assert ops[0].package.marker.is_any()
@pytest.mark.parametrize("enabled_extra", ["one", "two", None])
def test_solver_returns_extras_when_multiple_extras_use_same_dependency(
solver: Solver,
repo: Repository,
package: ProjectPackage,
enabled_extra: bool | None,
):
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
dep = get_dependency("C", "*", optional=True)
dep._in_extras.append("one")
dep._in_extras.append("two")
package_b.extras = {"one": [dep], "two": [dep]}
package_b.add_dependency(dep)
extras = [enabled_extra] if enabled_extra is not None else []
package_a.add_dependency(
Factory.create_dependency("B", {"version": "*", "extras": extras})
)
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
transaction = solver.solve()
expected = [
{"job": "install", "package": package_b},
{"job": "install", "package": package_a},
]
if enabled_extra is not None:
expected.insert(0, {"job": "install", "package": package_c})
ops = check_solver_result(
transaction,
expected,
)
assert ops[-1].package.marker.is_any()
assert ops[0].package.marker.is_any()
@pytest.mark.parametrize("enabled_extra", ["one", "two", None])
def test_solver_returns_extras_only_requested_nested(
solver: Solver,
repo: Repository,
package: ProjectPackage,
enabled_extra: bool | None,
):
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c10 = get_package("C", "1.0")
package_c20 = get_package("C", "2.0")
dep10 = get_dependency("C", "1.0", optional=True)
dep10._in_extras.append("one")
dep10.marker = parse_marker("extra == 'one'")
dep20 = get_dependency("C", "2.0", optional=True)
dep20._in_extras.append("two")
dep20.marker = parse_marker("extra == 'two'")
package_b.extras = {"one": [dep10], "two": [dep20]}
package_b.add_dependency(dep10)
package_b.add_dependency(dep20)
extras = [enabled_extra] if enabled_extra is not None else []
package_a.add_dependency(
Factory.create_dependency("B", {"version": "*", "extras": extras})
)
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c10)
repo.add_package(package_c20)
transaction = solver.solve()
expected = [
{"job": "install", "package": package_b},
{"job": "install", "package": package_a},
]
if enabled_extra is not None:
expected.insert(
0,
{
"job": "install",
"package": package_c10 if enabled_extra == "one" else package_c20,
},
)
ops = check_solver_result(transaction, expected)
assert ops[-1].package.marker.is_any()
assert ops[0].package.marker.is_any()
def test_solver_finds_extras_next_to_non_extras(
solver: Solver, repo: Repository, package: ProjectPackage
):
# Root depends on A[foo]
package.add_dependency(
Factory.create_dependency("A", {"version": "*", "extras": ["foo"]})
)
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
package_d = get_package("D", "1.0")
# A depends on B; A[foo] depends on B[bar].
package_a.add_dependency(Factory.create_dependency("B", "*"))
package_a.add_dependency(
Factory.create_dependency(
"B", {"version": "*", "extras": ["bar"], "markers": "extra == 'foo'"}
)
)
package_a.extras = {"foo": [get_dependency("B", "*")]}
# B depends on C; B[bar] depends on D.
package_b.add_dependency(Factory.create_dependency("C", "*"))
package_b.add_dependency(
Factory.create_dependency("D", {"version": "*", "markers": 'extra == "bar"'})
)
package_b.extras = {"bar": [get_dependency("D", "*")]}
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
repo.add_package(package_d)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_c},
{"job": "install", "package": package_d},
{"job": "install", "package": package_b},
{"job": "install", "package": package_a},
],
)
def test_solver_merge_extras_into_base_package_multiple_repos_fixes_5727(
solver: Solver, repo: Repository, pool: Pool, package: ProjectPackage
):
package.add_dependency(
Factory.create_dependency("A", {"version": "*", "source": "legacy"})
)
package.add_dependency(Factory.create_dependency("B", {"version": "*"}))
package_a = get_package("A", "1.0")
package_a.extras = {"foo": []}
repo.add_package(package_a)
package_b = Package("B", "1.0", source_type="legacy")
package_b.add_dependency(package_a.with_features(["foo"]).to_dependency())
package_a = Package("A", "1.0", source_type="legacy")
package_a.extras = {"foo": []}
repo = Repository("legacy")
repo.add_package(package_a)
repo.add_package(package_b)
pool.add_repository(repo)
transaction = solver.solve()
ops = transaction.calculate_operations(synchronize=True)
assert len(ops[0].package.requires) == 0, "a should not require itself"
def test_solver_returns_prereleases_if_requested(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package.add_dependency(
Factory.create_dependency("C", {"version": "*", "allow-prereleases": True})
)
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
package_c_dev = get_package("C", "1.1-beta.1")
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
repo.add_package(package_c_dev)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
{"job": "install", "package": package_c_dev},
],
)
def test_solver_does_not_return_prereleases_if_not_requested(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package.add_dependency(Factory.create_dependency("C", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
package_c_dev = get_package("C", "1.1-beta.1")
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
repo.add_package(package_c_dev)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
{"job": "install", "package": package_c},
],
)
def test_solver_sub_dependencies_with_requirements(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(Factory.create_dependency("A", "*"))
package.add_dependency(Factory.create_dependency("B", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
package_d = get_package("D", "1.0")
package_c.add_dependency(
Factory.create_dependency("D", {"version": "^1.0", "python": "<4.0"})
)
package_a.add_dependency(Factory.create_dependency("C", "*"))
package_b.add_dependency(Factory.create_dependency("D", "^1.0"))
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
repo.add_package(package_d)
transaction = solver.solve()
ops = check_solver_result(
transaction,
[
{"job": "install", "package": package_d},
{"job": "install", "package": package_c},
{"job": "install", "package": package_a},
{"job": "install", "package": package_b},
],
)
op = ops[1]
assert op.package.marker.is_any()
def test_solver_sub_dependencies_with_requirements_complex(
solver: Solver, repo: Repository, package: ProjectPackage
):
package.add_dependency(
Factory.create_dependency("A", {"version": "^1.0", "python": "<5.0"})
)
package.add_dependency(
Factory.create_dependency("B", {"version": "^1.0", "python": "<5.0"})
)
package.add_dependency(
Factory.create_dependency("C", {"version": "^1.0", "python": "<4.0"})
)
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0")
package_d = get_package("D", "1.0")
package_e = get_package("E", "1.0")
package_f = get_package("F", "1.0")
package_a.add_dependency(
Factory.create_dependency("B", {"version": "^1.0", "python": "<4.0"})
)
package_a.add_dependency(
Factory.create_dependency("D", {"version": "^1.0", "python": "<4.0"})
)
package_b.add_dependency(
Factory.create_dependency("E", {"version": "^1.0", "platform": "win32"})
)
package_b.add_dependency(
Factory.create_dependency("F", {"version": "^1.0", "python": "<5.0"})
)
package_c.add_dependency(
Factory.create_dependency("F", {"version": "^1.0", "python": "<4.0"})
)
package_d.add_dependency(Factory.create_dependency("F", "*"))
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
repo.add_package(package_d)
repo.add_package(package_e)
repo.add_package(package_f)
transaction = solver.solve()
check_solver_result(
transaction,
[
{"job": "install", "package": package_e},
{"job": "install", "package": package_f},
{"job": "install", "package": package_b},
{"job": "install", "package": package_d},
{"job": "install", "package": package_a},
{"job": "install", "package": package_c},
],
)
def test_solver_sub_dependencies_with_not_supported_python_version(
solver: Solver, repo: Repository, package: ProjectPackage
):
set_package_python_versions(solver.provider, "^3.5")
package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0")
package_b.python_versions = "<2.0"
package_a.add_dependency(
Factory.create_dependency("B", {"version": "^1.0", "python": "<2.0"})
)
repo.add_package(package_a)
repo.add_package(package_b)
transaction = solver.solve()
check_solver_result(transaction, [{"job": "install", "package": package_a}])
def test_solver_sub_dependencies_with_not_supported_python_version_transitive(
solver: Solver, repo: Repository, package: ProjectPackage
):
set_package_python_versions(solver.provider, "^3.4")
package.add_dependency(
Factory.create_dependency("httpx", {"version": "^0.17.1", "python": "^3.6"})
)
httpx = get_package("httpx", "0.17.1")
httpx.python_versions = ">=3.6"
httpcore = get_package("httpcore", "0.12.3")
httpcore.python_versions = ">=3.6"
sniffio_1_1_0 = get_package("sniffio", "1.1.0")
sniffio_1_1_0.python_versions = ">=3.5"
sniffio = get_package("sniffio", "1.2.0")
sniffio.python_versions = ">=3.5"
httpx.add_dependency(
Factory.create_dependency("httpcore", {"version": ">=0.12.1,<0.13"})
)
httpx.add_dependency(Factory.create_dependency("sniffio", {"version": "*"}))
httpcore.add_dependency(Factory.create_dependency("sniffio", {"version": "==1.*"}))
repo.add_package(httpx)
repo.add_package(httpcore)
repo.add_package(sniffio)
repo.add_package(sniffio_1_1_0)