Debian Codegraph @

test/units/modules/test_apt.py

raw
1 # Copyright: Contributors to the Ansible project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3 from __future__ import annotations
4
5 import collections
6
7 from ansible.modules.apt import expand_pkgspec_from_fnmatches
8 import pytest
9
10 FakePackage = collections.namedtuple("Package", ("name",))
11 fake_cache = [
12 FakePackage("apt"),
13 FakePackage("apt-utils"),
14 FakePackage("not-selected"),
15 ]
16
17
18 @pytest.mark.parametrize(
19 ("test_input", "expected"),
20 [
21 pytest.param(
22 ["apt"],
23 ["apt"],
24 id="trivial",
25 ),
26 pytest.param(
27 ["apt=1.0*"],
28 ["apt=1.0*"],
29 id="version-wildcard",
30 ),
31 pytest.param(
32 ["apt*=1.0*"],
33 ["apt", "apt-utils"],
34 id="pkgname-wildcard-version",
35 ),
36 pytest.param(
37 ["apt*"],
38 ["apt", "apt-utils"],
39 id="pkgname-expands",
40 ),
41 ],
42 )
43 def test_expand_pkgspec_from_fnmatches(test_input, expected):
44 """Test positive cases of ``expand_pkgspec_from_fnmatches``."""
45 assert expand_pkgspec_from_fnmatches(None, test_input, fake_cache) == expected