-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_module_metadata.py
More file actions
60 lines (47 loc) · 2.96 KB
/
Copy pathtest_module_metadata.py
File metadata and controls
60 lines (47 loc) · 2.96 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
import os
import tempfile
import unittest
from unittest import mock
from RAMP import module_metadata
class GetCurrOsTest(unittest.TestCase):
def test_uses_devcontainer_distro_before_host_distro(self):
with tempfile.TemporaryDirectory() as temp_dir:
devcontainer_path = os.path.join(temp_dir, "devcontainer")
with open(devcontainer_path, "w") as f:
f.write("DISTRO=amzn2023\n")
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
with mock.patch.object(module_metadata.distro, "id", return_value="rocky"):
with mock.patch.object(module_metadata.distro, "version_parts", return_value=("8",)):
self.assertEqual(module_metadata.get_curr_os(), "amzn2023")
def test_raises_when_devcontainer_has_no_distro(self):
with tempfile.TemporaryDirectory() as temp_dir:
devcontainer_path = os.path.join(temp_dir, "devcontainer")
with open(devcontainer_path, "w") as f:
f.write("OTHER=value\n")
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
with self.assertRaises(KeyError):
module_metadata.get_curr_os()
def test_maps_ubuntu_codenames_to_versions(self):
with tempfile.TemporaryDirectory() as temp_dir:
for distro_value, expected in (("focal", "ubuntu20"), ("jammy", "ubuntu22"), ("noble", "ubuntu24")):
devcontainer_path = os.path.join(temp_dir, "devcontainer")
with open(devcontainer_path, "w") as f:
f.write("DISTRO=%s\n" % distro_value)
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
self.assertEqual(module_metadata.get_curr_os(), expected)
def test_amzn2023_unchanged_but_jammy_mapped_to_ubuntu22(self):
with tempfile.TemporaryDirectory() as temp_dir:
for distro_value, expected in (("amzn2023", "amzn2023"), ("jammy", "ubuntu22")):
devcontainer_path = os.path.join(temp_dir, "devcontainer")
with open(devcontainer_path, "w") as f:
f.write("DISTRO=%s\n" % distro_value)
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
self.assertEqual(module_metadata.get_curr_os(), expected)
def test_preserves_distro_fallback_when_devcontainer_is_absent(self):
devcontainer_path = os.path.join(tempfile.gettempdir(), "missing-devcontainer")
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
with mock.patch.object(module_metadata.distro, "id", return_value="ubuntu"):
with mock.patch.object(module_metadata.distro, "version_parts", return_value=("22",)):
self.assertEqual(module_metadata.get_curr_os(), "ubuntu22")
if __name__ == "__main__":
unittest.main()