88import fixtures
99import mock
1010import testtools
11-
1211from bandit .cli import main as bandit
1312from bandit .core import extension_loader as ext_loader
1413from bandit .core import utils
@@ -89,20 +88,20 @@ def tearDown(self):
8988 def test_get_options_from_ini_no_ini_path_no_target (self ):
9089 # Test that no config options are loaded when no ini path or target
9190 # directory are provided
92- self .assertIsNone ( bandit ._get_options_from_ini (None , []))
91+ self .assertEqual ({}, bandit ._get_options_from_ini (None , []))
9392
9493 def test_get_options_from_ini_empty_directory_no_target (self ):
9594 # Test that no config options are loaded when an empty directory is
9695 # provided as the ini path and no target directory is provided
9796 ini_directory = self .useFixture (fixtures .TempDir ()).path
98- self .assertIsNone ( bandit ._get_options_from_ini (ini_directory , []))
97+ self .assertEqual ({}, bandit ._get_options_from_ini (ini_directory , []))
9998
10099 def test_get_options_from_ini_no_ini_path_no_bandit_files (self ):
101100 # Test that no config options are loaded when no ini path is provided
102101 # and the target directory contains no bandit config files (.bandit)
103102 target_directory = self .useFixture (fixtures .TempDir ()).path
104- self .assertIsNone ( bandit ._get_options_from_ini (None ,
105- [target_directory ]))
103+ self .assertEqual ({}, bandit ._get_options_from_ini (
104+ None , [target_directory ]))
106105
107106 def test_get_options_from_ini_no_ini_path_multi_bandit_files (self ):
108107 # Test that bandit exits when no ini path is provided and the target
@@ -124,27 +123,41 @@ def test_init_extensions(self):
124123 # Test that an extension loader manager is returned
125124 self .assertEqual (ext_loader .MANAGER , bandit ._init_extensions ())
126125
127- def test_log_option_source_arg_val (self ):
126+ def test_decide_option_source_arg_val (self ):
128127 # Test that the command argument value is returned when provided
129128 arg_val = 'file'
130129 ini_val = 'vuln'
131130 option_name = 'aggregate'
132- self .assertEqual (arg_val , bandit ._log_option_source (arg_val , ini_val ,
133- option_name ))
131+ self .assertEqual (arg_val , bandit ._decide_option_source (arg_val ,
132+ ini_val ,
133+ None ,
134+ option_name ))
134135
135- def test_log_option_source_ini_value (self ):
136+ def test_decide_option_source_ini_value (self ):
136137 # Test that the ini value is returned when no command argument is
137138 # provided
138139 ini_val = 'vuln'
139140 option_name = 'aggregate'
140- self .assertEqual (ini_val , bandit ._log_option_source (None , ini_val ,
141- option_name ))
141+ self .assertEqual (ini_val , bandit ._decide_option_source (None , ini_val ,
142+ None ,
143+ option_name ))
144+
145+ def test_decide_option_source_default_value (self ):
146+ # Test that the ini value is returned when no command argument is
147+ # provided
148+ default_val = 'vuln'
149+ option_name = 'aggregate'
150+ self .assertEqual (default_val ,
151+ bandit ._decide_option_source (None , None ,
152+ default_val ,
153+ option_name ))
142154
143- def test_log_option_source_no_values (self ):
155+ def test_decide_option_source_no_values (self ):
144156 # Test that None is returned when no command argument or ini value are
145157 # provided
146158 option_name = 'aggregate'
147- self .assertIsNone (bandit ._log_option_source (None , None , option_name ))
159+ self .assertIsNone (bandit ._decide_option_source (
160+ None , None , None , option_name ))
148161
149162 @mock .patch ('sys.argv' , ['bandit' , '-c' , 'bandit.yaml' , 'test' ])
150163 def test_main_config_unopenable (self ):
0 commit comments