Skip to content

Commit 0172647

Browse files
committed
Fix tests
1 parent e1e5ff2 commit 0172647

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

bandit/core/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class InvalidModulePath(Exception):
9595

9696
class ConfigError(Exception):
9797
"""Raised when the config file fails validation."""
98+
9899
def __init__(self, message, config_file):
99100
self.config_file = config_file
100101
self.message = "{0} : {1}".format(config_file, message)
@@ -103,6 +104,7 @@ def __init__(self, message, config_file):
103104

104105
class ProfileNotFound(Exception):
105106
"""Raised when chosen profile cannot be found."""
107+
106108
def __init__(self, config_file, profile):
107109
self.config_file = config_file
108110
self.profile = profile
@@ -312,7 +314,7 @@ def parse_ini_file(f_loc):
312314
LOG.warning("Unable to parse config file %s or missing [bandit] "
313315
"section", f_loc)
314316

315-
return None
317+
return {}
316318

317319

318320
def check_ast_node(name):

tests/unit/cli/test_main.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import fixtures
99
import mock
1010
import testtools
11-
1211
from bandit.cli import main as bandit
1312
from bandit.core import extension_loader as ext_loader
1413
from 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,36 @@ 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, ini_val, None,
132+
option_name))
134133

135-
def test_log_option_source_ini_value(self):
134+
def test_decide_option_source_ini_value(self):
136135
# Test that the ini value is returned when no command argument is
137136
# provided
138137
ini_val = 'vuln'
139138
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))
142149

143-
def test_log_option_source_no_values(self):
150+
def test_decide_option_source_no_values(self):
144151
# Test that None is returned when no command argument or ini value are
145152
# provided
146153
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))
148156

149157
@mock.patch('sys.argv', ['bandit', '-c', 'bandit.yaml', 'test'])
150158
def test_main_config_unopenable(self):

0 commit comments

Comments
 (0)