Skip to content

Commit 53e1141

Browse files
stvmlAmber Mao
andauthored
test: Improve coverage for unsupported distros in package_list_parser.py (#2963)
Co-authored-by: Amber Mao <[email protected]>
1 parent e19ee4b commit 53e1141

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

cve_bin_tool/package_list_parser.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ def parse_list(self):
5454
self.check_file()
5555
installed_packages = []
5656
if not input_file.endswith("requirements.txt"):
57-
if distro.id() not in SUPPORTED_DISTROS:
58-
LOGGER.warning(
59-
f"Package list support only available on {','.join(SUPPORTED_DISTROS)}!"
60-
)
61-
return {}
62-
6357
system_packages = []
6458

6559
LOGGER.info(f"Scanning {distro.id().capitalize()} package list.")

test/test_package_list_parser.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,21 @@ def test_invalid_linux_list(self, filepath, caplog):
138138
def test_valid_ubuntu_list(self, filepath, parsed_data):
139139
package_list = PackageListParser(filepath, error_mode=ErrorMode.FullTrace)
140140
assert package_list.parse_list() == parsed_data
141+
142+
@pytest.mark.skipif(
143+
distro.id() in SUPPORTED_DISTROS,
144+
reason="Test for unsupported distros",
145+
)
146+
@pytest.mark.parametrize(
147+
"filepath",
148+
[str(TXT_PATH / "test_ubuntu_list.txt")],
149+
)
150+
def test_unsupported_distros(self, filepath, caplog):
151+
package_list = PackageListParser(filepath, error_mode=ErrorMode.FullTrace)
152+
expected_output = [
153+
f"Package list support only available for {','.join(SUPPORTED_DISTROS)}!"
154+
]
155+
156+
with pytest.raises(InvalidListError):
157+
package_list.parse_list()
158+
assert expected_output == [rec.message for rec in caplog.records]

0 commit comments

Comments
 (0)