| 
 | 1 | +import dataclasses  | 
1 | 2 | import os  | 
2 | 3 | 
 
  | 
3 | 4 | import pytest  | 
4 | 5 | 
 
  | 
5 |  | -from tests import helpers  | 
6 | 6 | from twine import commands  | 
7 | 7 | from twine import exceptions  | 
8 | 8 | 
 
  | 
@@ -52,41 +52,70 @@ def test_find_dists_handles_real_files():  | 
52 | 52 |     assert expected == files  | 
53 | 53 | 
 
  | 
54 | 54 | 
 
  | 
 | 55 | +class Signed(str):  | 
 | 56 | + | 
 | 57 | +    @property  | 
 | 58 | +    def signature(self):  | 
 | 59 | +        return f"{self}.asc"  | 
 | 60 | + | 
 | 61 | +    def attestation(self, what):  | 
 | 62 | +        return f"{self}.{what}.attestation"  | 
 | 63 | + | 
 | 64 | + | 
 | 65 | +@dataclasses.dataclass  | 
 | 66 | +class Distribution:  | 
 | 67 | +    name: str  | 
 | 68 | +    version: str  | 
 | 69 | + | 
 | 70 | +    @property  | 
 | 71 | +    def sdist(self):  | 
 | 72 | +        return Signed(f"dist/{self.name}-{self.version}.tar.gz")  | 
 | 73 | + | 
 | 74 | +    @property  | 
 | 75 | +    def wheel(self):  | 
 | 76 | +        return Signed(f"dist/{self.name}-{self.version}-py2.py3-none-any.whl")  | 
 | 77 | + | 
 | 78 | + | 
55 | 79 | def test_split_inputs():  | 
56 | 80 |     """Split inputs into dists, signatures, and attestations."""  | 
 | 81 | + | 
 | 82 | +    a = Distribution("twine", "1.5.0")  | 
 | 83 | +    b = Distribution("twine", "1.6.5")  | 
 | 84 | + | 
57 | 85 |     inputs = [  | 
58 |  | -        helpers.WHEEL_FIXTURE,  | 
59 |  | -        helpers.WHEEL_FIXTURE + ".asc",  | 
60 |  | -        helpers.WHEEL_FIXTURE + ".build.attestation",  | 
61 |  | -        helpers.WHEEL_FIXTURE + ".publish.attestation",  | 
62 |  | -        helpers.SDIST_FIXTURE,  | 
63 |  | -        helpers.SDIST_FIXTURE + ".asc",  | 
64 |  | -        helpers.NEW_WHEEL_FIXTURE,  | 
65 |  | -        helpers.NEW_WHEEL_FIXTURE + ".frob.attestation",  | 
66 |  | -        helpers.NEW_SDIST_FIXTURE,  | 
 | 86 | +        a.wheel,  | 
 | 87 | +        a.wheel.signature,  | 
 | 88 | +        a.wheel.attestation("build"),  | 
 | 89 | +        a.wheel.attestation("build.publish"),  | 
 | 90 | +        a.sdist,  | 
 | 91 | +        a.sdist.signature,  | 
 | 92 | +        b.wheel,  | 
 | 93 | +        b.wheel.attestation("frob"),  | 
 | 94 | +        b.sdist,  | 
67 | 95 |     ]  | 
68 | 96 | 
 
  | 
69 | 97 |     inputs = commands._split_inputs(inputs)  | 
70 | 98 | 
 
  | 
71 | 99 |     assert inputs.dists == [  | 
72 |  | -        helpers.WHEEL_FIXTURE,  | 
73 |  | -        helpers.SDIST_FIXTURE,  | 
74 |  | -        helpers.NEW_WHEEL_FIXTURE,  | 
75 |  | -        helpers.NEW_SDIST_FIXTURE,  | 
 | 100 | +        a.wheel,  | 
 | 101 | +        a.sdist,  | 
 | 102 | +        b.wheel,  | 
 | 103 | +        b.sdist,  | 
76 | 104 |     ]  | 
77 | 105 | 
 
  | 
78 |  | -    expected_signatures = {  | 
79 |  | -        os.path.basename(dist) + ".asc": dist + ".asc"  | 
80 |  | -        for dist in [helpers.WHEEL_FIXTURE, helpers.SDIST_FIXTURE]  | 
 | 106 | +    assert inputs.signatures == {  | 
 | 107 | +        "twine-1.5.0-py2.py3-none-any.whl.asc": a.wheel.signature,  | 
 | 108 | +        "twine-1.5.0.tar.gz.asc": a.sdist.signature,  | 
81 | 109 |     }  | 
82 |  | -    assert inputs.signatures == expected_signatures  | 
83 | 110 | 
 
  | 
84 | 111 |     assert inputs.attestations_by_dist == {  | 
85 |  | -        helpers.WHEEL_FIXTURE: [  | 
86 |  | -            helpers.WHEEL_FIXTURE + ".build.attestation",  | 
87 |  | -            helpers.WHEEL_FIXTURE + ".publish.attestation",  | 
 | 112 | +        a.wheel: [  | 
 | 113 | +            a.wheel.attestation("build"),  | 
 | 114 | +            a.wheel.attestation("build.publish"),  | 
 | 115 | +        ],  | 
 | 116 | +        a.sdist: [],  | 
 | 117 | +        b.wheel: [  | 
 | 118 | +            b.wheel.attestation("frob"),  | 
88 | 119 |         ],  | 
89 |  | -        helpers.SDIST_FIXTURE: [],  | 
90 |  | -        helpers.NEW_WHEEL_FIXTURE: [helpers.NEW_WHEEL_FIXTURE + ".frob.attestation"],  | 
91 |  | -        helpers.NEW_SDIST_FIXTURE: [],  | 
 | 120 | +        b.sdist: [],  | 
92 | 121 |     }  | 
0 commit comments