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
|
import textwrap
from typing import Mapping
from debputy.maintscript_snippet import MaintscriptSnippetContainer
from debputy.packager_provided_files import PackagerProvidedFile
from debputy.packages import BinaryPackage
from debputy.packaging.alternatives import process_alternatives
from debputy.plugin.api import virtual_path_def, VirtualPath
from debputy.plugin.api.impl import plugin_metadata_for_debputys_own_plugin
from debputy.plugin.api.impl_types import PackagerProvidedFileClassSpec
from debputy.plugin.api.test_api import build_virtual_file_system
def _ppf_for(pkg: BinaryPackage, path: VirtualPath) -> PackagerProvidedFile:
plugin_metadata = plugin_metadata_for_debputys_own_plugin()
return PackagerProvidedFile(
path,
pkg.name,
"irrelevant",
"irrelevant",
PackagerProvidedFileClassSpec(
plugin_metadata,
"alternatives",
"DEBIAN/alternatives",
0o0644,
None,
False,
False,
None,
False,
True,
None,
None,
False,
),
)
def test_alternatives(
package_single_foo_arch_all_cxt_amd64: Mapping[str, BinaryPackage],
) -> None:
pkg = package_single_foo_arch_all_cxt_amd64["foo"]
debian_dir = build_virtual_file_system(
[
virtual_path_def(
"alternatives",
fs_path="debian/alternatives",
content=textwrap.dedent(
"""\
Name: x-terminal-emulator
Link: /usr/bin/x-terminal-emulator
Alternative: /usr/bin/xterm
Dependents:
/usr/share/man/man1/x-terminal-emulator.1.gz x-terminal-emulator.1.gz /usr/share/man/man1/xterm.1.gz
Priority: 20
"""
),
),
]
)
fs_root = build_virtual_file_system(
[
"./usr/bin/xterm",
"./usr/share/man/man1/xterm.1.gz",
]
)
reserved_ppfs = {"alternatives": [_ppf_for(pkg, debian_dir["alternatives"])]}
maintscript_snippets = {
"prerm": MaintscriptSnippetContainer(),
"postinst": MaintscriptSnippetContainer(),
}
process_alternatives(
pkg,
fs_root,
reserved_ppfs,
maintscript_snippets,
)
prerm = maintscript_snippets["prerm"].generate_snippet(reverse=True)
postinst = maintscript_snippets["postinst"].generate_snippet(reverse=True)
assert prerm is not None
assert postinst is not None
assert "--remove x-terminal-emulator /usr/bin/xterm" in prerm
assert (
"--install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/bin/xterm 20"
) in postinst
|