Skip to content

Commit 1ddae10

Browse files
authored
test(package-list-parser): use ubuntu packages' versions dynamically (#1458)
* test(package-list-parser): use ubuntu packages' versions dynamically * test(package-list-parser): fix test in windows
1 parent 5b14b1b commit 1ddae10

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

test/test_package_list_parser.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

44
import subprocess
5-
from os import environ
65
from os.path import dirname, join
7-
from sys import platform
86

97
import distro
108
import pytest
@@ -38,16 +36,43 @@ class TestPackageListParser:
3836
},
3937
}
4038

39+
# Find the versions of the ubuntu packages
40+
UBUNTU_PACKAGE_VERSIONS = (
41+
(
42+
subprocess.run(
43+
[
44+
"dpkg-query",
45+
"--show",
46+
"--showformat=${Version}\n",
47+
"bash",
48+
"binutils",
49+
"wget",
50+
],
51+
stdout=subprocess.PIPE,
52+
)
53+
.stdout.decode("utf-8")
54+
.splitlines()
55+
)
56+
if "ubuntu" in distro.id()
57+
else ["dummy", "array", "for windows"]
58+
)
59+
4160
UBUNTU_PARSED_TRIAGE_DATA = {
42-
ProductInfo(vendor="gnu*", product="bash", version="5.0-6ubuntu1.1"): {
61+
ProductInfo(
62+
vendor="gnu*", product="bash", version=UBUNTU_PACKAGE_VERSIONS[0]
63+
): {
4364
"default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
4465
"paths": {""},
4566
},
46-
ProductInfo(vendor="gnu*", product="binutils", version="2.34-6ubuntu1.3"): {
67+
ProductInfo(
68+
vendor="gnu*", product="binutils", version=UBUNTU_PACKAGE_VERSIONS[1]
69+
): {
4770
"default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
4871
"paths": {""},
4972
},
50-
ProductInfo(vendor="gnu*", product="wget", version="1.20.3-1ubuntu1"): {
73+
ProductInfo(
74+
vendor="gnu*", product="wget", version=UBUNTU_PACKAGE_VERSIONS[2]
75+
): {
5176
"default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
5277
"paths": {""},
5378
},
@@ -103,25 +128,13 @@ def test_invalid_linux_list(self, filepath, caplog):
103128
assert expected_output == [rec.message for rec in caplog.records]
104129

105130
@pytest.mark.skipif(
106-
"ACTIONS" not in environ
107-
or not platform == "linux"
108-
or ("ubuntu" not in distro.id() and "20.04" not in distro.version()),
109-
reason="Running locally requires root permission",
131+
"ubuntu" not in distro.id(),
132+
reason="Test for Ubuntu systems",
110133
)
111134
@pytest.mark.parametrize(
112135
"filepath, parsed_data",
113136
[(join(TXT_PATH, "test_ubuntu_list.txt"), UBUNTU_PARSED_TRIAGE_DATA)],
114137
)
115138
def test_valid_ubuntu_list(self, filepath, parsed_data):
116-
subprocess.run(
117-
[
118-
"sudo",
119-
"apt-get",
120-
"install",
121-
"bash=5.0-6ubuntu1.1",
122-
"binutils=2.34-6ubuntu1.3",
123-
"wget=1.20.3-1ubuntu1",
124-
]
125-
)
126139
package_list = PackageListParser(filepath, error_mode=ErrorMode.FullTrace)
127140
assert package_list.parse_list() == parsed_data

0 commit comments

Comments
 (0)