-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bashprovider.py
More file actions
139 lines (116 loc) · 5.06 KB
/
test_bashprovider.py
File metadata and controls
139 lines (116 loc) · 5.06 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
import tempfile
from pathlib import Path
from abxpkg import BashProvider, Binary
BASH_ZX_INSTALL = (
'npm install --quiet --prefix "$INSTALL_ROOT/npm" zx '
'&& ln -sf "$INSTALL_ROOT/npm/node_modules/.bin/zx" "$BIN_DIR/bash-zx"'
)
class TestBashProvider:
def test_install_root_alias_without_explicit_bin_dir_uses_root_bin(
self,
test_machine,
):
test_machine.require_tool("npm")
with tempfile.TemporaryDirectory() as temp_dir:
install_root = Path(temp_dir) / "bash-root"
provider = BashProvider.model_validate(
{
"install_root": install_root,
"postinstall_scripts": True,
"min_release_age": 0,
},
).get_provider_with_overrides(
overrides={"bash-zx": {"install": BASH_ZX_INSTALL}},
)
installed = provider.install("bash-zx")
test_machine.assert_shallow_binary_loaded(installed)
assert installed is not None
assert provider.install_root == install_root
assert provider.bin_dir == install_root / "bin"
assert installed.loaded_abspath is not None
def test_install_root_and_bin_dir_aliases_install_into_the_requested_paths(
self,
test_machine,
):
test_machine.require_tool("npm")
with tempfile.TemporaryDirectory() as temp_dir:
install_root = Path(temp_dir) / "bash-root"
bin_dir = Path(temp_dir) / "bash-bin"
provider = BashProvider.model_validate(
{
"install_root": install_root,
"bin_dir": bin_dir,
"postinstall_scripts": True,
"min_release_age": 0,
},
).get_provider_with_overrides(
overrides={"bash-zx": {"install": BASH_ZX_INSTALL}},
)
installed = provider.install("bash-zx")
test_machine.assert_shallow_binary_loaded(installed)
assert installed is not None
assert provider.install_root == install_root
assert provider.bin_dir == bin_dir
assert installed.loaded_abspath is not None
def test_explicit_bash_bin_dir_takes_precedence_over_existing_PATH_entries(
self,
test_machine,
):
test_machine.require_tool("npm")
with tempfile.TemporaryDirectory() as temp_dir:
temp_dir_path = Path(temp_dir)
ambient_provider = BashProvider(
install_root=temp_dir_path / "ambient-root",
bin_dir=temp_dir_path / "ambient-root/bin",
postinstall_scripts=True,
min_release_age=0,
).get_provider_with_overrides(
overrides={"bash-zx": {"install": BASH_ZX_INSTALL}},
)
ambient_installed = ambient_provider.install("bash-zx")
assert ambient_installed is not None
provider = BashProvider(
PATH=str(ambient_provider.bin_dir),
install_root=temp_dir_path / "bash-root",
bin_dir=temp_dir_path / "bash-bin",
postinstall_scripts=True,
min_release_age=0,
).get_provider_with_overrides(
overrides={"bash-zx": {"install": BASH_ZX_INSTALL}},
)
installed = provider.install("bash-zx")
test_machine.assert_shallow_binary_loaded(installed)
assert installed is not None
assert provider.bin_dir == temp_dir_path / "bash-bin"
assert installed.loaded_abspath is not None
assert ambient_installed.loaded_abspath is not None
def test_provider_direct_methods_exercise_real_lifecycle(self, test_machine):
test_machine.require_tool("npm")
with tempfile.TemporaryDirectory() as temp_dir:
provider = BashProvider(
install_root=Path(temp_dir) / "bash-root",
bin_dir=Path(temp_dir) / "bash-root/bin",
postinstall_scripts=True,
min_release_age=0,
).get_provider_with_overrides(
overrides={"bash-zx": {"install": BASH_ZX_INSTALL}},
)
test_machine.exercise_provider_lifecycle(provider, bin_name="bash-zx")
def test_binary_direct_methods_exercise_real_lifecycle(self, test_machine):
test_machine.require_tool("npm")
with tempfile.TemporaryDirectory() as temp_dir:
binary = Binary(
name="bash-zx",
binproviders=[
BashProvider(
install_root=Path(temp_dir) / "bash-root",
bin_dir=Path(temp_dir) / "bash-root/bin",
postinstall_scripts=True,
min_release_age=0,
),
],
overrides={"bash": {"install": BASH_ZX_INSTALL}},
postinstall_scripts=True,
min_release_age=0,
)
test_machine.exercise_binary_lifecycle(binary)