|
15 | 15 | from poetry.core.constraints.generic import BaseConstraint |
16 | 16 |
|
17 | 17 |
|
18 | | -def test_allows() -> None: |
19 | | - c = Constraint("win32") |
20 | | - |
21 | | - assert c.allows(Constraint("win32")) |
22 | | - assert not c.allows(Constraint("linux")) |
23 | | - |
24 | | - c = Constraint("win32", "!=") |
25 | | - |
26 | | - assert not c.allows(Constraint("win32")) |
27 | | - assert c.allows(Constraint("linux")) |
28 | | - |
29 | | - |
30 | | -def test_allows_any() -> None: |
31 | | - c = Constraint("win32") |
32 | | - |
33 | | - assert c.allows_any(Constraint("win32")) |
34 | | - assert not c.allows_any(Constraint("linux")) |
35 | | - assert c.allows_any(UnionConstraint(Constraint("win32"), Constraint("linux"))) |
36 | | - assert c.allows_any(Constraint("linux", "!=")) |
37 | | - |
38 | | - c = Constraint("win32", "!=") |
39 | | - |
40 | | - assert not c.allows_any(Constraint("win32")) |
41 | | - assert c.allows_any(Constraint("linux")) |
42 | | - assert c.allows_any(UnionConstraint(Constraint("win32"), Constraint("linux"))) |
43 | | - assert c.allows_any(Constraint("linux", "!=")) |
| 18 | +@pytest.mark.parametrize( |
| 19 | + ("constraint1", "constraint2", "expected"), |
| 20 | + [ |
| 21 | + (Constraint("win32"), Constraint("win32"), True), |
| 22 | + (Constraint("win32"), Constraint("linux"), False), |
| 23 | + (Constraint("win32", "!="), Constraint("win32"), False), |
| 24 | + (Constraint("win32", "!="), Constraint("linux"), True), |
| 25 | + ], |
| 26 | +) |
| 27 | +def test_allows( |
| 28 | + constraint1: Constraint, constraint2: Constraint, expected: bool |
| 29 | +) -> None: |
| 30 | + assert constraint1.allows(constraint2) is expected |
44 | 31 |
|
45 | 32 |
|
46 | | -def test_allows_all() -> None: |
47 | | - c = Constraint("win32") |
48 | | - |
49 | | - assert c.allows_all(Constraint("win32")) |
50 | | - assert not c.allows_all(Constraint("linux")) |
51 | | - assert not c.allows_all(Constraint("linux", "!=")) |
52 | | - assert not c.allows_all(UnionConstraint(Constraint("win32"), Constraint("linux"))) |
| 33 | +@pytest.mark.parametrize( |
| 34 | + ("constraint1", "constraint2", "expected_any", "expected_all"), |
| 35 | + [ |
| 36 | + (Constraint("win32"), EmptyConstraint(), False, True), |
| 37 | + (Constraint("win32"), AnyConstraint(), True, False), |
| 38 | + (Constraint("win32"), Constraint("win32"), True, True), |
| 39 | + (Constraint("win32"), Constraint("linux"), False, False), |
| 40 | + (Constraint("win32"), Constraint("win32", "!="), False, False), |
| 41 | + (Constraint("win32"), Constraint("linux", "!="), True, False), |
| 42 | + ( |
| 43 | + Constraint("win32"), |
| 44 | + UnionConstraint(Constraint("win32"), Constraint("linux")), |
| 45 | + True, |
| 46 | + False, |
| 47 | + ), |
| 48 | + ( |
| 49 | + Constraint("win32"), |
| 50 | + UnionConstraint(Constraint("darwin"), Constraint("linux")), |
| 51 | + False, |
| 52 | + False, |
| 53 | + ), |
| 54 | + ( |
| 55 | + Constraint("win32"), |
| 56 | + UnionConstraint(Constraint("win32", "!="), Constraint("linux", "!=")), |
| 57 | + True, |
| 58 | + False, |
| 59 | + ), |
| 60 | + ( |
| 61 | + Constraint("win32"), |
| 62 | + UnionConstraint(Constraint("darwin", "!="), Constraint("linux", "!=")), |
| 63 | + True, |
| 64 | + False, |
| 65 | + ), |
| 66 | + ( |
| 67 | + Constraint("win32"), |
| 68 | + MultiConstraint(Constraint("win32", "!="), Constraint("linux", "!=")), |
| 69 | + False, |
| 70 | + False, |
| 71 | + ), |
| 72 | + ( |
| 73 | + Constraint("win32"), |
| 74 | + MultiConstraint(Constraint("darwin", "!="), Constraint("linux", "!=")), |
| 75 | + True, |
| 76 | + False, |
| 77 | + ), |
| 78 | + (Constraint("win32", "!="), EmptyConstraint(), False, True), |
| 79 | + (Constraint("win32", "!="), AnyConstraint(), True, False), |
| 80 | + (Constraint("win32", "!="), Constraint("win32"), False, False), |
| 81 | + (Constraint("win32", "!="), Constraint("linux"), True, True), |
| 82 | + (Constraint("win32", "!="), Constraint("win32", "!="), True, True), |
| 83 | + (Constraint("win32", "!="), Constraint("linux", "!="), True, False), |
| 84 | + ( |
| 85 | + Constraint("win32", "!="), |
| 86 | + UnionConstraint(Constraint("win32"), Constraint("linux")), |
| 87 | + True, |
| 88 | + False, |
| 89 | + ), |
| 90 | + ( |
| 91 | + Constraint("win32", "!="), |
| 92 | + UnionConstraint(Constraint("darwin"), Constraint("linux")), |
| 93 | + True, |
| 94 | + True, |
| 95 | + ), |
| 96 | + ( |
| 97 | + Constraint("win32", "!="), |
| 98 | + UnionConstraint(Constraint("win32", "!="), Constraint("linux", "!=")), |
| 99 | + True, |
| 100 | + False, |
| 101 | + ), |
| 102 | + ( |
| 103 | + Constraint("win32", "!="), |
| 104 | + UnionConstraint(Constraint("darwin", "!="), Constraint("linux", "!=")), |
| 105 | + True, |
| 106 | + False, |
| 107 | + ), |
| 108 | + ( |
| 109 | + Constraint("win32", "!="), |
| 110 | + MultiConstraint(Constraint("win32", "!="), Constraint("linux", "!=")), |
| 111 | + True, |
| 112 | + True, |
| 113 | + ), |
| 114 | + ( |
| 115 | + Constraint("win32", "!="), |
| 116 | + MultiConstraint(Constraint("darwin", "!="), Constraint("linux", "!=")), |
| 117 | + True, |
| 118 | + False, |
| 119 | + ), |
| 120 | + ], |
| 121 | +) |
| 122 | +def test_allows_any_and_allows_all( |
| 123 | + constraint1: Constraint, |
| 124 | + constraint2: BaseConstraint, |
| 125 | + expected_any: bool, |
| 126 | + expected_all: bool, |
| 127 | +) -> None: |
| 128 | + assert constraint1.allows_any(constraint2) is expected_any |
| 129 | + assert constraint1.allows_all(constraint2) is expected_all |
53 | 130 |
|
54 | 131 |
|
55 | 132 | @pytest.mark.parametrize( |
|
0 commit comments