-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathtest_commands.py
120 lines (93 loc) · 2.72 KB
/
test_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import dataclasses
import os
import pytest
from twine import commands
from twine import exceptions
def test_ensure_wheel_files_uploaded_first():
files = commands._group_wheel_files_first(
["twine/foo.py", "twine/first.whl", "twine/bar.py", "twine/second.whl"]
)
expected = [
"twine/first.whl",
"twine/second.whl",
"twine/foo.py",
"twine/bar.py",
]
assert expected == files
def test_ensure_if_no_wheel_files():
files = commands._group_wheel_files_first(["twine/foo.py", "twine/bar.py"])
expected = ["twine/foo.py", "twine/bar.py"]
assert expected == files
def test_find_dists_expands_globs():
files = sorted(commands._find_dists(["twine/__*.py"]))
expected = [
os.path.join("twine", "__init__.py"),
os.path.join("twine", "__main__.py"),
]
assert expected == files
def test_find_dists_errors_on_invalid_globs():
with pytest.raises(exceptions.InvalidDistribution):
commands._find_dists(["twine/*.rb"])
def test_find_dists_handles_real_files():
expected = [
"twine/__init__.py",
"twine/__main__.py",
"twine/cli.py",
"twine/utils.py",
"twine/wheel.py",
]
files = commands._find_dists(expected)
assert expected == files
class Signed(str):
@property
def signature(self):
return f"{self}.asc"
def attestation(self, what):
return f"{self}.{what}.attestation"
@dataclasses.dataclass
class Distribution:
name: str
version: str
@property
def sdist(self):
return Signed(f"dist/{self.name}-{self.version}.tar.gz")
@property
def wheel(self):
return Signed(f"dist/{self.name}-{self.version}-py2.py3-none-any.whl")
def test_split_inputs():
"""Split inputs into dists, signatures, and attestations."""
a = Distribution("twine", "1.5.0")
b = Distribution("twine", "1.6.5")
inputs = [
a.wheel,
a.wheel.signature,
a.wheel.attestation("build"),
a.wheel.attestation("build.publish"),
a.sdist,
a.sdist.signature,
b.wheel,
b.wheel.attestation("frob"),
b.sdist,
]
inputs = commands._split_inputs(inputs)
assert inputs.dists == [
a.wheel,
a.sdist,
b.wheel,
b.sdist,
]
assert inputs.signatures == {
"twine-1.5.0-py2.py3-none-any.whl.asc": a.wheel.signature,
"twine-1.5.0.tar.gz.asc": a.sdist.signature,
}
assert inputs.attestations_by_dist == {
a.wheel: [
a.wheel.attestation("build"),
a.wheel.attestation("build.publish"),
],
a.sdist: [],
b.wheel: [
b.wheel.attestation("frob"),
],
b.sdist: [],
}