Skip to content

Commit cdebaeb

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 cdebaeb

File tree

1 file changed

+53
-24
lines changed

1 file changed

+53
-24
lines changed

tests/test_commands.py

Lines changed: 53 additions & 24 deletions
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,70 @@ 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+
82+
a = Distribution("twine", "1.5.0")
83+
b = Distribution("twine", "1.6.5")
84+
5785
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,
6795
]
6896

6997
inputs = commands._split_inputs(inputs)
7098

7199
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,
76104
]
77105

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

84111
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"),
88119
],
89-
helpers.SDIST_FIXTURE: [],
90-
helpers.NEW_WHEEL_FIXTURE: [helpers.NEW_WHEEL_FIXTURE + ".frob.attestation"],
91-
helpers.NEW_SDIST_FIXTURE: [],
120+
b.sdist: [],
92121
}

0 commit comments

Comments
 (0)