Skip to content

Commit 5e7c46c

Browse files
Extract constants from functions to file level
1 parent 50f6027 commit 5e7c46c

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

test/test_modules.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,31 @@
3131
]
3232
)
3333

34+
# content: ssh version, release shortcut,
35+
ssh_pkg_info = {
36+
"rockylinux9": ("8.", ".el9"),
37+
"debian_bookworm": ("1:9.2", None),
38+
}
39+
40+
# content: distribution, codename, architecture, release_regex
41+
docker_image_info = {
42+
"rockylinux9": ("rocky", None, "x86_64", r"^9.\d+$"),
43+
"debian_bookworm": ("debian", "bookworm", "amd64", r"^12"),
44+
}
45+
3446

3547
@all_images
3648
def test_package(host, docker_image):
3749
assert not host.package("zsh").is_installed
3850
ssh = host.package("openssh-server")
39-
version = {
40-
"rockylinux9": "8.",
41-
"debian_bookworm": "1:9.2",
42-
}[docker_image]
51+
ssh_version, sshd_release = ssh_pkg_info[docker_image]
4352
assert ssh.is_installed
44-
assert ssh.version.startswith(version)
45-
release = {
46-
"rockylinux9": ".el9",
47-
"debian_bookworm": None,
48-
}[docker_image]
49-
if release is None:
53+
assert ssh.version.startswith(ssh_version)
54+
if sshd_release is None:
5055
with pytest.raises(NotImplementedError):
5156
ssh.release
5257
else:
53-
assert release in ssh.release
58+
assert sshd_release in ssh.release
5459

5560

5661
def test_held_package(host):
@@ -89,14 +94,10 @@ def test_uninstalled_package_version(host):
8994
def test_systeminfo(host, docker_image):
9095
assert host.system_info.type == "linux"
9196

92-
release, distribution, codename, arch = {
93-
"rockylinux9": (r"^9.\d+$", "rocky", None, "x86_64"),
94-
"debian_bookworm": (r"^12", "debian", "bookworm", "x86_64"),
95-
}[docker_image]
96-
97+
distribution, codename, unused_arch, release_regex = docker_image_info[docker_image]
9798
assert host.system_info.distribution == distribution
9899
assert host.system_info.codename == codename
99-
assert re.match(release, host.system_info.release)
100+
assert re.match(release_regex, host.system_info.release)
100101

101102

102103
@all_images
@@ -318,7 +319,7 @@ def test_file(host):
318319

319320

320321
def test_ansible_unavailable(host):
321-
expected = "Ansible module is only available with " "ansible connection backend"
322+
expected = "Ansible module is only available with ansible connection backend"
322323
with pytest.raises(RuntimeError) as excinfo:
323324
host.ansible("setup")
324325
assert expected in str(excinfo.value)

0 commit comments

Comments
 (0)