|
| 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,69 @@ 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 | + a = Distribution("twine", "1.5.0") |
| 82 | + b = Distribution("twine", "1.6.5") |
| 83 | + |
57 | 84 | 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, |
| 85 | + a.wheel, |
| 86 | + a.wheel.signature, |
| 87 | + a.wheel.attestation("build"), |
| 88 | + a.wheel.attestation("build.publish"), |
| 89 | + a.sdist, |
| 90 | + a.sdist.signature, |
| 91 | + b.wheel, |
| 92 | + b.wheel.attestation("frob"), |
| 93 | + b.sdist, |
67 | 94 | ] |
68 | 95 |
|
69 | 96 | inputs = commands._split_inputs(inputs) |
70 | 97 |
|
71 | 98 | assert inputs.dists == [ |
72 | | - helpers.WHEEL_FIXTURE, |
73 | | - helpers.SDIST_FIXTURE, |
74 | | - helpers.NEW_WHEEL_FIXTURE, |
75 | | - helpers.NEW_SDIST_FIXTURE, |
| 99 | + a.wheel, |
| 100 | + a.sdist, |
| 101 | + b.wheel, |
| 102 | + b.sdist, |
76 | 103 | ] |
77 | 104 |
|
78 | | - expected_signatures = { |
79 | | - os.path.basename(dist) + ".asc": dist + ".asc" |
80 | | - for dist in [helpers.WHEEL_FIXTURE, helpers.SDIST_FIXTURE] |
| 105 | + assert inputs.signatures == { |
| 106 | + "twine-1.5.0-py2.py3-none-any.whl.asc": a.wheel.signature, |
| 107 | + "twine-1.5.0.tar.gz.asc": a.sdist.signature, |
81 | 108 | } |
82 | | - assert inputs.signatures == expected_signatures |
83 | 109 |
|
84 | 110 | assert inputs.attestations_by_dist == { |
85 | | - helpers.WHEEL_FIXTURE: [ |
86 | | - helpers.WHEEL_FIXTURE + ".build.attestation", |
87 | | - helpers.WHEEL_FIXTURE + ".publish.attestation", |
| 111 | + a.wheel: [ |
| 112 | + a.wheel.attestation("build"), |
| 113 | + a.wheel.attestation("build.publish"), |
| 114 | + ], |
| 115 | + a.sdist: [], |
| 116 | + b.wheel: [ |
| 117 | + b.wheel.attestation("frob"), |
88 | 118 | ], |
89 | | - helpers.SDIST_FIXTURE: [], |
90 | | - helpers.NEW_WHEEL_FIXTURE: [helpers.NEW_WHEEL_FIXTURE + ".frob.attestation"], |
91 | | - helpers.NEW_SDIST_FIXTURE: [], |
| 119 | + b.sdist: [], |
92 | 120 | } |
0 commit comments