diff --git a/test/test_cli.py b/test/test_cli.py index 188d9706a1..d28c391cb0 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -516,3 +516,49 @@ def test_SBOM(self, caplog): logging.INFO, "There are 1 products with known CVEs detected", ) in caplog.record_tuples + + def test_console_output_depending_reportlab_existence(self, caplog): + from importlib.machinery import ModuleSpec + from importlib.util import module_from_spec + + my_test_filename = os.path.join(self.tempdir, "reportlab_test_report.pdf") + + if os.path.exists(my_test_filename): + os.remove(my_test_filename) + + pkg_to_spoof = "reportlab" + not_installed_msg = "PDF output not available. Default to console." + execution = [ + "cve-bin-tool", + "-f", + "pdf", + "-o", + my_test_filename, + os.path.join(self.tempdir, CURL_7_20_0_RPM), + ] + + with caplog.at_level(logging.INFO): + main(execution) + + assert ( + "cve_bin_tool", + logging.INFO, + not_installed_msg, + ) in caplog.record_tuples + + caplog.clear() + + if os.path.exists(my_test_filename): + os.remove(my_test_filename) + + ms = ModuleSpec(pkg_to_spoof, "surelyanotexistentmodule") + m = module_from_spec(ms) + sys.modules[pkg_to_spoof] = m + + with caplog.at_level(logging.INFO): + main(execution) + assert ( + "cve_bin_tool", + logging.INFO, + not_installed_msg, + ) not in caplog.record_tuples