Skip to content

Commit 5c963e7

Browse files
authored
add test for quiet mode (#586)
1 parent bc7b8d9 commit 5c963e7

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

cve_bin_tool/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ def main(argv=None):
298298
if argv is None:
299299
argv = sys.argv
300300

301+
# Reset logger level to info
302+
LOGGER.setLevel(logging.INFO)
303+
301304
parser = argparse.ArgumentParser(
302305
prog="cve-bin-tool",
303306
description=textwrap.dedent(

test/test_cli.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
22
CVE-bin-tool CLI tests
33
"""
4-
import os
5-
import unittest
64
import logging
5+
import os
76
import subprocess
7+
import unittest
8+
89
from cve_bin_tool.cli import main
910
from cve_bin_tool.cvedb import DISK_LOCATION_DEFAULT
1011
from cve_bin_tool.extractor import Extractor
11-
1212
from .utils import (
1313
TempDirTest,
1414
download_file,
@@ -219,3 +219,20 @@ def test_unknown_warning(self):
219219
warnings = [i for i in cm.output if "WARNING" in i]
220220
self.assertTrue(len(warnings) > 0)
221221
self.assertTrue("was detected with version UNKNOWN" in "".join(warnings))
222+
223+
def test_quiet_mode(self):
224+
""" Test that an quite mode isn't generating any output """
225+
logger = logging.getLogger()
226+
227+
# build the test file in test/binaries
228+
binaries_path = os.path.join(
229+
os.path.abspath(os.path.dirname(__file__)), "binaries"
230+
)
231+
filename = "test-python-3.7.1.out"
232+
subprocess.call(["make", filename], cwd=binaries_path)
233+
234+
with self.assertLogs(logger, logging.INFO) as cm:
235+
main(["cve-bin-tool", "-q", os.path.join(binaries_path, filename)])
236+
logger.info("test")
237+
238+
self.assertEqual(["INFO:root:test"], cm.output)

0 commit comments

Comments
 (0)