Skip to content

Commit 9ca63bf

Browse files
committed
Fix tests
1 parent e1e5ff2 commit 9ca63bf

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

bandit/core/utils.py

Lines changed: 3 additions & 1 deletion
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

Lines changed: 26 additions & 13 deletions
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,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):

tests/unit/core/test_util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import tempfile
1313

1414
import testtools
15-
1615
from bandit.core import utils as b_utils
1716

1817

@@ -272,7 +271,7 @@ def test_parse_ini_file(self):
272271
'expected': {'exclude': '/abc,/def'}},
273272

274273
{'content': '[Blabla]\nsomething=something',
275-
'expected': None}]
274+
'expected': {}}]
276275

277276
with tempfile.NamedTemporaryFile('r+') as t:
278277
for test in tests:

0 commit comments

Comments
 (0)