-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_denoprovider.py
More file actions
231 lines (212 loc) · 8.95 KB
/
test_denoprovider.py
File metadata and controls
231 lines (212 loc) · 8.95 KB
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
import logging
import tempfile
from pathlib import Path
from typing import cast
import pytest
from abxpkg import Binary, DenoProvider
from abxpkg.binprovider import BinProvider
from abxpkg.exceptions import BinaryInstallError, BinProviderInstallError
class TestDenoProvider:
def test_install_root_alias_installs_into_the_requested_prefix(self, test_machine):
with tempfile.TemporaryDirectory() as temp_dir:
install_root = Path(temp_dir) / "deno-root"
provider = DenoProvider.model_validate(
{
"install_root": install_root,
"postinstall_scripts": False,
"min_release_age": 0,
},
)
installed = provider.install("cowsay")
test_machine.assert_shallow_binary_loaded(
installed,
assert_version_command=False,
)
assert installed is not None
assert installed.loaded_abspath is not None
assert provider.install_root == install_root
assert provider.bin_dir == install_root / "bin"
assert installed.loaded_abspath.parent == provider.bin_dir
# Real on-disk side effect: deno's shim landed in <root>/bin/cowsay
# and the global module cache is populated under cache_dir.
assert (install_root / "bin" / "cowsay").exists()
assert provider.cache_dir.exists()
def test_provider_direct_methods_exercise_real_lifecycle(self, test_machine):
with tempfile.TemporaryDirectory() as temp_dir:
provider = DenoProvider(
install_root=Path(temp_dir) / "deno",
postinstall_scripts=False,
min_release_age=0,
)
installed, _ = test_machine.exercise_provider_lifecycle(
provider,
bin_name="cowsay",
assert_version_command=False,
)
assert installed.loaded_abspath is not None
assert installed.loaded_abspath.is_relative_to(provider.install_root)
def test_provider_defaults_and_binary_overrides_enforce_min_release_age(
self,
test_machine,
):
with tempfile.TemporaryDirectory() as tmpdir:
strict_provider = DenoProvider(
install_root=Path(tmpdir) / "strict-deno",
postinstall_scripts=False,
min_release_age=36500,
)
# CI matrix installs Deno 2.5+ which supports
# --minimum-dependency-age.
assert strict_provider.supports_min_release_age("install") is True
with pytest.raises(BinProviderInstallError):
strict_provider.install("cowsay")
test_machine.assert_provider_missing(strict_provider, "cowsay")
direct_override = strict_provider.install(
"cowsay",
min_release_age=0,
)
test_machine.assert_shallow_binary_loaded(
direct_override,
assert_version_command=False,
)
assert (
strict_provider.install_root is not None
and (strict_provider.install_root / "bin" / "cowsay").exists()
)
assert strict_provider.uninstall("cowsay", min_release_age=0)
binary = Binary(
name="cowsay",
binproviders=cast(
list[BinProvider],
[
DenoProvider(
install_root=Path(tmpdir) / "binary-deno",
postinstall_scripts=False,
min_release_age=36500,
),
],
),
postinstall_scripts=False,
min_release_age=0,
)
installed = binary.install()
test_machine.assert_shallow_binary_loaded(
installed,
assert_version_command=False,
)
def test_min_release_age_extreme_value_blocks_install(self):
with tempfile.TemporaryDirectory() as tmpdir:
strict_provider = DenoProvider(
install_root=Path(tmpdir) / "deno",
postinstall_scripts=False,
min_release_age=36500, # 100 years
)
assert strict_provider.supports_min_release_age("install") is True
with pytest.raises(BinProviderInstallError):
strict_provider.install("cowsay")
assert strict_provider.install_root is not None
assert not (strict_provider.install_root / "bin" / "cowsay").exists()
def test_postinstall_scripts_default_off_does_not_block_simple_packages(
self,
test_machine,
):
with tempfile.TemporaryDirectory() as tmpdir:
provider = DenoProvider(
install_root=Path(tmpdir) / "deno",
postinstall_scripts=False,
min_release_age=0,
)
installed = provider.install("cowsay")
test_machine.assert_shallow_binary_loaded(
installed,
assert_version_command=False,
)
assert installed is not None
assert installed.loaded_abspath is not None
assert installed.loaded_abspath.exists()
def test_jsr_scheme_is_honored_for_jsr_packages(self, test_machine):
with tempfile.TemporaryDirectory() as tmpdir:
provider = DenoProvider(
install_root=Path(tmpdir) / "deno",
postinstall_scripts=False,
min_release_age=0,
).get_provider_with_overrides(
overrides={
"fileserver": {
"install_args": ["jsr:@std/http/file-server"],
},
},
)
installed = provider.install("fileserver")
test_machine.assert_shallow_binary_loaded(
installed,
assert_version_command=False,
)
assert installed is not None
assert installed.loaded_abspath is not None
assert provider.install_root is not None
assert (
installed.loaded_abspath == provider.install_root / "bin" / "fileserver"
)
def test_binary_direct_methods_exercise_real_lifecycle(self, test_machine):
with tempfile.TemporaryDirectory() as temp_dir:
binary = Binary(
name="cowsay",
binproviders=cast(
list[BinProvider],
[
DenoProvider(
install_root=Path(temp_dir) / "deno",
postinstall_scripts=False,
min_release_age=0,
),
],
),
postinstall_scripts=False,
min_release_age=0,
)
test_machine.exercise_binary_lifecycle(
binary,
assert_version_command=False,
)
def test_provider_dry_run_does_not_install_cowsay(self, test_machine):
with tempfile.TemporaryDirectory() as temp_dir:
provider = DenoProvider(
install_root=Path(temp_dir) / "deno",
postinstall_scripts=False,
min_release_age=0,
)
test_machine.exercise_provider_dry_run(provider, bin_name="cowsay")
shim = Path(temp_dir) / "deno" / "bin" / "cowsay"
assert not shim.exists()
def test_supports_methods_do_not_emit_unsupported_warnings(self, caplog):
with tempfile.TemporaryDirectory() as tmpdir:
with caplog.at_level(logging.WARNING, logger="abxpkg.binprovider"):
provider = DenoProvider(
install_root=Path(tmpdir) / "deno",
postinstall_scripts=False,
min_release_age=0,
)
installed = provider.install("cowsay")
assert installed is not None
assert "ignoring unsupported postinstall_scripts" not in caplog.text
assert "ignoring unsupported min_release_age" not in caplog.text
def test_binary_install_failure_propagates_as_BinaryInstallError(self):
with tempfile.TemporaryDirectory() as tmpdir:
failing_binary = Binary(
name="cowsay",
binproviders=cast(
list[BinProvider],
[
DenoProvider(
install_root=Path(tmpdir) / "deno",
postinstall_scripts=False,
min_release_age=36500,
),
],
),
postinstall_scripts=False,
min_release_age=36500,
)
with pytest.raises(BinaryInstallError):
failing_binary.install()