2222
2323from cve_bin_tool .cli import main
2424from cve_bin_tool .cvedb import DISK_LOCATION_DEFAULT
25+ from cve_bin_tool .error_handler import ERROR_CODES , InsufficientArgs
2526from cve_bin_tool .extractor import Extractor
2627from cve_bin_tool .version_scanner import VersionScanner
2728
@@ -88,37 +89,37 @@ def test_usage(self):
8889 """Test that the usage returns 0"""
8990 with pytest .raises (SystemExit ) as e :
9091 main (["cve-bin-tool" ])
91- assert e .value .args [0 ] == 24
92+ assert e .value .args [0 ] == ERROR_CODES [ InsufficientArgs ]
9293
9394 def test_invalid_file_or_directory (self ):
9495 """Test behaviour with an invalid file/directory"""
9596 with pytest .raises (SystemExit ) as e :
9697 main (["cve-bin-tool" , "non-existant" ])
97- assert e .value .args [0 ] == 21
98+ assert e .value .args [0 ] == ERROR_CODES [ FileNotFoundError ]
9899
99100 def test_invalid_parameter (self ):
100101 """Test that invalid parmeters exit with expected error code.
101- ArgParse calls sys.exit(2) for all errors """
102+ ArgParse calls sys.exit(2) for all errors"""
102103
103104 # no directory specified
104105 with pytest .raises (SystemExit ) as e :
105106 main (["cve-bin-tool" , "--bad-param" ])
106- assert e .value .args [0 ] == 2
107+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
107108
108109 # bad parameter (but good directory)
109110 with pytest .raises (SystemExit ) as e :
110111 main (["cve-bin-tool" , "--bad-param" , self .tempdir ])
111- assert e .value .args [0 ] == 2
112+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
112113
113114 # worse parameter
114115 with pytest .raises (SystemExit ) as e :
115116 main (["cve-bin-tool" , "--bad-param && cat hi" , self .tempdir ])
116- assert e .value .args [0 ] == 2
117+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
117118
118119 # bad parameter after directory
119120 with pytest .raises (SystemExit ) as e :
120121 main (["cve-bin-tool" , self .tempdir , "--bad-param;cat hi" ])
121- assert e .value .args [0 ] == 2
122+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
122123
123124 @unittest .skipUnless (LONG_TESTS () > 0 , "Skipping long tests" )
124125 def test_update_flags (self ):
@@ -136,7 +137,7 @@ def test_update_flags(self):
136137 )
137138 with pytest .raises (SystemExit ) as e :
138139 main (["cve-bin-tool" , "-u" , "whatever" , "-n" , "json" , self .tempdir ])
139- assert e .value .args [0 ] == 2
140+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
140141
141142 @staticmethod
142143 def check_exclude_log (caplog , exclude_path , checkers ):
@@ -349,11 +350,11 @@ def test_severity(self, capsys, caplog):
349350 # Check command line parameters - wrong case
350351 with pytest .raises (SystemExit ) as e :
351352 main (["cve-bin-tool" , "-S" , "HIGH" , self .tempdir ])
352- assert e .value .args [0 ] == 2
353+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
353354 # Check command line parameters - wrong option
354355 with pytest .raises (SystemExit ) as e :
355356 main (["cve-bin-tool" , "-S" , "ALL" , self .tempdir ])
356- assert e .value .args [0 ] == 2
357+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
357358
358359 my_test_filename = "sevtest.csv"
359360
0 commit comments