Skip to content

Commit 2f8f562

Browse files
committed
Use a better way to construct file names in test_commands
There is no need for the strings to be real file paths and using string manipulation to build the file names is error prone. Define simple helpers that construct the file names as needed. This makes the tests intent and implementation easier to understand.
1 parent 4406034 commit 2f8f562

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

Diff for: tests/test_commands.py

+52-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import dataclasses
12
import os
23

34
import pytest
45

5-
from tests import helpers
66
from twine import commands
77
from twine import exceptions
88

@@ -52,41 +52,69 @@ def test_find_dists_handles_real_files():
5252
assert expected == files
5353

5454

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+
5579
def test_split_inputs():
5680
"""Split inputs into dists, signatures, and attestations."""
81+
a = Distribution("twine", "1.5.0")
82+
b = Distribution("twine", "1.6.5")
83+
5784
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,
6794
]
6895

6996
inputs = commands._split_inputs(inputs)
7097

7198
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,
76103
]
77104

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,
81108
}
82-
assert inputs.signatures == expected_signatures
83109

84110
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"),
88118
],
89-
helpers.SDIST_FIXTURE: [],
90-
helpers.NEW_WHEEL_FIXTURE: [helpers.NEW_WHEEL_FIXTURE + ".frob.attestation"],
91-
helpers.NEW_SDIST_FIXTURE: [],
119+
b.sdist: [],
92120
}

0 commit comments

Comments
 (0)