8
8
import fixtures
9
9
import mock
10
10
import testtools
11
-
12
11
from bandit .cli import main as bandit
13
12
from bandit .core import extension_loader as ext_loader
14
13
from bandit .core import utils
@@ -89,20 +88,20 @@ def tearDown(self):
89
88
def test_get_options_from_ini_no_ini_path_no_target (self ):
90
89
# Test that no config options are loaded when no ini path or target
91
90
# directory are provided
92
- self .assertIsNone ( bandit ._get_options_from_ini (None , []))
91
+ self .assertEqual ({}, bandit ._get_options_from_ini (None , []))
93
92
94
93
def test_get_options_from_ini_empty_directory_no_target (self ):
95
94
# Test that no config options are loaded when an empty directory is
96
95
# provided as the ini path and no target directory is provided
97
96
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 , []))
99
98
100
99
def test_get_options_from_ini_no_ini_path_no_bandit_files (self ):
101
100
# Test that no config options are loaded when no ini path is provided
102
101
# and the target directory contains no bandit config files (.bandit)
103
102
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 ]))
106
105
107
106
def test_get_options_from_ini_no_ini_path_multi_bandit_files (self ):
108
107
# Test that bandit exits when no ini path is provided and the target
@@ -124,27 +123,36 @@ def test_init_extensions(self):
124
123
# Test that an extension loader manager is returned
125
124
self .assertEqual (ext_loader .MANAGER , bandit ._init_extensions ())
126
125
127
- def test_log_option_source_arg_val (self ):
126
+ def test_decide_option_source_arg_val (self ):
128
127
# Test that the command argument value is returned when provided
129
128
arg_val = 'file'
130
129
ini_val = 'vuln'
131
130
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 , ini_val , None ,
132
+ option_name ))
134
133
135
- def test_log_option_source_ini_value (self ):
134
+ def test_decide_option_source_ini_value (self ):
136
135
# Test that the ini value is returned when no command argument is
137
136
# provided
138
137
ini_val = 'vuln'
139
138
option_name = 'aggregate'
140
- self .assertEqual (ini_val , bandit ._log_option_source (None , ini_val ,
141
- option_name ))
139
+ self .assertEqual (ini_val , bandit ._decide_option_source (None , ini_val , None ,
140
+ option_name ))
141
+
142
+ def test_decide_option_source_default_value (self ):
143
+ # Test that the ini value is returned when no command argument is
144
+ # provided
145
+ default_val = 'vuln'
146
+ option_name = 'aggregate'
147
+ self .assertEqual (default_val , bandit ._decide_option_source (None , None , default_val ,
148
+ option_name ))
142
149
143
- def test_log_option_source_no_values (self ):
150
+ def test_decide_option_source_no_values (self ):
144
151
# Test that None is returned when no command argument or ini value are
145
152
# provided
146
153
option_name = 'aggregate'
147
- self .assertIsNone (bandit ._log_option_source (None , None , option_name ))
154
+ self .assertIsNone (bandit ._decide_option_source (
155
+ None , None , None , option_name ))
148
156
149
157
@mock .patch ('sys.argv' , ['bandit' , '-c' , 'bandit.yaml' , 'test' ])
150
158
def test_main_config_unopenable (self ):
0 commit comments