-
Notifications
You must be signed in to change notification settings - Fork 241
/
test_package.py
308 lines (252 loc) · 8.69 KB
/
test_package.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pytest
from poetry.core.packages import Package
from poetry.core.utils._compat import Path
def test_package_authors():
package = Package("foo", "0.1.0")
package.authors.append("Sébastien Eustace <sebastien@eustace.io>")
assert package.author_name == "Sébastien Eustace"
assert package.author_email == "sebastien@eustace.io"
package.authors.insert(0, "John Doe")
assert package.author_name == "John Doe"
assert package.author_email is None
def test_package_authors_invalid():
package = Package("foo", "0.1.0")
package.authors.insert(0, "<John Doe")
with pytest.raises(ValueError) as e:
package.author_name
assert (
str(e.value)
== "Invalid author string. Must be in the format: John Smith <john@example.com>"
)
@pytest.mark.parametrize("category", ["main", "dev"])
def test_package_add_dependency_vcs_category(category, f):
package = Package("foo", "0.1.0")
dependency = package.add_dependency(
f.create_dependency(
"poetry",
{"git": "https://github.com/python-poetry/poetry.git"},
category=category,
)
)
assert dependency.category == category
def test_package_add_dependency_vcs_category_default_main(f):
package = Package("foo", "0.1.0")
dependency = package.add_dependency(
f.create_dependency(
"poetry", {"git": "https://github.com/python-poetry/poetry.git"}
)
)
assert dependency.category == "main"
@pytest.mark.parametrize("category", ["main", "dev"])
@pytest.mark.parametrize("optional", [True, False])
def test_package_url_category_optional(category, optional, f):
package = Package("foo", "0.1.0")
dependency = package.add_dependency(
f.create_dependency(
"poetry",
{
"url": "https://github.com/python-poetry/poetry/releases/download/1.0.5/poetry-1.0.5-linux.tar.gz",
"optional": optional,
},
category=category,
)
)
assert dependency.category == category
assert dependency.is_optional() == optional
def test_package_equality_simple():
assert Package("foo", "0.1.0") == Package("foo", "0.1.0")
assert Package("foo", "0.1.0") != Package("foo", "0.1.1")
assert Package("bar", "0.1.0") != Package("foo", "0.1.0")
def test_package_equality_source_type():
a1 = Package("a", "0.1.0", source_type="file")
a2 = Package(a1.name, a1.version, source_type="directory")
a3 = Package(a1.name, a1.version, source_type=a1.source_type)
a4 = Package(a1.name, a1.version)
assert a1 == a1
assert a1 == a3
assert a1 != a2
assert a2 != a3
assert a1 != a4
assert a2 != a4
def test_package_equality_source_url():
a1 = Package("a", "0.1.0", source_type="file", source_url="/some/path")
a2 = Package(
a1.name, a1.version, source_type=a1.source_type, source_url="/some/other/path"
)
a3 = Package(
a1.name, a1.version, source_type=a1.source_type, source_url=a1.source_url
)
a4 = Package(a1.name, a1.version, source_type=a1.source_type)
assert a1 == a1
assert a1 == a3
assert a1 != a2
assert a2 != a3
assert a1 != a4
assert a2 != a4
def test_package_equality_source_reference():
a1 = Package(
"a",
"0.1.0",
source_type="git",
source_url="https://foo.bar",
source_reference="c01b317af582501c5ba07b23d5bef3fbada2d4ef",
)
a2 = Package(
a1.name,
a1.version,
source_type="git",
source_url="https://foo.bar",
source_reference="a444731cd243cb5cd04e4d5fb81f86e1fecf8a00",
)
a3 = Package(
a1.name,
a1.version,
source_type="git",
source_url="https://foo.bar",
source_reference="c01b317af582501c5ba07b23d5bef3fbada2d4ef",
)
a4 = Package(a1.name, a1.version, source_type="git")
assert a1 == a1
assert a1 == a3
assert a1 != a2
assert a2 != a3
assert a1 != a4
assert a2 != a4
def test_package_resolved_reference_is_relevant_for_equality_only_if_present_for_both_packages():
a1 = Package(
"a",
"0.1.0",
source_type="git",
source_url="https://foo.bar",
source_reference="master",
source_resolved_reference="c01b317af582501c5ba07b23d5bef3fbada2d4ef",
)
a2 = Package(
a1.name,
a1.version,
source_type="git",
source_url="https://foo.bar",
source_reference="master",
source_resolved_reference="a444731cd243cb5cd04e4d5fb81f86e1fecf8a00",
)
a3 = Package(
a1.name,
a1.version,
source_type="git",
source_url="https://foo.bar",
source_reference="master",
source_resolved_reference="c01b317af582501c5ba07b23d5bef3fbada2d4ef",
)
a4 = Package(
a1.name,
a1.version,
source_type="git",
source_url="https://foo.bar",
source_reference="master",
)
assert a1 == a1
assert a1 == a3
assert a1 != a2
assert a2 != a3
assert a1 == a4
assert a2 == a4
def test_complete_name():
assert "foo" == Package("foo", "1.2.3").complete_name
assert (
"foo[bar,baz]" == Package("foo", "1.2.3", features=["baz", "bar"]).complete_name
)
def test_to_dependency():
package = Package("foo", "1.2.3")
dep = package.to_dependency()
assert "foo" == dep.name
assert package.version == dep.constraint
def test_to_dependency_with_python_constraint():
package = Package("foo", "1.2.3")
package.python_versions = ">=3.6"
dep = package.to_dependency()
assert "foo" == dep.name
assert package.version == dep.constraint
assert ">=3.6" == dep.python_versions
def test_to_dependency_with_features():
package = Package("foo", "1.2.3", features=["baz", "bar"])
dep = package.to_dependency()
assert "foo" == dep.name
assert package.version == dep.constraint
assert frozenset({"bar", "baz"}) == dep.features
def test_to_dependency_for_directory():
path = Path(__file__).parent.parent.joinpath("fixtures/simple_project")
package = Package(
"foo",
"1.2.3",
source_type="directory",
source_url=path.as_posix(),
features=["baz", "bar"],
)
dep = package.to_dependency()
assert "foo" == dep.name
assert package.version == dep.constraint
assert frozenset({"bar", "baz"}) == dep.features
assert dep.is_directory()
assert path == dep.path
assert "directory" == dep.source_type
assert path.as_posix() == dep.source_url
def test_to_dependency_for_file():
path = Path(__file__).parent.parent.joinpath(
"fixtures/distributions/demo-0.1.0.tar.gz"
)
package = Package(
"foo",
"1.2.3",
source_type="file",
source_url=path.as_posix(),
features=["baz", "bar"],
)
dep = package.to_dependency()
assert "foo" == dep.name
assert package.version == dep.constraint
assert frozenset({"bar", "baz"}) == dep.features
assert dep.is_file()
assert path == dep.path
assert "file" == dep.source_type
assert path.as_posix() == dep.source_url
def test_to_dependency_for_url():
package = Package(
"foo",
"1.2.3",
source_type="url",
source_url="https://example.com/path.tar.gz",
features=["baz", "bar"],
)
dep = package.to_dependency()
assert "foo" == dep.name
assert package.version == dep.constraint
assert frozenset({"bar", "baz"}) == dep.features
assert dep.is_url()
assert "https://example.com/path.tar.gz" == dep.url
assert "url" == dep.source_type
assert "https://example.com/path.tar.gz" == dep.source_url
def test_package_clone(f):
# TODO(nic): this test is not future-proof, in that any attributes added
# to the Package object and not filled out in this test setup might
# cause comparisons to match that otherwise should not. A factory method
# to create a Package object with all fields fully randomized would be the
# most rigorous test for this, but that's likely overkill.
p = Package(
"lol_wut",
"3.141.5926535",
pretty_version="③.⑭.⑮",
source_type="git",
source_url="http://some.url",
source_reference="fe4d2adabf3feb5d32b70ab5c105285fa713b10c",
source_resolved_reference="fe4d2adabf3feb5d32b70ab5c105285fa713b10c",
features=["abc", "def"],
)
p.files = (["file1", "file2", "file3"],)
p.homepage = "https://some.other.url"
p.repository_url = "http://bug.farm"
p.documentation_url = "http://lorem.ipsum/dolor/sit.amet"
p2 = p.clone()
assert p == p2
assert p.__dict__ == p2.__dict__